# Idea & Solution

# include<bits/stdc++.h>
# define int long long
using namespace std;
const int N=1005;
int s0[N][N],s1[N][N],a[N][N],b[N][N];
int n,m,q;
int count(int x) { int ret=0;while(x){if(x&1)ret++;x>>=1;}return ret;}
pair<int,int> find(int x,int y) { return make_pair((x-1)/n,(y-1)/m);}
int check(int x,int y) { return (count(x)+count(y))&1;}
{
int X=0,w=0; char c=0;
while(c<'0'||c>'9') {w|=c=='-';c=getchar();}
while(c>='0'&&c<='9') X=(X<<3)+(X<<1)+(c^48),c=getchar();
return w?-X:X;
}
void write(int x)
{
if (x>9) write(x/10);
putchar('0'+x%10);
}
int solve(int x,int y)
{
if (x<=0 || y<=0) return 0;
pair<int,int>tmp=find(x,y); int cx = tmp.first, cy = tmp.second;
if ((cx&1) && (cy&1)) {
int ret = ((cx*cy-1)>>1)*n*m,h=x-cx*n,w=y-cy*m;
ret=ret+h*((cy-1)>>1)*m+w*((cx-1)>>1)*n;
if (check(cx,cy)==0) ret+=s0[h][w]; else ret+=s1[h][w];
if (cx>=1 && cy>=1) { if (check(cx-1,cy-1)==0) ret+=s0[n][m]; else ret+=s1[n][m]; }
if (cx>=1) { if (check(cx-1,cy)==0) ret+=s0[n][w]; else ret+=s1[n][w]; }
if (cy>=1) { if (check(cx,cy-1)==0) ret+=s0[h][m]; else ret+=s1[h][m]; }
return ret;
} else if ((cx&1) && !(cy&1)) {
int ret = (cx*cy>>1)*n*m,h=x-cx*n,w=y-cy*m;
ret=ret+h*(cy>>1)*m+w*((cx-1)>>1)*n;
if (check(cx,cy)==0) ret+=s0[h][w]; else ret+=s1[h][w];
if (cx>=1) { if (check(cx-1,cy)==0) ret+=s0[n][w]; else ret+=s1[n][w]; }
return ret;
} else if (!(cx&1) && (cy&1)) {
int ret = (cx*cy>>1)*n*m,h=x-cx*n,w=y-cy*m;
ret=ret+h*((cy-1)>>1)*m+w*(cx>>1)*n;
if (check(cx,cy)==0) ret+=s0[h][w]; else ret+=s1[h][w];
if (cy>=1) { if (check(cx,cy-1)==0) ret+=s0[h][m]; else ret+=s1[h][m]; }
return ret;
} else if (!(cx&1) && !(cy&1)) {
int ret = (cx*cy>>1)*n*m,h=x-cx*n,w=y-cy*m;
ret=ret+h*(cy>>1)*m+w*(cx>>1)*n;
if (check(cx,cy)==0) ret+=s0[h][w]; else ret+=s1[h][w];
return ret;
}
}
signed main()
{
for (int i=1;i<=n;i++) {
for (int j=1;j<=m;j++) {
char c=0; while (c!='0'&&c!='1') c=getchar();
a[i][j]=(c=='1'); b[i][j]=1-a[i][j];
}
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
s0[i][j]=s0[i-1][j]+s0[i][j-1]-s0[i-1][j-1]+a[i][j],
s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1]+b[i][j];
while (q--) {
}