Problem list
Log in
#coci00452 · COCI 2017/2018 Contest 1

Lozinke

Gold III 1.0 s 256 MB

Recently, there has been a breach of user information from the mega-popular social network Secret Network. Among the confidential information are the passwords of all users. Mihael, a young student who has been exploring computer security lately, found the whole thing really interesting. While experimenting with the social network, he found another security breach! When you input any string of characters that contains a substring equal to the actual password, the login will be successful. For example, if the user whose password is abc inputs one of the strings abc, abcd or imaabcnema, the system will successfully log him in, whereas the login will fail for axbc. Mihael wants to know how many ordered pairs of different users exist such that the first user, using their own password, can login as the second user.

Input

The first line of input contains the positive integer $N$ ($1 \le N \le 20,000$), the number of users. Each of the following $N$ lines contains the user passwords. The passwords consist of at least one and at most 10 lowercase letters of the English alphabet.

Output

The first and only line of output must contains the number of ordered pairs from the task.

Constraints

In test cases worth 40 points total, it will hold $1 \le N \le 2000$.

Example 1

Input
3
aaa
aa
abb
Output
1

Example 2

Input
3
x
x
xy
Output
4

Example 3

Input
5
mir
mirta
ta
ir
t
Output
6
Source
COCI 2017/2018 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code