Palindrome

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

A palindromic string is a string that reads the same forward as it does backward.

Yuuka has a string ss, and she would like to ask some questions about it. In each question, Yuuka will give you a list of integers x_1,x_2,,x_kx\_1, x\_2, \dots, x\_k (where x_ix\_i is 11-indexed) and an integer ll. Let tt be the concatenation of s(x_1,l),s(x_2,l),,s(x_k,l)s(x\_1, l), s(x\_2, l), \dots, s(x\_k, l), where s(x,p)s(x, p) is a substring of ss with length pp that starts at position xx. Yuuka would like to know the total number of palindromic substrings in tt.

입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains an integer nn denoting the length of the string (1n1051 \le n \le 10^5).

The second line contains nn integers s_1,s_2,,s_ns\_1, s\_2, \dots, s\_n denoting the string ss (1s_in1 \le s\_i \le n; the alphabet Yuuka uses may be large, so we just denote its characters by integers from 11 to nn).

The third line contains an integer mm denoting the number of questions (1m1051 \le m \le 10^5).

The ii-th of the following mm lines contains two integers k_ik\_i and l_il\_i, followed by k_ik\_i integers x_i,1,x_i,2,,x_i,k_ix\_{i, 1}, x\_{i, 2}, \dots, x\_{i, k\_i} (1k_i1051 \le k\_i \le 10^5, 1l_in1 \le l\_i \le n, k_il_i109k\_i \cdot l\_i \le 10^9, 1x_i,jnl_i+11 \le x\_{i, j} \le n - l\_i + 1).

It is guaranteed that neither the sum of all nn nor the sum of all k_ik\_i exceeds 10510^5.

출력

For each question, output an integer denoting the number of palindromic substrings.