QOJ.ac

QOJ

Limite de temps : 1.5 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#18688. Putata Strikes Back

Statistiques

Putata loves string problems. Now he brings the traditional string problem back to competitive programming. His nemesis, Budada, is trying to prove that all the string problems are trivial. Now he wants you to solve this problem proposed by Putata to prove his claim.

You are given three string sequences $P,Q$ and $R$ of length $n,m$ and $k$. Each element of the a string sequence is a string. For example, if $P=\{\texttt{ab},\texttt{bcd}\}$, then $P_1=\texttt{ab}$,$P_2=\texttt{bcd}$. Find the number of pairs of non-empty string $(A,B)$ satisfying the following conditions:

  • $\exists i\in[1,n]$, s.t. $A$ is a prefix of $P_i$.
  • $\exists i\in[1,m]$, s.t. $B$ is a suffix of $Q_i$.
  • $\exists i\in[1,k]$, s.t. $AB$ is a substring of $R_i$.

String $A$ of length $n$ is said to be a prefix of string $B$ of length $m$ if and only if $n\leq m$ and $\forall i\in [1,n]$, $A_i=B_i$.

String $A$ of length $n$ is said to be a suffix of string $B$ of length $m$ if and only if $n\leq m$ and $\forall i\in [1,n]$, $A_i=B_{m-n+i}$.

String $A$ of length $n$ is said to be a substring of string $B$ of length $m$ if and only if $n\leq m$ and $\exists j\in [0,m-n]$, s.t. $\forall i\in [1,n]$, $A_i=B_{j+i}$.

The concatenation of string $A$ of length $n$ and string $B$ of length $m$, $AB$, is a string of length $n+m$, s.t. the $AB_{i}=A_i$ for $i\in [1,n]$, $AB_{i}=B_{i-n}$ otherwise.

Two pairs of strings $(A,B)$ and $(C,D)$ are considered different if and only if $A\neq C$ or $B\neq D$.

Input

The first line contains three integes $n,m$ and $k$ ($1\leq n,m,k\leq 3\times 10^5$), denoting the length of the sequence $P,Q$ and $R$.

The $i$-th of the following $n$ lines contains a string $P_i$ ($1\leq |P_i|\leq 3\times 10^5$).

The $i$-th of the following $m$ lines contains a string $Q_i$ ($1\leq |Q_i|\leq 3\times 10^5$).

The $i$-th of the following $k$ lines contains a string $R_i$ ($1\leq |R_i|\leq 3\times 10^5$).

It is guaranteed that all the strings consist of only lowercase English letters.

It is guaranteed that $1\leq \sum|P_i|,\sum|Q_i|,\sum|R_i|\leq 3\times 10^5$.

Output

Output one integer, denoting the answer.

Examples

Input 1

1 1 1
pb
pb
ppb

Output 1

2

Input 2

2 2 2
putata
budada
oipotato
suikapredator
putato
budapredatortato

Output 2

8

Input 3

2 2 1
aba
abc
bac
bca
abcabc

Output 3

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.