#include <bits/stdc++.h>
using i64 = long long;
using PII = std::pair<int, int>;
const int N = 1050;
int op, s;
i64 c[N][N];
int main() {
freopen("mobilephones.in", "r", stdin);
freopen("mobilephones.out", "w", stdout);
std::cin >> op >> s;
while (std::cin >> op, op != 3) {
if (op == 1) {
i64 x, y, a;
std::cin >> x >> y >> a;
c[x][y] += a;
} else {
i64 l, b, r, t, res = 0;
std::cin >> l >> b >> r >> t;
for (int i = l; i <= r; ++ i)
for (int j = b; j <= t; ++ j)
res += c[i][j];
std::cout << res << '\n';
}
}
return 0;
}