logo AlgoBeat OnlineJudge
登录 注册

#217728. [ICPC 2026 Wuhan I] String Matching

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Given strings consisting of lowercase letters. It is guaranteed that these strings are sorted in non-decreasing order of length, i.e. .

For any two different strings and with , define , which means the new string obtained by concatenating and in order, with in front and behind.

We define a function , where is a string of length . The value of is the number of positive integers () satisfying the following condition:

  • The first characters of string are exactly the same as the last characters of . That is, .

Your task is to compute the sum of over all valid pairs , that is:

输入格式

The input contains multiple lines.

The first line contains an integer (), representing the total number of given strings.

The next lines each contain a lowercase string ().

It is guaranteed that the total length of all strings in the test data satisfies .

输出格式

Output one line containing an integer, representing the total sum of all .

样例

样例输入 1

2
ak
hbcpc

样例输出 1

1

样例输入 2

3
aa
abaa
ababaa

样例输出 2

9

数据范围与提示

In the second sample, there are strings, and we can form different :

  • When : . The lengths such that the prefix equals the suffix are: .
  • When : . The lengths such that the prefix equals the suffix are: .
  • When : . The lengths such that the prefix equals the suffix are: .

The final answer is .