パナソニックグループ プログラミングコンテスト2025(AtCoder Beginner Contest 427)
F
Not Adjacent
AtCoder
⌀ 1605
原题
← EG →
翻译中…

Problem Statement

翻译中…

You are given a length-$N$ integer sequence $A=(A _ 1,A _ 2,\ldots,A _ N)$.

翻译中…

There are $2 ^ N$ (not necessarily contiguous) subsequences of $A$. Find how many subsequences $(A _ {i _ 1},A _ {i _ 2},\ldots,A _ {i _ k})\ (1\le i _ 1\lt i _ 2\lt\cdots\lt i _ k\le N)$ satisfy both of the following two conditions:

翻译中…
  • The selected elements are not adjacent in $A$. That is, $1+i _ j\ne i _ {j+1}$ holds for all $1\le j\lt k$.
  • The sum is a multiple of $M$. That is, $\displaystyle\sum _ {j=1} ^ kA _ {i _ j}\equiv0\pmod M$.
翻译中…

Even if two subsequences are equal as integer sequences, they are counted separately if the positions from which they are taken are different.

翻译中…

Constraints

翻译中…
  • $1\le N\le60$
  • $1\le M\le10 ^ 9$
  • $0\le A _ i\lt M$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A _ 1 A _ 2 \ldots A _ N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
7 6
3 1 4 1 5 3 2
Output #1
6
The following six subsequences satisfy the conditions: - $()=()$ - $(A _ 1,A _ 3,A _ 5)=(3,4,5)$ - $(A _ 1,A _ 4,A _ 7)=(3,1,2)$ - $(A _ 1,A _ 6)=(3,3)$ - $(A _ 2,A _ 5)=(1,5)$ - $(A _ 3,A _ 7)=(4,2)$ Thus, print `6`.
Input #2
15 10
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Output #2
798
Input #3
20 998244353
778718481 719092922 676292280 713825156 0 434453766 620370916 67922064 0 577696866 21516423 955580612 955580612 0 332156721 0 0 0 632133714 500614291
Output #3
40
题目信息

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