Hide

Problem C
Find the Lucky Numbers

/problems/findtheluckynumbers/file/statement/en/img-0001.jpg
Image by Benjamin Wheatley, Four Leaf Clover by vecteezy.com

A lucky clover is a highly rare, four leaf clover. Much like looking through a field of clovers for any appearences of a four-leaf clover, your job is to find a lucky number $s$ in a field of numbers $a$, where arranged around it lie $4$ numbers which when added are a multiple of $s$. The numbers surrounding a lucky number are located diagonally to the top left, top right, bottom left, and bottom right of $s$. Note that a surrounding number may contribute to more than one lucky number, and a lucky number may also be part of the leaves of another lucky number.

Input

The first line of input consists of two integers $r$ and $c$ ($1 \le r \le 100$, $1 \le c \le 100$), denoting the numbers of rows and columns in the field. This next line contains an integer $s$ ($1 \le s \le 1\, 000$), which is the lucky number to search for. The following $r$ lines each contain $c$ integers $a_{ij}$ ($1 \leq a_{ij} \leq 1\, 000$) comprising the field of numbers.

Output

Output a single integer, the number of occurrences of the lucky number in the field.

Sample Input 1 Sample Output 1
4 10
7
1 2 8 9 1 2 5 5 8 3
6 7 2 8 4 9 1 7 5 8
5 7 3 9 5 5 7 3 1 2
8 6 7 6 4 5 2 7 8 6
2

Please log in to submit a solution to this problem

Log in