{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"\u003cp\u003eYou are given a string \u003cvar\u003eS\u003c/var\u003e of size \u003cvar\u003eN\u003c/var\u003e. Can you count how many unordered pairs of substrings \u003cvar\u003e(a, b)\u003c/var\u003e exist satisfying the following properties? \u003c/p\u003e\n\n\u003cul\u003e\n \u003cli\u003ea \u003d S[p : q]\u003c/li\u003e\n \u003cli\u003ea is a palindrome\u003c/li\u003e\n \u003cli\u003eb \u003d S[r : s]\u003c/li\u003e\n \u003cli\u003eb is a palindrome\u003c/li\u003e\n \u003cli\u003ep !\u003d r or q !\u003d s\u003c/li\u003e\n \u003cli\u003eThe segments [p : q] and [r : s] intersect. (There is at least one index i such that p \u003c\u003d i \u003c\u003d q and r \u003c\u003d i \u003c\u003d s.)\u003c/li\u003e\n\u003c/ul\u003e"}},{"title":"Constraints","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cul\u003e \n \u003cli\u003e\u003cvar\u003e1 \u003c\u003d N \u003c\u003d 2000000\u003c/var\u003e\u003c/li\u003e \n\u003c/ul\u003e"}},{"title":"Input Format","value":{"format":"MD","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e\u003cvar\u003eN\u003c/var\u003e\n\u003cvar\u003eS\u003cvar\u003e\n\u003c/pre\u003e"}},{"title":"Output Format","value":{"format":"MD","content":"\u003cp\u003ePrint the number of pairs satisfying the conditions modulo \u003cvar\u003e51123987\u003c/var\u003e.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"MD","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e4\u003cbr\u003ebabb\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e6\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e2\u003cbr\u003eaa\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e2\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Explanation Sample 1","value":{"format":"MD","content":"\u003cul\u003e\n \u003cli\u003e[1 : 1] and [1 : 3] intersect\u003c/li\u003e\n \u003cli\u003e[1 : 3] and [2 : 2] intersect\u003c/li\u003e\n \u003cli\u003e[1 : 3] and [3 : 3] intersect\u003c/li\u003e\n \u003cli\u003e[1 : 3] and [1 : 3] intersect\u003c/li\u003e\n \u003cli\u003e[3 : 3] and [3 : 4] intersect\u003c/li\u003e\n \u003cli\u003e[3 : 4] and [4 : 4] intersect\u003c/li\u003e\n\u003c/ul\u003e"}}]}