---
{"category_name":"medium","problem_code":"ICM0010","problem_name":"Good pairs of substrings","problemComponents":{"constraints":"","constraintsState":false,"subtasks":"","subtasksState":false,"inputFormat":"","inputFormatState":false,"outputFormat":"","outputFormatState":false,"sampleTestCases":{}},"video_editorial_url":"","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":2,"source_sizelimit":50000,"problem_author":"shikhar7s","problem_tester":"","date_added":"22-03-2021","tags":{"0":"icm2021","1":"shikhar7s"},"problem_difficulty_level":"Unavailable","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/ICM0010","time":{"view_start_date":1617728402,"submit_start_date":1617728402,"visible_start_date":1617728402,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=ICM0010","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
You are given a string $S$ of length $N$.
<br>
Count the number of ways of choosing $4$ integers $L_1$, $R_1$, $L_2$, $R_2$, such that :-
<ul>
<li> $1$ $\leq$ $L_1$ $\leq$ $R_1$ $\lt$ $L_2$ $\leq$ $R_2$ $\leq $ $N$ </li>
<li> $R_1- L_1$ $=$ $R_2-L_2$ </li>
<li> string $T$ $=$ $S[L_1...R_1]$ + $S[L_2...R_2]$ is palindrome</li>
</ul>
<br>
For example, consider $S$ $=$ $abaa$, there exists three ways:-
<ul>
<li> $[$ $L_1$, $R_1$, $L_2$, $R_2$ $]$ $=$ $[1,1,3,3]$ </li>
<li> $[$ $L_1$, $R_1$, $L_2$, $R_2$ $]$ $=$ $[3,3,4,4]$ </li>
<li> $[$ $L_1$, $R_1$, $L_2$, $R_2$ $]$ $=$ $[1,1,4,4]$ </li>
</ul>
<hr>
<h3> Input </h3>
<ul>
<li>The first line of the input contains a single integer $T$ denoting the number of test cases. The description of
T test cases follows.
<li>Each testcase contains a single string $S$.</li>
</ul>
<hr>
<h3> Output </h3>
<ul>
<li> For each test case, print a single line containing one integer, Number of ways to select $4$ integers which satisfy the given property</li>
</ul>
<hr>
<h3>Constraints</h3>
<ul>
<li> $1$ $\leq$ $T$ $\leq$ $10^5$ </li>
<li> $1$ $\leq$ $|S|$ $\leq$ $10^5$</li>
<li> $S$ contains only lowercase English letters </li>
<li> the sum of $|S|$ over all test cases does not exceed $500,000$ </li>
</ul>
<hr>
<h3>Example Input</h3>
4<br>
abaa<br>
abajatinaba<br>
ttktotkkot<br>
r<br>
<hr>
<h3>Example Output</h3>
3<br>
14<br>
16<br>
0<br>
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>