Codeforces Round 326 (Div. 1)
F
Duff is Mad
Codeforces
3000
原题
← E→
翻译中…

Duff is mad at her friends. That's why she sometimes makes Malek to take candy from one of her friends for no reason!

翻译中…

image

翻译中…

She has $*n*$ friends. Her $*i*$-th friend's name is $*s*_{*i*}$ (their names are not necessarily unique). $*q*$ times, she asks Malek to take candy from her friends. She's angry, but also she acts with rules. When she wants to ask Malek to take candy from one of her friends, like $*k*$, she chooses two numbers $*l*$ and $*r*$ and tells Malek to take exactly image candies from him/her, where $*occur*(*t*, *s*)$ is the number of occurrences of string $*t*$ in $*s*$.

翻译中…

Malek is not able to calculate how many candies to take in each request from Duff. That's why she asked for your help. Please tell him how many candies to take in each request.

翻译中…

Input

翻译中…

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

翻译中…

The next $*n*$ lines contain the names. $*i*$-th of them contains an string $*s*_{*i*}$, consisting of lowercase English letters (image).

翻译中…

The next $*q*$ lines contain the requests. Each of them contains three integers, $*l*, *r*$ and $*k*$ (says that Malek should take image candies from Duff's $*k*$-th friend).

翻译中…

Output

翻译中…

Print the answer to each request in one line.

翻译中…

样例

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

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