For this Question: Tom loves Chess boards. He admires its symmetry and how the black and white colors are placed adjacently along both axis.
More formally, a chessboard-like coloring implies that no two adjacent cells have the same color and all the cells are painted either white or black.
On his birthday, Tom has been gifted a board which is in the form of an N*N grid. Every cell is painted either black or white. Since Tom loves the placement of colors in a chessboard, he will try to convert the board that has been gifted to him, identical to a chessboard. He has both black and white colors available to him. Help him find out the minimum number of cells he will have to recolor to paint his board similar to a chessboard.The first line contains an integer N, denoting the size of the board
Each of the next N lines contains N space-separated integers and each integer being either '0' or '1'
'1' represent black cell
'0' represents white cell

Constraints
1 &le; N &le; 1000A single integer that is the minimum number of cells that Tom will have to re-color in his board to convert the given board to a chess board like coloring.Input:
3
1 1 1
1 1 1
1 1 1

Output:
4

<b>Explanation:</b>
Convert to 
1 0 1
0 1 0
1 0 1
Thus he has to color 4 cells., I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {

                      BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
                      int n = Integer.parseInt(sc.readLine());
                      String[] arr = new String[n];
                      for(int i = 0  ; i < n ; i++){
                         arr[i] = sc.readLine();
                      }

                      int initial =1, paintWhenStartWithOne = 0;
                      for(int i = 0 ; i < n ;i++){
                          int current = initial;
                          for(int j = 0 ; j < arr[i].length() ; j+=2){
                              int val = arr[i].charAt(j) -48;

                              if(current != val)
                                paintWhenStartWithOne++;

                                current = 1-current;
                          }
                          initial = 1-initial;
                      }

                      initial =0;
                      int paintWhenStartWithZero = 0;
                      for(int i = 0 ; i < n ;i++){
                          int current = initial;
                          for(int j = 0 ; j < arr[i].length() ; j+=2){
                            int val =arr[i].charAt(j)-48;
                            if(current != val)
                                paintWhenStartWithZero++;

                                current = 1-current;
                          }
                          initial = 1-initial;
                      }


                      int ans = Math.min(paintWhenStartWithOne, paintWhenStartWithZero);
                      System.out.println(ans);

	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?