class Solution {
public int solution(int[][] board) {
int answer = 0;
int n = board.length;
boolean[][] check = new boolean[n][n];
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[i].length; j++){
if(board[i][j] == 1){
check[i][j] = true;
if(i>0) check[i-1][j] = true;
if(j>0) check[i][j-1] = true;
if(i<n-1) check[i+1][j] = true;
if(j<n-1) check[i][j+1] = true;
if(i>0 && j>0) check[i-1][j-1] = true;
if(i>0 && j<n-1) check[i-1][j+1] = true;
if(i<n-1 && j>0) check[i+1][j-1] = true;
if(i<n-1 && j<n-1) check[i+1][j+1] = true;
}
}
}
for(int i = 0; i < check.length; i++){
for(int j = 0; j < check[i].length; j++){
if(!check[i][j]){
answer++;
}
}
}
return answer;
}
}
