#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvvl vector #define vvl vector> #define VV(a, b, c, d) vector>(a, vector(b, c)) #define VVV(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c x, y; ll mode = 1; vvl dat; vvl v; Accum2D(vvl point, ll h=0, ll w=0){ if(point.size()==0) mode=0; for(int i=0;ic) swap(a, c); if(b>d) swap(b, d); if(mode==1){ a = x.at(a), b = y.at(b); c = x.at(c), d = y.at(d); } ll r = v[c][d]; ll u = (a==0?0:v[a-1][d]); ll l = (b==0?0:v[c][b-1]); ll o = (a==0||b==0?0:v[a-1][b-1]); return r - u - l + o; } }; int main() { ll n, m;std::cin >> n >> m; vvl d = VV(m, m, 0, ll); get(d); Accum2D ac(vvl{}, m, m); re(i, m) re(j, m) ac.insert(i, j, d[i][j]); ac.calc(); re(t, n){ ll x, y;std::cin >> x >> y; x--, y--; ll ans = 0; for(int i=0;i<=x;i++){ for(int j=0;j<=y;j++){ for(int l=x;l