You are given a string \(S\) of length \(N\). A string is called twin if the characters of the string can be split into two groups such that the occurrence of each character is equal in both groups.
Find the number of twin substrings of \(S\).
Input Format:
Output Format:
For each test case, print the number of twin substrings of \(S\).
Constraints:
\(1 <= T <= 10\)
\(1 <= N <= 10^5\)
\(S \) contains lower-case English letters
First test case:-
Substrings \(cc, bccb, abccba\) are twin as they can divide into \((c,c), (bc,cb)\) and \((abc,cba)\) respectively. Hence, the answer is \(3\).
Second test case:-
Substring \(dd\) is twin as they can divide into \((d, d)\). Hence, the answer is \(1\).