Under construction

Still being built. Things may change

Bomboni

Time limit2sMemory limit1024 MB

Summary
Count the right-and-down paths from top-left to bottom-right, avoiding obstacles, whose candy values multiply to a number divisible by k, modulo 998244353.
Level

Medium6 of 10

Topics
Dynamic programming, Number theory
Solved
No attempts yet

Statement

Iva is a big fan of candy! In front of her is an n×nn \times n field filled with candy and obstacles. Iva is currently in the upper left cell of the field and, by moving only down and right, she will travel to the lower right cell. The cell Iva is currently in does not contain an obstacle.

In every cell, there is either an obstacle or a piece of candy with a number written on it. Iva will eat all the candy she gets her hands on during her trip (including the candy in the first and last cell) and then multiply all the numbers on them. Iva's favourite number is kk, and she wants the product of the numbers on the candy she has eaten to be divisible by kk. Count how many such paths there are. Because that number can be huge, print it modulo 998 244 353998\,244\,353.

Input

The first line contains two integers nn and kk (1≤n≤5001 \le n \le 500, 1≤k≤1061 \le k \le 10^6), which denote the size of the field and Iva's favourite number.

Each of the next nn lines contains nn numbers describing the ii-th row of the field (−1≤ai,j≤106-1 \le a_{i,j} \le 10^6). If ai,j=−1a_{i,j} = -1, then that cell contains an obstacle. Otherwise, 1≤ai,j≤1061 \le a_{i,j} \le 10^6 and that cell contains a piece of candy with that number.

Output

Print a single line with the required number.

Hint

Clarification of the second example:

There are three possible paths such that the product is divisible by 6: (5, 2, 3, 3, 1), (5, 2, 3, 6, 1), (5, 7, 3, 6, 1).

Examples2

  1. Example 1

    Input
    2 2
    3 2
    1 4
    
    Expected output
    2
    
  2. Example 2

    Input
    3 6
    5 2 -1
    7 3 6
    -1 3 1
    
    Expected output
    3