#P16287. [蓝桥杯 2026 省 Python A 组] 单词合并
[蓝桥杯 2026 省 Python A 组] 单词合并
Problem Description
Xiaolan has pairwise distinct words in the dictionary. Each word consists only of lowercase letters, and its length does not exceed .
Xiaolan defines an operation: perform exactly one of the following two transformations on a word:
- Insert one lowercase letter at any position.
- Delete any one letter from it.
Except for the inserted or deleted position, the relative order of the original letters remains unchanged.
Now, please count how many ordered word pairs (where ) satisfy: can be transformed into by performing exactly one operation as defined above.
Input Format
The first line contains a positive integer .
The next lines each contain a string consisting only of lowercase letters, representing a word.
Output Format
Output one line containing one integer, representing the number of ordered word pairs that satisfy the condition.
5
aab
ab
a
bb
b
8
Hint
Sample Explanation
The ordered word pairs that satisfy the condition are:
- : delete the st letter from to get .
- : insert the letter at the st position of to get .
- : delete the nd letter from to get .
- : insert the letter at the nd position of to get .
- : delete the st letter from to get .
- : insert the letter at the st position of to get .
- : delete the st letter from to get .
- : insert the letter at the st position of to get .
Constraints
For of the testdata, .
For all testdata, . It is guaranteed that all words are pairwise distinct.
Translated by ChatGPT 5