Fibonnacci Suffix Array

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

문제

The sequence of Fibonacci words is defined as follows: fib_0=b,fib_1=a,fib_n=fib_n1fib_n2 for n2fib\_0=b, fib\_1=a, fib\_n=fib\_{n-1}fib\_{n-2} \text{ for } n \ge 2. fib_nfib\_n is the concatenation of fib_n1fib\_{n-1} and fib_n2fib\_{n-2}.

The first few Fibonacci words are: bb, aa, abab, abaaba, abaababaab, abaababaabaababa, abaababaabaababaababaabaab, \dots

A suffix array for string ss of length nn is a permutation sasa of integers from 11 to nn such that s\[sa_1..n],s\[sa_2..n],,s\[sa_n..n]s\[sa\_1.. n], s\[sa\_2..n], \dots, s\[sa\_n..n] is the list of non-empty suffixes of ss sorted in lexicographical order.

Let sasa be the suffix array for fib_nfib\_n. Your task is to calculate the value of (sa_p_1modm),(sa_p_2modm),,(sa_p_qmodm)(sa\_{p\_1} \bmod m), (sa\_{p\_2} \bmod m), \dots, (sa\_{p\_q} \bmod m).

입력

The input consists of several test cases terminated by end-of-file. For each test case:

The first line contains three integers nn, qq and mm.

The second line contains qq integers p_1,p_2,,p_qp\_1, p\_2, \dots, p\_q.

출력

For each test case, output qq values (sa_p_1modm),(sa_p_2modm),,(sa_p_qmodm)(sa\_{p\_1} \bmod m), (sa\_{p\_2} \bmod m), \dots, (sa\_{p\_q} \bmod m), separated by spaces.

제한

  • 1n10181 \le n \le 10^{18}
  • 1q1051 \le q \le 10^5
  • 1m2×1091 \le m \le 2 \times 10^9
  • 1p_imin(1018,fib_n)1 \le p\_i \le \min(10^{18}, |fib\_n|)
  • The sum of qq does not exceed 10610^6.