#P7377. Counting Similar Parameterized Words

    ID: 20574 Type: Default 1000ms 256MiB

Counting Similar Parameterized Words

Counting Similar Parameterized Words

We define a parameterized word as a string consisting of lowercase English letters and the character '?' . For instance, a??cd, bcd, and ?? are parameterized words.

Two parameterized words are said to be similar if it is possible to replace the '?' characters with specific lowercase letters such that the resulting words are identical. For example, a??? and ?b?a are similar since both can be transformed into abba.

Given $N$ parameterized words each of length $M$, count the number of pairs of similar parameterized words.

inputFormat

The first line contains an integer $N$, the number of parameterized words. Each of the following $N$ lines contains a parameterized word of length $M$.

outputFormat

Output a single integer representing the number of pairs of similar parameterized words.

sample

3
a?c
??c
abc
3