- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Do you know Jack-Jack? He is the youngest child of Parr family. The Parr family consists of Bob, Helen, Violet, Dashiell, and Jack-Jack. They are all characters of the “The Incredibles Movie”. Jack-Jack has many superpowers. Some of them are still not discovered yet. Recently, Helen saw Jack-Jack playing with matrices.
Jack-Jack thinks each cell of a matrix is powerful if it has three neighbors, which sum of their values is a power of two. Two cells are neighbors if and only if they share a side or corner. Jack-Jack is superhero, he is not a programmer. Can you count the number of powerful cells of the matrix for him?
ورودی
The first line of input contains two space separated integers $N$, $M$ – the number of rows and the number of columns of the matrix.
$$1 \leq N, M \leq 1000$$
In each of the next $N$ lines, there are $M$ space-separated integers each representing a cell of the matrix. The value each cell is a non-negative integer that does not exceed $10^6$.
خروجی
For each test, print a single integer, the number of powerful cells in the matrix.
مثالها
ورودی نمونه ۱
4 3
3 3 3
3 3 4
1 1 1
1 1 1
خروجی نمونه ۱
3
ورودی نمونه ۲
1 1
3
خروجی نمونه ۲
0
ارسال پاسخ برای این سؤال