CF1202E.You Are Given Some Strings...

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string tt and nn strings s1,s2,,sns_1, s_2, \dots, s_n . All strings consist of lowercase Latin letters.

Let f(t,s)f(t, s) be the number of occurences of string ss in string tt . For example, f(aaabacaa,aa)=3f('\text{aaabacaa}', '\text{aa}') = 3 , and f(ababa,aba)=2f('\text{ababa}', '\text{aba}') = 2 .

Calculate the value of i=1nj=1nf(t,si+sj)\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{n} f(t, s_i + s_j) , where s+ts + t is the concatenation of strings ss and tt . Note that if there are two pairs i1i_1 , j1j_1 and i2i_2 , j2j_2 such that si1+sj1=si2+sj2s_{i_1} + s_{j_1} = s_{i_2} + s_{j_2} , you should include both f(t,si1+sj1)f(t, s_{i_1} + s_{j_1}) and f(t,si2+sj2)f(t, s_{i_2} + s_{j_2}) in answer.

输入格式

The first line contains string tt ( 1t21051 \le |t| \le 2 \cdot 10^5 ).

The second line contains integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ).

Each of next nn lines contains string sis_i ( 1si21051 \le |s_i| \le 2 \cdot 10^5 ).

It is guaranteed that i=1nsi2105\sum\limits_{i=1}^{n} |s_i| \le 2 \cdot 10^5 . All strings consist of lowercase English letters.

输出格式

Print one integer — the value of i=1nj=1nf(t,si+sj)\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{n} f(t, s_i + s_j) .

输入输出样例

  • 输入#1

    aaabacaa
    2
    a
    aa
    

    输出#1

    5
    
  • 输入#2

    aaabacaa
    4
    a
    a
    a
    b
    

    输出#2

    33
    
首页