Problem:
Quality Management
The fabric coasters produced and sold by Aizu Takada City are known for their symmetrical design and beauty. As part of quality control, Aizu Takada has installed cameras on the production line to automatically verify that the images obtained from each coaster are symmetrical. Each coaster is represented as a
N
×
N
pixel square black and white image. Each pixel takes a value of 0 or 1, corresponding to a white or black image.
We have decided to update the software of our image analysis system in conjunction with the equipment upgrade of our production line. The new system has been devised to reduce the amount of communication data, and the data is sent from the camera to the analysis system in the following way.
Information about the first coaster flowing into the line is sent to the system as an image of
N
×
N
pixels.
For the second and subsequent coasters, only the difference from the previous image is sent. The difference is given as a set of pixel positions that have changed from "0 to 1" or "1 to 0".
Write a program that reads
C
coasters by the pixel information of the first image and the difference information of the following
C
- 1 sheet, and reports the number of coasters of vertically symmetrical and horizontally symmetrical.
Input
The input is given in the following format.
C
N
p
11
p
12
...
p
1N
p
21
p
22
...
p
2N
:
p
N1
p
N2
...
p
NN
diff
1
diff
2
:
diff
C−1
In the first line, the number of coasters
C
(1 ≤
C
≤ 10000) and the number of vertical and horizontal pixels in the image
N
(2 ≤
N
≤ 1000 and
N
is even) are given. From the second line to the line
N
+ 1 represent the pixels of the first coaster image
N
row ×
N
elements
p
ij
(
p
ij
is 0 or 1) are given.
After the line
N
+ 2, the difference
diff
i
representing the information of the second and subsequent coasters is given in the following format.
The number of changed pixels
D
(0 ≤
D
≤ 100) is given in the first line. In the following
D
lines, the row and column numbers of the changed pixels
r
i
and
c
i
are given, respectively. (1 ≤
r
i
,
c
i
≤
N
) . The same position cannot be given more than once in
diff
i
.
Output
Output the number of coasters that are vertically symmetrical and horizontally symmetrical in a line.
Sample Input 1
7 8
00100000
00011000
10111101
01100110
01000110
10111101
00011000
00100100
2
5 3
1 6
1
6 8
3
6 8
3 3
3 6
2
6 3
6 6
0
2
3 8
6 8
Sample Output 1
3
The image of the coaster for input example 1 is shown below. In this case, the second, fifth, and sixth coasters are symmetrical vertically and horizontally, so they are reported as 3.
Sample Input 2
1 6
000000
000000
010010
010010
000000
000000
Sample Output 2
1
Sample Input 3
2 2
00
00
4
1 1
1 2
2 1
2 2
Sample Output 3
2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int INF = 1 << 30;

int C, n;
vector<vector<int>> p;
int check(int x, int y) {
    if (p[x][y] == p[x][n-y-1] && p[x][y] == p[n-x-1][y] && p[x][y] == p[n-x-1][n-y-1]) return 1;
    else return 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> C >> n;
    p.resize(n);
    for (int i = 0; i < n; i++) {
        p[i].resize(n);
        string s;
        cin >> s;
        for (int j = 0; j < n; j++) {
            p[i][j] = s[j]-'0';
        }
    }
    
    int cnt = 0;
    for (int i = 0; i < n/2; i++) {
        for (int j = 0; j < n/2; j++) {
            if (check(i, j)) cnt++;
        }
    }
    int ans = 0;
    if (cnt == n*n/4) ans++;
    for (int i = 0; i < C-1; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int r, c;
            cin >> r >> c;
            r--, c--;

            if (check(r, c)) cnt--;
            p[r][c] = 1-p[r][c];
            if (check(r, c)) cnt++;
        }
        if (cnt == n*n/4) ans++;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 7296
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)

int calcNr(int r, int N) {
    if (r >= N / 2) r = N - r - 1;
    return r;
}

int calcNc(int c, int N) {
    if (c >= N / 2) c = N - c - 1;
    return c;
}

int main() {
    int C, N;
    cin >> C >> N;

    vector<vector<int>> P(N, vector<int>(N));
    rep(i, N) {
        rep(j, N) {
            char tmp;
            cin >> tmp;
            P[i][j] = tmp - '0';
        }
    }

    // 前計算
    // S[i][j] := P[i][j], P[N - i - 1][j], P[i][N - j - 1], P[N - i - 1][N - j - 1] の和
    // cnt := Sの内、0または4である要素数
    vector<vector<int>> S(N / 2, vector<int>(N / 2, 0));
    int cnt = 0;

    rep(i, N) {
        int nr = calcNr(i, N);
        rep(j, N) {
            int nc = calcNc(j, N);
            S[nr][nc] += P[i][j];
        }
    }

    rep(i, N / 2) {
        rep(j, N / 2) {
            if (S[i][j] == 4 || S[i][j] == 0) cnt++;
        }
    }

    // クエリ処理
    int ans = 0;
    if (cnt == N * N / 4) ans++;

    rep(i, C - 1) {
        int D;
        cin >> D;

        rep(j, D) {
            int r, c;
            cin >> r >> c;
            r--; c--;

            // Pの更新
            P[r][c] = ((P[r][c] == 0) ? 1 : 0);

            // S, cntの更新
            int diff = ((P[r][c] == 1) ? 1 : -1);
            int nr = calcNr(r, N), nc = calcNc(c, N);
            if (S[nr][nc] == 4 || S[nr][nc] == 0) cnt--;
            S[nr][nc] += diff;
            if (S[nr][nc] == 4 || S[nr][nc] == 0) cnt++;
        }

        // ansの更新
        if (cnt == N * N / 4) ans++;
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 250
memory_kb: 8360
final_rank: 12

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
  int c,n; cin >> c >> n;
  int aaa=0;
  vector<vector<char>> A(n,vector<char>(n));
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      cin >> A[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n/2;++i){
    for(int j=0;j<n/2;++j){
      if(A[i][j]==A[i][n-1-j]&&A[i][j]==A[n-1-i][j]&&A[i][j]==A[n-1-i][n-1-j]){
        ans++;
      }
    }
  }
  if(ans==n*n/4)aaa++;
  for(int i=0;i<c-1;++i){
    int d; cin >> d;
    for(int j=0;j<d;++j){
      int a,b; cin >> a >> b;
      a--;b--;
      bool p=false;
      if(A[a][b]==A[a][n-1-b]&&A[a][b]==A[n-1-a][b]&&A[a][b]==A[n-1-a][n-1-b]){
        p=true;
      }
      if(A[a][b]=='0'){
        A[a][b]='1';
      }else{
        A[a][b]='0';
      }
      if(p){
        ans--;
      }else{
        if(A[a][b]==A[a][n-1-b]&&A[a][b]==A[n-1-a][b]&&A[a][b]==A[n-1-a][n-1-b]){
          ans++;
        }
      }
    }
    if(ans==n*n/4)aaa++;
  }
  cout << aaa << endl;
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 4440
final_rank: 8

code_snippet: #include<iostream>
#include<string>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include <unordered_map>
#include<iomanip>
#include<numeric>
#include<stack>
#include<tuple>
#include<unordered_set>
#define all(a) (a).begin(), (a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, x) for(long long i = 0; i < (x); i++)
#define REP(i, x, limit) for (ll i = (ll)x; i <= (ll)limit; i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
int X[4] = { 1, 0, -1, 0 };//右、上、左、下
int Y[4] = { 0, 1, 0, -1 };

int main() {
	ll C, N, ans = 0;
	cin >> C >> N;
	vector<vector<char>>list(N, vector<char>(N));
	rep(i, N) {
		rep(j, N) {
			cin >> list[i][j];
		}
	}
	ll ok = 0;
	rep(i, N / 2) {
		rep(j, N / 2) {
			if (list[i][j] == list[N - i - 1][N - j - 1] && list[i][j] == list[i][N - j - 1] && list[i][j] == list[N - i - 1][j]) {
				ok++;
			}
		}
	}
	if (ok == N * N / 4) {
		ans++;
	}
	rep(i, C-1) {
		ll a;
		cin >> a;
		rep(j, a) {
			ll b, c;
			cin >> b >> c;
			b--, c--;
			if (list[b][c] == list[N - b - 1][N - c - 1] && list[b][c] == list[b][N - c - 1] && list[b][c] == list[N - b - 1][c]) {
				ok--;
			}				
			if (list[b][c] == '0') {
				list[b][c] = '1';
			}
			else {
				list[b][c] = '0';
			}
			if (list[b][c] == list[N - b - 1][N - c - 1] && list[b][c] == list[b][N - c - 1] && list[b][c] == list[N - b - 1][c]) {
				ok++;
			}
		}
		if (ok == N * N / 4) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 4364
final_rank: 6

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
  int c,n; cin >> c >> n;
  int aaa=0;
  vector<vector<char>> A(n,vector<char>(n));
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      cin >> A[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n/2;++i){
    for(int j=0;j<n/2;++j){
      if(A[i][j]==A[i][n-1-j]&&A[i][j]==A[n-1-i][j]&&A[i][j]==A[n-1-i][n-1-j]){
        ans++;
      }
    }
  }
  if(ans==n*n/4)aaa++;
  for(int i=0;i<c-1;++i){
    int d; cin >> d;
    for(int j=0;j<d;++j){
      int g,r;
      int a,b; cin >> a >> b;
      g=a;r=b;
      g--;r--;
      a--;b--;
      bool p=false;
      if(A[g][r]==A[g][n-1-r]&&A[g][r]==A[n-1-g][r]&&A[g][r]==A[n-1-g][n-1-r]){
        p=true;
      }
      if(A[a][b]=='0'){
        A[a][b]='1';
      }else{
        A[a][b]='0';
      }
      if(p){
        ans--;
      }else{
        if(A[g][r]==A[g][n-1-r]&&A[g][r]==A[n-1-g][r]&&A[g][r]==A[n-1-g][n-1-r]){
          ans++;
        }
      }
    }
    if(ans==n*n/4)aaa++;
  }
  cout << aaa << endl;
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 4432
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
using namespace std;

int main(){
  int c,n; cin >> c >> n;
  int aaa=0;
  vector<vector<char>> A(n,vector<char>(n));
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      cin >> A[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n/2;++i){
    for(int j=0;j<n/2;++j){
      if(A[i][j]==A[i][n-1-j]&&A[i][j]==A[n-1-i][j]&&A[i][j]==A[n-1-i][n-1-j]){
        ans++;
      }
    }
  }
  if(ans==n*n/4)aaa++;
  for(int i=0;i<c-1;++i){
    int d; cin >> d;
    for(int j=0;j<d;++j){
      int g,r;
      int a,b; cin >> a >> b;
      if(a>n/2){
        g=n+1-a;
      }else{
        g=a;
      }
      if(b>n/2){
        r=n+1-b;
      }else{
        r=b;
      }
      g--;r--;
      a--;b--;
      bool p=false;
      if(A[g][r]==A[g][n-1-r]&&A[g][r]==A[n-1-g][r]&&A[g][r]==A[n-1-g][n-1-r]){
        p=true;
      }
      if(A[a][b]=='0'){
        A[a][b]='1';
      }else{
        A[a][b]='0';
      }
      if(p){
        ans--;
      }else{
        if(A[g][r]==A[g][n-1-r]&&A[g][r]==A[n-1-g][r]&&A[g][r]==A[n-1-g][n-1-r]){
          ans++;
        }
      }
    }
    if(ans==n*n/4)aaa++;
  }
  cout << aaa << endl;
  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 4440
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int C, N;
    cin >> C >> N;
    vector S(N, vector<bool>(N));
    rep(i, 0, N) rep(j, 0, N) {
        char p;
        cin >> p;
        S[i][j] = (p == '1');
    }
    
    int M = N / 2;
    int diff = M*M;
    rep(i, 0, M) rep(j, 0, M) {
        if (S[i][j] == S[N - i - 1][j] && S[i][j] == S[i][N - j - 1] && S[i][j] == S[N - i - 1][N - j - 1]) --diff;
    }
    
    int ans = (diff == 0 ? 1 : 0);
    
    rep(query, 0, C - 1) {
        int D;
        cin >> D;
        
        rep(k, 0, D) {
            int i, j;
            cin >> i >> j;
            --i, --j;
            
            if (S[i][j] == S[N - i - 1][j] && S[i][j] == S[i][N - j - 1] && S[i][j] == S[N - i - 1][N - j - 1]) ++diff;
            S[i][j] = !S[i][j];
            if (S[i][j] == S[N - i - 1][j] && S[i][j] == S[i][N - j - 1] && S[i][j] == S[N - i - 1][N - j - 1]) --diff;
        }
        
        if (diff == 0) {
            ++ans;
        }
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 90
memory_kb: 3596
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int c, n; cin >> c >> n;
    vector<string> p(n);
    rep(i, n)cin >> p[i];
    auto same = [&](int y, int x) {
        if (y >= (n + 1) / 2)y = n - 1 - y;
        if (x >= (n + 1) / 2)x = n - 1 - x;
        return p[y][x] == p[n - 1 - y][x] && p[y][x] == p[y][n - 1 - x] && p[y][x] == p[n - 1 - y][n - 1 - x];
    };
    int cnt = 0;
    rep(i, (n + 1) / 2)rep(j, (n + 1) / 2)if (!same(i, j))cnt++;
    int ans = 0;
    if (cnt == 0)ans++;
    rep(i, c - 1) {
        int d; cin >> d;
        rep(j, d) {
            int r, c; cin >> r >> c;
            r--, c--;
            if (same(r, c))cnt++;
            if (p[r][c] == '0')p[r][c] = '1';
            else p[r][c] = '0';
            if (same(r, c))cnt--;
        }
        if (cnt == 0)ans++;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 5504
final_rank: 5

code_snippet: #include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define print(a) cout<<a<<endl
typedef long long ll;
#define yn(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YN(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define so(a) sort(a.begin(),a.end())
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define a2i(a,s) (ll)(a-s)
#define i2a(s,a) (char)(s+a)
#define ssize(a) a.size()
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<pair<ll,ll>,ll> P3;
typedef pair<pair<ll,ll>,pair<ll,ll>> P4;

typedef pair<ll, ll> Pll;
typedef pair<ll,Pll> Plll;
typedef pair<Pii, int> Piii;
const ll INF = 1000000000000000000;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//vector<ll> saiki(ll bit,ll n){
//	vector<ll> s(n);
//	for(ll i=0;i<n;i++){
//		if(bit&(1<<i)){
//			s[i]=1;
//		}else s[i]=0;
//	}
//	return s;
//}
int main(){
//入力

	cin.tie(0);
	ios::sync_with_stdio(0);

	ll c,n;
	cin>>c>>n;
	vector<vector<char> > p(n,vector<char> (n));
	rep(i,n)rep(j,n)cin>>p[i][j];
	set<Pll> st2;
	for(ll i=0;i<n/2;i++){
		for(ll j=0;j<n/2;j++){
			if(p[i][j]==p[i][n-1-j]&&p[i][j]==p[n-i-1][j]&&p[i][j]==p[n-1-i][n-1-j]){
				st2.insert({i,j});
			}
		}
	}
//	cout<<v<<endl;
//判定
	ll ans=0;
	if(st2.size()==(n/2)*(n/2))ans++;
	rep(i,c-1){
		ll d;
		cin>>d;
		set<Pll> st;
		vector<Pll> u;
		rep(j,d){
			ll x,y;
			cin>>x>>y;
			if(p[x-1][y-1]=='0')p[x-1][y-1]='1';
			else p[x-1][y-1]='0';
			u.push_back({x,y});
		}
		rep(j,d){
			ll x=u[j].first,y=u[j].second;
			ll X=x-1,Y=y-1;
			if(X>=n/2)X=n-X-1;
			if(Y>=n/2)Y=n-Y-1;
			if(st.find({X,Y})!=st.end())continue;
			if(p[X][Y]==p[X][n-1-Y]&&p[X][Y]==p[n-X-1][Y]&&p[X][Y]==p[n-1-X][n-1-Y]){
				st2.insert({X,Y});
				st.insert({X,Y});
			}else{
				st2.erase({X,Y});
			}

		}
//		rep(j,d){
//			ll x=u[j].first,y=u[j].second;
//			if(p[x-1][y-1]=='0')p[x-1][y-1]='1';
//			else p[x-1][y-1]='0';
////			if(i==0)cout<<x<<" "<<y<<endl;
//		}
//		cout<<V<<endl;
		if(st2.size()==(n/2)*(n/2)){
			ans++;
		}
	}

	cout<<ans<<endl;
//判定２
//	for(ll i=0;i<n;i++){
//		for(ll j=0;j<n/2;j++){
//			if(p[i][j]!=p[i][n-j-1]){
//				cout<<
//			}
//		}
//	}

	return 0;

}
accuracy: 1
time_ms: 410
memory_kb: 20080
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int C,N;
    cin>>C>>N;
    vector<string> A(N);
    rep(i,N)cin>>A[i];
    int now=0;
    rep(i,N)rep(j,N)now+=(A[i][j]==A[N-i-1][j])+(A[i][j]==A[i][N-j-1]);
    now/=2;

    int ans=0;
    if(now==N*N) ans++;
    rep(_,C-1){
        int D;
        cin>>D;
        rep(_,D){
            int r,c;
            cin>>r>>c;
            r--;c--;
            if(A[r][c]==A[N-r-1][c]) now--;
            if(A[r][c]==A[r][N-c-1]) now--;
            A[r][c]='0'+('1'-A[r][c]);
            if(A[r][c]==A[N-r-1][c]) now++;
            if(A[r][c]==A[r][N-c-1]) now++;
        }
        if(now==N*N)ans++;
    }
    cout<<ans<<"\n";
}
accuracy: 1
time_ms: 50
memory_kb: 4736
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(ll i=0;i<N;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back


int main(){
    int C,N;cin>>C>>N;
    vector<vector<int>>P(N,vector<int>(N,0));
    rep(i,N){
        string s;cin>>s;
        rep(j,N)if(s[j]=='1')P[i][j]=1;
    }
    int ans = 0;
    int ct = 0;
    rep(i,(N+1)/2)rep(j,(N+1)/2){
        int x = 0;
        x+=P[i][j];
        x+=P[i][N-j-1];
        x+=P[N-i-1][j];
        x+=P[N-i-1][N-j-1];
        if(x!=0&&x!=4)ct++;
    }
    if(ct==0)ans++;
    rep(c,C-1){
        int D;cin>>D;
        rep(d,D){
            int r,c;cin>>r>>c;r--;c--;
            int bef = P[r][c]+P[N-r-1][c]+P[r][N-c-1]+P[N-r-1][N-c-1];
            if(bef==0||bef==4)ct++;
            P[r][c]=1-P[r][c];
            bef = P[r][c]+P[N-r-1][c]+P[r][N-c-1]+P[N-r-1][N-c-1];
            if(bef==0||bef==4)ct--;
        }
        if(ct==0)ans++;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 230
memory_kb: 7392
final_rank: 11

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

int c, n;

pii getza(int cx, int cy){
	if (cx >= n / 2)
		cx = n - cx - 1;
	if (cy >= n / 2)
		cy = n - cy - 1;
	return{ cx, cy };
}

int nanm(int cx, int cy){
	int ret = 0;
	if (cx >= n / 2)
		ret += 1;
	if (cy >= n / 2)
		ret+= 2;
	return ret;
}

signed main() {
	cin >> c >> n;
	int mp[251][251][4] = {};

	int wr = 0;

	REP(i, n){
		char ch;
		scnaf("%c", &ch);
		REP(j, n){
			pii cc = getza(i, j);
			scnaf("%c",&ch);
			mp[cc.first][cc.second][nanm(i,j)] = ch - '0';
		}
	}

	REP(i, n/2){
		REP(j, n/2){
			pii cc = getza(i, j);
			int cs = mp[cc.first][cc.second][0] + mp[cc.first][cc.second][1] + mp[cc.first][cc.second][2] + mp[cc.first][cc.second][3];
			if (cs < 4 && cs > 0)
				wr++;
		}
	}

	int ans = 0;

	if (!wr)
		ans++;

	REP(i, c-1){
		int m;
		cin >> m;
		REP(i, m){
			int x, y;
			cin >> x >> y;
			x--, y--;
			pii cc = getza(x, y);
			int bef = mp[cc.first][cc.second][0] + mp[cc.first][cc.second][1] + mp[cc.first][cc.second][2] + mp[cc.first][cc.second][3];

			mp[cc.first][cc.second][nanm(x, y)] = 1 - mp[cc.first][cc.second][nanm(x, y)];

			int cur = mp[cc.first][cc.second][0] + mp[cc.first][cc.second][1] + mp[cc.first][cc.second][2] + mp[cc.first][cc.second][3];

			if ((bef == 4 ||bef == 0) && (cur > 0 && cur < 4)){
				wr++;
			}

			if ((cur == 4 || cur == 0) && (bef > 0 && bef < 4)){
				wr--;
			}
		}

		if (!wr)
			ans++;
	}

	printf("%d\n", ans);
	return 0;
}
accuracy: 0.375
time_ms: 10
memory_kb: 4552
final_rank: 18

code_snippet: #include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const size_t C_MIN = 1;
const size_t C_MAX = 10000;
const size_t N_MIN = 2;
const size_t N_MAX = 1000;
const size_t D_MIN = 0;
const size_t D_MAX = 100;

inline int next(int N, int i)
{
	return (((N - i - 1) + N) % N);
}

inline bool isSymmetry(int N, vector<vector<char>>& pat, int i, int j)
{
	//int const N = pat[0].size();
	char ch = pat[i][j];
	return (ch == pat[i][next(N, j)]
		&& ch == pat[next(N, i)][j]
		&& ch == pat[next(N, i)][next(N, j)]);
}


int calcInit(vector<vector<char>>& pat)
{
	int const N = pat[0].size();
	int cnt = 0;

	for (int i = 0; i < N / 2; i++)
	{
		for (int j = 0; j < N / 2; j++)
		{
			if (!isSymmetry(N, pat, i, j))
			{
				cnt++;
			}
		}
	}
	return cnt;
}

inline void toggle(vector<vector<char>>& pat, int r, int c)
{

	if (pat[r][c] == '0')
	{
		pat[r][c] = '1';
	}
	else
	{
		pat[r][c] = '0';
	}
}

int main()
{
	// コースターの枚数
	int c = 0;
	cin >> c;
	if (c < C_MIN || C_MAX < c)
	{
		cout << C_MIN << " <= c <= " << C_MAX << ") but input " << c << endl;
		exit(1);
	}

	// コースターのサイズ
	int n = 0;
	cin >> n;
	if (n < N_MIN || N_MAX < n)
	{
		cout << N_MIN << " <= n <= " << N_MAX << ") but input " << n << endl;
		exit(1);
	}
	vector<vector<char>> VIC(n, vector<char>(n));
	// １枚目のコースターの画像情報の入力
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> VIC[i][j];
		}
   	}
	int const N = VIC[0].size();
	int count = 0;
	int dcnt = calcInit(VIC);
	if (dcnt == 0) count++;
	// 2枚目以降の情報入力
	for (int i = 0; i < c - 1; i++)
	{
		int d;
		cin >> d;
		if (d < D_MIN || D_MAX < d)
		{
			cout << D_MIN << " <= d <= " << D_MAX << ") but input " << d << endl;
			exit(1);
		}

		for (int j = 0; j < d; j++)
		{
			bool pre = false;
			bool post = false;
			int r = 0;
			int c = 0;
			cin >> r >> c;
			r--; c--;
			pre = isSymmetry(N, VIC, r, c);
			toggle(VIC, r, c);
			post = isSymmetry(N, VIC, r, c);
			if (!pre && post)
			{
				dcnt--;
			}
			else if (pre && !post)
			{
				dcnt++;
			}
		}
		if (dcnt == 0)
		{
			count++;
		}
	}
	cout << count << endl;
	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 4468
final_rank: 10

code_snippet: #include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const size_t C_MIN = 1;
const size_t C_MAX = 10000;
const size_t N_MIN = 2;
const size_t N_MAX = 1000;
const size_t D_MIN = 0;
const size_t D_MAX = 100;

using vc = vector<char>; // charの１次元の型にvcの別名を付ける
using vic = vector<vc>;  // vcの2次元の型にvicの別名を付ける
using vvic = vector<vic>; // vcの３次元の型にvvicの別名を付ける

void toggle(vector<vector<char>>& rowlist, int r, int c)
{

	if (rowlist[r][c] == '0')
	{
		rowlist[r][c] = '1';
	}
	else
	{
		rowlist[r][c] = '0';
	}
}

// 上下対称確認
bool isHorizontalSymmetry(vector<vector<char>>& left, vector<vector<char>>& right)
{
	int const N = left[0].size();
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (left[i][j] != right[N - 1 - i][j])
			{
				// 上下対称ではない
				return false;
			}
		}
	}
	// 上下対称です
	return true;
}

// 左右対称確認
bool isVerticalSymmetry(vector<vector<char>>& left, vector<vector<char>>& right)
{
	int const N = left[0].size();
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (left[i][j] != right[i][N - 1 - j])
			{
				// 左右対称ではない
				return false;
			}
		}
	}
	// 左右対称です
	return true;
}

int main()
{
	// コースターの枚数
	int c = 0;
	cin >> c;
	if (c < C_MIN || C_MAX < c)
	{
		cout << C_MIN << " <= c <= " << C_MAX << ") but input " << c << endl;
		exit(1);
	}
	// コースターのサイズ
	int n = 0;
	cin >> n;
	if (n < N_MIN || N_MAX < n)
	{
		cout << N_MIN << " <= n <= " << N_MAX << ") but input " << n << endl;
		exit(1);
	}

	vc VC(n);
	vic VIC(n, VC);
	vvic VVIC(c, VIC);
	// １枚目のコースターの画像情報の入力
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> VVIC[0][i][j];
		}
		if (VVIC[0][i].size() != n)
		{
			std::string str(VVIC[0][i].begin(), VVIC[0][i].end());
			cout << " patlist.size == " << n << " but input " << str << " size is " << str.size() << endl;
			exit(1);
		}
	}
	// 2枚目以降の情報入力
	for (int i = 1; i < c; i++)
	{
		VVIC[i] = VVIC[i - 1];
		int d;
		cin >> d;
		if (d < D_MIN || D_MAX < d)
		{
			cout << D_MIN << " <= d <= " << D_MAX << ") but input " << d << endl;
			exit(1);
		}

		for (int j = 0; j < d; j++)
		{
			int r;
			int c;
			cin >> r >> c;
			toggle(VVIC[i], r - 1, c - 1);
		}
	}

	int count = 0;
	for (int i = 0; i < c; i++)
	{
		if (isHorizontalSymmetry(VVIC[i], VVIC[i])
			&& isVerticalSymmetry(VVIC[i], VVIC[i])
			)
		{
			count++;
		}
	}
	cout << count << endl;

	return 0;
}
accuracy: 0.375
time_ms: 10
memory_kb: 6796
final_rank: 19

code_snippet: #include <iostream>
#include <map>

using namespace std;

int P[1000][1000];
int N;
map<int, int> d;

void diff()
{
    int i, j;

    for (i = 0; i < N / 2; i++){
        for (j = 0; j < N / 2; j++){
            if (P[i][j] != P[i][N - j - 1]){
                d.insert(make_pair(i * 1000 + (N - j - 1), 0));
            }
            if (P[i][j] != P[N - i - 1][j]){
                d.insert(make_pair((N - i - 1) * 1000 + j, 0));
            }
            if (P[i][j] != P[N - i - 1][N - j - 1]){
                d.insert(make_pair((N - i - 1) * 1000 + (N - j - 1), 0));
            }
        }
    }
}

void update(int r, int c)
{
    auto it = d.find(r * 1000 + c);
    if (it == d.end()){
        d.insert(make_pair(r * 1000 + c, 0));
    }
    else {
        d.erase(it);
    }
}

int main(void)
{
    int C;
    string p;
    int D;
    int r, c;
    int i, j;
    int cnt;

    cin >> C >> N;
    for (i = 0; i < N; i++){
        cin >> p;
        for (j = 0; j < N; j++){
            P[i][j] = p[j] - '0';
        }
    } 

    diff();
    if (d.empty()){
        cnt++;
    }
    // cout << "<";
    // for (auto it = d.begin(); it != d.end(); it++){
    //     cout << "[" << it->first << "]";
    // }
    // cout << ">" << endl;


    for (i = 0; i < C - 1; i++){
        cin >> D;
        for (j = 0; j < D; j++){
            scanf("%d%d", &r, &c);
            r--;
            c--;
            if (r < N / 2 && c < N / 2){
                update(N - r - 1, c);
                update(r,         N - c - 1);
                update(N - r - 1, N - c - 1);
            }
            else {
                update(r, c);
            }
        }
        if (d.empty()){
            cnt++;
        }
        // cout << "<";
        // for (auto it = d.begin(); it != d.end(); it++){
        //     cout << "[" << it->first << "]";
        // }
        // cout << ">" << endl;
    }
    cout << cnt << endl;

    return (0);
}
accuracy: 1
time_ms: 280
memory_kb: 22588
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long

/*
6:51~7:05
13:07~
*/

signed main(){
	int q,n;cin>>q>>n;
	vector<string> s(n);

	for(auto&&e:s)cin>>e;

	auto enu=[&](int x,int y){
		vector<pair<int,int>> vec;
		int x2=n-x-1,y2=n-y-1;

		for(int S=0;S<4;S++){
			pair<int,int> p;
			if(S>>0&1)p.first=x;
			else p.first=x2;
			if(S>>1&1)p.second=y;
			else p.second=y2;
			vec.push_back(p);
		}

		return vec;
	};

	auto fit=[&](int x,int y){
		auto vec=enu(x,y);
		for(int i=1;i<3;i++){
			if(s[vec[0].first][vec[0].second]!=s[vec[i].first][vec[i].second]){
				return 0;
			}
		}
		return 1;
	};

	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cnt+=fit(i,j);
		}
	}

	int ans=(cnt==n*n);
	q--;
	while(q--){
		int m;cin>>m;
		while(m--){
			int x,y;cin>>x>>y;
			x--;y--;
			for(auto&&[nx,ny]:enu(x,y)){
				cnt-=fit(nx,ny);
			}
			if(s[x][y]=='0')s[x][y]='1';
			else s[x][y]='0';
			for(auto&&[nx,ny]:enu(x,y)){
				cnt+=fit(nx,ny);
			}
		}

		if(cnt==n*n){
			ans++;
		}
	}

	cout<<ans<<endl;
}
accuracy: 1
time_ms: 810
memory_kb: 5368
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
char p[1000][1001];
int dw[1000][500],dh[500][1000];
int main(void)
{
	int c,n,i,j,wc,hc,d,r,cc,cnt,c2,r2;
	cin >>c>>n;
	for(i=0;i<n;i++)	cin >>p[i];
	wc=0;
	for(i=0;i<n;i++)	{
		for(j=0;j<n/2;j++)	{
			if(p[i][j]==p[i][n-j-1]){
				dw[i][j]=0;
			}
			else {
				dw[i][j]=1;	wc++;
//				cout <<"i="<<i<<"j="<<j<<endl;
			}
		}
	}
	hc=0;
	for(i=0;i<n/2;i++)	{
		for(j=0;j<n;j++)	{
			if(p[i][j]==p[n-i-1][j]){
				dh[i][j]=0;
			}
			else {
				dh[i][j]=1;	hc++;
//				cout <<"i="<<i<<"j="<<j<<endl;
			}
		}
	}	
//	cout <<" "<<wc<<" "<<hc<<endl;
	if(hc==0 && wc==0)	cnt=1;
	else cnt=0;
	for(i=2;i<=c;i++)	{
		cin >>d;
		for(j=0;j<d;j++)	{
			cin >>r>>cc;
			r--;	cc--;
			if(cc>=n/2)	c2=n-cc-1;
			else c2=cc;
//			cout <<"   "<<r<<c2<<endl;
	
			if(dw[r][c2]==1)	{
				dw[r][c2]=0;
				wc--;
			}
			else {
				dw[r][c2]=1;
				wc++;
			}
			if(r>=n/2)	r2=n-r-1;
			else r2=r;
			
//			cout <<"   "<<r2<<cc<<endl;			
			
			if(dh[r2][cc]==1)	{
				dh[r2][cc]=0;
				hc--;
			}
			else {
				dh[r2][cc]=1;
				hc++;
			}
		}
//			cout <<" "<<wc<<" "<<hc<<endl;
		if(hc==0 && wc==0)	cnt++;
	}
	cout <<cnt<<endl;
	return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 7968
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
void solve();
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) solve();
    return 0;
}
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
// ll dy[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void solve() {
    ll C, n;
    cin >> C >> n;
    vvc<char> a(n, vc<char>(n));
    rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
    vvc<bool> sym(n / 2, vc<bool>(n / 2));
    ll cnt = 0;
    rep(i, 0, n / 2) rep(j, 0, n / 2) {
        if (a[i][j] == a[i][n - 1 - j] && a[i][j] == a[n - 1 - i][j] &&
            a[i][j] == a[n - 1 - i][n - 1 - j])
            sym[i][j] = true, cnt++;
    }
    ll res = (cnt == n / 2 * n / 2);
    rep(i, 1, C) {
        ll d;
        cin >> d;
        auto check = [&](ll r, ll c) {
            return a[r][c] == a[n - 1 - r][n - 1 - c] &&
                   a[r][c] == a[n - 1 - r][c] && a[r][c] == a[r][n - 1 - c];
        };
        rep(j, 0, d) {
            ll r, c;
            cin >> r >> c;
            r--, c--;
            if (a[r][c] == '0')
                a[r][c] = '1';
            else
                a[r][c] = '0';
            if (r >= n / 2) r = n - 1 - r;
            if (c >= n / 2) c = n - 1 - c;
            if (sym[r][c] && !check(r, c)) {
                sym[r][c] = false;
                cnt--;
            }
            if (!sym[r][c] && check(r, c)) {
                sym[r][c] = true;
                cnt++;
            }
        }
        res += (cnt == n / 2 * n / 2);
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 4460
final_rank: 3

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  cout << (x);
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}
template <typename T>
void wt_integer128(T x) {
  char buf[64];
  char *d = end(buf);
  d--; *d = '\0';
  __uint128_t tmp = ((x < 0)? -x : x);
  do {
    d--; *d = char(tmp%10 + '0'); tmp /= 10;
  } while (tmp);
  if (x < 0) {
    d--; *d = '-';
  }
  cout << d;
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer128(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer128(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll C, N;
  cin >> C >> N;
  vc<string> p(N);
  rep(i, N) {cin >> p[i];}
  vc<set<pi>> v(2), h(2); // 0: 片方、1: 両方
  auto check_and_conduct =[&](ll r, ll c, bool adding) {
    ll y = (r < N/2) ? r : N-1-r;
    ll x = (c < N/2) ? c : N-1-c;
    if (adding) {
      auto t = mp(y, c);
      if (v[0].count(t)) {
        v[0].erase(t);
        v[1].emplace(t);
      } else {
        v[0].emplace(t);
      }
      t = mp(r, x);
      if (h[0].count(t)) {
        h[0].erase(t);
        h[1].emplace(t);
      } else {
        h[0].emplace(t);
      }
    } else {
      auto t = mp(y, c);
      if (v[0].count(t)) {
        v[0].erase(t);
      } elif (v[1].count(t)) {
        v[1].erase(t);
        v[0].emplace(t);
      }
      t = mp(r, x);
      if (h[0].count(t)) {
        h[0].erase(t);
      } elif (h[1].count(t)) {
        h[1].erase(t);
        h[0].emplace(t);
      }
    }
  };
  rep(r, N) rep(c, N) {
    if (p[r][c] == '0') continue;
    check_and_conduct(r, c, true);
  }
  ll ans = ((len(v[0]) == 0) and (len(h[0]) == 0));
  rep(C-1) {
    ll D, r, c;
    cin >> D;
    rep(D) {
      cin >> r >> c;
      --r, --c;
      check_and_conduct(r, c, p[r][c] == '0');
      p[r][c] = (p[r][c] == '1') ? '0' : '1';
    }
    ans += ((len(v[0]) == 0) and (len(h[0]) == 0));
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 1120
memory_kb: 66972
final_rank: 17

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  cout << (x);
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}
template <typename T>
void wt_integer128(T x) {
  char buf[64];
  char *d = end(buf);
  d--; *d = '\0';
  __uint128_t tmp = ((x < 0)? -x : x);
  do {
    d--; *d = char(tmp%10 + '0'); tmp /= 10;
  } while (tmp);
  if (x < 0) {
    d--; *d = '-';
  }
  cout << d;
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer128(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer128(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll C, N;
  cin >> C >> N;
  vc<string> p(N);
  rep(i, N) {cin >> p[i];}
  vc<set<pi>> v(2), h(2); // 0: 片方、1: 両方
  auto check_and_conduct =[&](ll r, ll c) {
    ll y = (r < N/2) ? r : N-1-r;
    ll x = (c < N/2) ? c : N-1-c;
    auto t = mp(r, x);
    if (v[0].count(t)) {
      v[0].erase(t);
      v[1].emplace(t);
    } else {
      v[0].emplace(t);
    }
    t = mp(y, c);
    if (h[0].count(t)) {
      h[0].erase(t);
      h[1].emplace(t);
    } else {
      h[0].emplace(t);
    }
  };
  rep(i, N) rep(j, N) {
    if (p[i][j] == '0') continue;
    check_and_conduct(i, j);
  }
  ll ans = ((len(v[0]) == 0) and (len(h[0]) == 0));
  rep(C) {
    ll D, r, c;
    cin >> D;
    rep(D) {
      cin >> r >> c;
      --r, --c;
      check_and_conduct(r, c);
      ans += ((len(v[0]) == 0) and (len(h[0]) == 0));
    }
  }
  print(ans);
  return 0;
}
accuracy: 0.1875
time_ms: 10
memory_kb: 7240
final_rank: 20