#include using namespace std; typedef long long ll; #define rep(i,a,b) for(ll i=a;i> n >> m; ll a[m+1][m+1]; rep(i,1,m+1) rep(j,1,m+1) cin >> a[i][j]; rep(i,1,m+1) rep(j,1,m+1) a[i][j] += a[i][j-1]; rep(j,1,m+1) rep(i,1,m+1) a[i][j] += a[i-1][j]; rep(i,0,n) { int x,y; cin >> x >> y; int ans = 0; rep(i,0,x) rep(j,0,y) rep(k,x,m+1) rep(l,y,m+1) if(a[i][j] - a[i][l] - a[k][j] + a[k][l] == 0) ans++; cout << ans << endl; } }