CF1483F.Exam

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This year a Chunin Selection Exam is held again in Konoha, and taking part in it are nn ninjas named s1s_1 , s2s_2 , ..., sns_n . All names are distinct. One of the exam stages consists of fights between the participants. This year the rules determining the ninjas for each fight are the following: ninjas ii and jj fight against each other if the following conditions are held:

  • iji \neq j ;
  • sjs_{j} is a substring of sis_{i} ;
  • there is no kk except ii and jj that sjs_{j} is a substring of sks_{k} , and sks_{k} is a substring of sis_{i} .

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Your task is to find out how many fights are going to take place this year.

输入格式

The first line consists of the only integer nn ( 1n1061 \leq n \leq 10^{6} ) standing for the number of examinees.

The following nn lines contain their names. No two names coincide, all names are non-empty and consist of lowercase English letters. The total length of all names doesn't exceed 10610^6 .

输出格式

Print the only integer standing for the number of fights.

输入输出样例

  • 输入#1

    5
    hidan
    dan
    hanabi
    bi
    nabi

    输出#1

    3
  • 输入#2

    4
    abacaba
    abaca
    acaba
    aca

    输出#2

    4

说明/提示

In the first example hidan fights against dan, and hanabi fights against nabi, who also fights bi. Ninjas named hanabi and bi don't fight each other since there is the ninja called nabi who breaks the third condition for them.

In the second example the fights are held between abacaba and acaba, abacaba and abaca, acaba and aca, abaca and aca.

首页