#P7377. [COCI 2018/2019 #5] Parametriziran
[COCI 2018/2019 #5] Parametriziran
Description
We define a string consisting of lowercase letters and question marks as a parameterized word. For example, a??cd, bcd, and ?? are all parameterized words.
If, for two parameterized words, we can replace the question marks in each of them with specific lowercase letters so that the two resulting words become exactly the same, then the two original parameterized words are called similar. For example, both a??? and ?b?a can be replaced to become abba, so a??? and ?b?a are similar.
Given parameterized words of length , find how many pairs of parameterized words are similar.
Input Format
The first line contains integers .
The next lines each contain a parameterized word of length .
Output Format
Output the number of pairs of similar parameterized words.
3 3
??b
c??
c?c
2
4 6
ab??c?
??kll?
a?k??c
?bcd??
3
5 2
??
b?
c?
?g
cg
8
Hint
Explanation for Sample 1
??b and c?? are similar, and c?? and c?c are also similar. Therefore, there are a total of pairs of similar parameterized words.
Constraints
For of the testdata, .
For another of the testdata, .
For of the testdata, and .
Notes
The score settings of this problem follow the original COCI problem, with a full score of .
This problem is translated from COCI2018-2019 CONTEST #5 T4 Parametriziran.
Translated by ChatGPT 5
京公网安备 11011102002149号