Not Adjacent

AtCoder
IDabc427_f
Time4000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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
API Response (JSON)
{
  "problem": {
    "name": "Not Adjacent",
    "description": {
      "content": "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},\\ld",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc427_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a length-$N$ integer sequence $A=(A _ 1,A _ 2,\\ldots,A _ N)$.\nThere are $2 ^ N$ (not necessarily contiguous) subsequences of $A$. Find how many subsequences $(A _ {i _ 1},A _ {i _ 2},\\ld...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments