using
System;
class
Solution
{
public
int
Count(
int
[][] matrix)
{
int
numRows = matrix.Length;
int
numCols = matrix[0].Length;
int
result = 0;
for
(
int
row = 0; row < numRows; ++row)
{
for
(
int
col = 0; col < numCols; ++col)
{
if
(matrix[row][col] == 1)
{
int
zeroCount = 0;
if
(row - 1 >= 0)
zeroCount += matrix[row - 1][col] == 0 ? 1 : 0;
if
(row + 1 < numRows)
zeroCount += matrix[row + 1][col] == 0 ? 1 : 0;
if
(col - 1 >= 0)
zeroCount += matrix[row][col - 1] == 0 ? 1 : 0;
if
(col + 1 < numCols)
zeroCount += matrix[row][col + 1] == 0 ? 1 : 0;
if
(row - 1 >= 0 && col - 1 >= 0)
zeroCount += matrix[row - 1][col - 1] == 0 ? 1 : 0;
if
(row - 1 >= 0 && col + 1 < numCols)
zeroCount += matrix[row - 1][col + 1] == 0 ? 1 : 0;
if
(row + 1 < numRows && col - 1 >= 0)
zeroCount += matrix[row + 1][col - 1] == 0 ? 1 : 0;
if
(row + 1 < numRows && col + 1 < numCols)
zeroCount += matrix[row + 1][col + 1] == 0 ? 1 : 0;
if
(zeroCount % 2 == 0 && zeroCount > 0)
result++;
}
}
}
return
result;
}
}
class
MainClass
{
public
static
void
Main(
string
[] args)
{
int
tc = 1;
while
(tc-- > 0)
{
int
[][] matrix = {
new
[] { 1, 0, 0 },
new
[] { 1, 1, 0 },
new
[] { 0, 1, 0 } };
Solution ob =
new
Solution();
int
ans = ob.Count(matrix);
Console.WriteLine(ans);
}
}
}