#include using namespace std; int calc_line(int start,int end,vector cero,vector un,vector c_count,vector w_count){ int a2,a1,a0; int x=0; a2=c_count[end]; a1=-un[end]; a0=cero[end]; if(start!=0){ a2-=c_count[start-1]; a1-=-un[start-1]; a0-=cero[start-1]; x=w_count[start-1]; } return a2*x*x+a1*x+a0; } vector calc(vector> S,int H,int W,int Q,vector> query){ vector> c_count(H,vector(W)); vector> w_count(H,vector(W)); int temp; for(int i=0;i> un(H,vector(W)); vector> cero(H,vector(W)); for(int i=0;i ret(0); int m,n,x,a2,a1,a0; for(vector q:query){ temp=0; for(int j=q[0];j<=q[2];j++){ temp+=calc_line(q[1],q[3],cero[j],un[j],c_count[j],w_count[j]); } ret.push_back(temp); } return ret; } int main(){ int H,W; cin>>H>>W; vector>> S(4,vector>(H,vector(W))); S[1].resize(W,vector(H)); S[3].resize(W,vector(H)); string line; for(int i=0;i>line; for(int j=0;j>Q; vector>> query(4,vector>(Q,vector(4))); vector> nextQuery(Q,vector(4)); vector temp(4); for(int i=0;i>temp[j]; } for(int j=0;j<4;j++)query[0][i][j]=temp[j]-1; query[1][i][0]=W-1-(temp[3]-1); query[1][i][1]=temp[0]-1; query[1][i][2]=W-1-(temp[1]-1); query[1][i][3]=temp[2]-1; query[2][i][0]=H-1-(temp[2]-1); query[2][i][1]=W-1-(temp[3]-1); query[2][i][2]=H-1-(temp[0]-1); query[2][i][3]=W-1-(temp[1]-1); query[3][i][0]=temp[1]-1; query[3][i][1]=H-1-(temp[2]-1); query[3][i][2]=temp[3]-1; query[3][i][3]=H-1-(temp[0]-1); } vector> answers(4,vector(Q)); for(int i=0;i<4;i++){ answers[i]=calc(S[i],H,W,Q,query[i]); swap(H,W); } for(int i=0;i