importjava.io.*;importjava.util.*;publicclassCowTip{publicstaticvoidmain(String[]args)throwsIOException{CowTip.Kattioio=newCowTip.Kattio("cowtip");intN=io.nextInt();int[][]farm=newint[N][N];for(inti=0;i<N;i++){Stringa=io.next();for(intj=0;j<N;j++){farm[i][j]=Character.getNumericValue(a.charAt(j));}}inttotalflips=0;for(inti=N-1;i>=0;i--){for(intj=N-1;j>=0;j--){// go from bottom right to top, check if it's a 1if(farm[i][j]==1){totalflips++;// cow flip rectanglefor(inta=0;a<=i;a++){for(intb=0;b<=j;b++){if(farm[a][b]==0){farm[a][b]=1;}else{farm[a][b]=0;}}}// end cow flip}}}io.println(totalflips);io.close();}// https://usaco.guide/general/io?lang=java#io-templatestaticclassKattioextendsPrintWriter{privateBufferedReaderr;privateStringTokenizerst;// standard inputpublicKattio(){this(System.in,System.out);}publicKattio(InputStreami,OutputStreamo){super(o);r=newBufferedReader(newInputStreamReader(i));}// USACO-style file inputpublicKattio(StringproblemName)throwsIOException{super(newFileWriter(problemName+".out"));r=newBufferedReader(newFileReader(problemName+".in"));}// returns null if no more inputpublicStringnext(){try{while(st==null||!st.hasMoreTokens())st=newStringTokenizer(r.readLine());returnst.nextToken();}catch(Exceptione){}returnnull;}publicintnextInt(){returnInteger.parseInt(next());}publicdoublenextDouble(){returnDouble.parseDouble(next());}publiclongnextLong(){returnLong.parseLong(next());}}}
#include <bits/stdc++.h>
usingnamespacestd;intmain(){freopen("cowtip.in","r",stdin);freopen("cowtip.out","w",stdout);// solution comes hereintn;cin>>n;vector<vector<char>>farm(n,vector<char>(n));for(inti=0;i<n;i++){for(intj=0;j<n;j++){chartemp;cin>>temp;farm[i][j]=temp;}}inttotalflips=0;for(inti=n-1;i>=0;i--){for(intj=n-1;j>=0;j--){// go from bottom right to top, check if it's a 1if(farm[i][j]=='1'){totalflips++;// cow flip rectanglefor(inta=0;a<=i;a++){for(intb=0;b<=j;b++){if(farm[a][b]=='0'){farm[a][b]='1';}else{farm[a][b]='0';}}}// end cow flip}}}cout<<totalflips;}