#include<bits/stdc++.h>
using namespace std;
int n, c[1050][1050] = {0};
int lowbit(int x) {
return x & -x;
}
int add(int x, int y, int a) {
for(int i = y; i <= n; i += lowbit(i)) {
c[x][i] += a;
}
return 0;
}
int sum(int x, int y) {
int ans = 0;
for(int i = y; i >= 1; i -= lowbit(i)) {
ans += c[x][i];
}
return ans;
}
int main() {
freopen("mobilephones.in", "r", stdin);
freopen("mobilephones.out", "w", stdout);
int xx;
cin >> xx >> n;
while(cin >> xx && xx != 3) {
if(xx == 1) {
int x, y, z;
cin >> x >> y >> z;
add(x + 1, y + 1, z);
}
if(xx == 2) {
int a, b, c, d, ans = 0;
cin >> a >> b >> c >> d;
for(int i = a + 1; i <= c + 1; i ++) {
ans = ans + sum(i, d + 1) - sum(i, b);
}
cout << ans << endl;
}
}
return 0;
}