Waterloo 2025 Fall B - Palindromic Triplets
View as PDFThere is a collection of non-empty strings that are indexed from
to
(where
is the number of strings). Count how many ordered triples of indices
(with repetition allowed) produce a palindrome of odd length when concatenated as
.
Input Specification
The first line of input contains an integer , the number of strings in
. The following
lines of input consist of 1 or more lowercase letters each, where the
-th line contains the string
(string indexed at
). The total number of letters in all of the strings put together will be at most
.
Output Specification
Output a single integer, the number of such triplets.
Sample Input 1
4
a
ab
ba
cc
Sample Output 1
6
Explanation for Sample Output 1
The valid triplets are .
Sample Input 2
2
a
a
Sample Output 2
8
Explanation for Sample Output 2
The valid triplets are .
Comments