#include <iostream>

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    int arr[n][n];
    int jj[m][4];
    int sum[m]={0,};
    for (int i = 0;i < n ;i++ ) {
        for (int j = 0;j < n ;j++ ) {
            cin >> arr[i][j];
        }
    }
    for (int i = 0;i < m;i++) {
        for (int j = 0; j < 4;j++ ) {
            cin >> jj[i][j];
        }
                for (int k = jj[i][0];k < jj[i][2];k++ ) {
                for (int l = jj[i][1];l < jj[i][3];l++ ) {
                    sum[i] += arr[k-1][l-1];
                }
            }
    }
    for (int i = 0;i < m ;i++ ) {
        cout << sum[i] << "\n";
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: