Codeforces Round 305 (Div. 1)
E
Mike and Friends
Codeforces
2800
原题
← D→
翻译中…

What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears!

翻译中…

In that country there is a rock band called CF consisting of $*n*$ bears (including Mike) numbered from $1$ to $*n*$.

翻译中…

image

翻译中…

Phone number of $*i*$-th member of CF is $*s*_{*i*}$. May 17th is a holiday named Phone Calls day. In the last Phone Calls day, everyone called all the numbers that are substrings of his/her number (one may call some number several times). In particular, everyone called himself (that was really strange country).

翻译中…

Denote as $*call*(*i*, *j*)$ the number of times that $*i*$-th member of CF called the $*j*$-th member of CF.

翻译中…

The geek Mike has $*q*$ questions that he wants to ask you. In each question he gives you numbers $*l*, *r*$ and $*k*$ and you should tell him the number

翻译中…

image

翻译中…

Input

翻译中…

The first line of input contains integers $*n*$ and $*q*$ ($1 ≤ *n* ≤ 2 × 10^{5}$ and $1 ≤ *q* ≤ 5 × 10^{5}$).

翻译中…

The next $*n*$ lines contain the phone numbers, $*i*$-th line contains a string $*s*_{*i*}$ consisting of lowercase English letters (image).

翻译中…

The next $*q*$ lines contain the information about the questions, each of them contains integers $*l*, *r*$ and $*k*$ ($1 ≤ *l* ≤ *r* ≤ *n*$ and $1 ≤ *k* ≤ *n*$).

翻译中…

Output

翻译中…

Print the answer for each question in a separate line.

翻译中…

样例

Input #1
5 5
a
ab
abab
ababab
b
1 5 1
3 5 1
1 5 2
1 5 3
1 4 5
Output #1
7
5
6
3
6
InputCopy OutputCopy
题目信息
题号
547E
时间限制
3 s
内存限制
256 MB
标签
数据结构
后缀结构
字符串
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。