Matcom Online Grader
Faculty of Mathematics and Computer Science of University of Havana
ℹ️ We've recently migrated MOG to a new server with a different grader. As a result, some features—especially those related to submission evaluation—might not work correctly. If you encounter any issues, please report them by clicking the exclamation icon in the bottom right corner of the website.
Are you sure you want to participate in this contest ?
If you select a team then virtual participation for other team members will be disabled. So, pick one if and only if your teammates are ready to compete with you.
Two strings are anagrams of each other if the letters of one string can be rearranged to form the other string. Given a string $s$, find the number of pairs of substrings of $s$ which are anagrams of each other.
For example $s = wow$ the list of all anagrammatic pairs is $[w, w], [wo, ow]$ at positions $([0..0], [2..2])$ and $([0..1], [1..2])$ respectively.
Input
A single line containing a string $s$ to analyze. String $s$ only contains lowercase English characters $[a..z]$ and $|s| \le 100$.
Output
Print the number of anagrammatic pairs in the given string.
Sample test(s)
Input
abba
Output
4
Input
abcd
Output
0
Hints
No anagrammatic pairs exist in the second test case as no character repeats.