#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll rd(){
ll x = 0, f = 1; char c = getchar();
while(! isdigit(c)){if(c == '-')f = - f; c = getchar();}
while(isdigit(c)){x = (x << 3) + (x << 1) + (c ^ 48); c = getchar();}
return x * f;
}
const int N = 2e6 + 5;
int n, cnt, tot;
ll t[N], ans[N];
struct node{
int x, y, z, op; ll w;
}a[N >> 2], b[N >> 2];
bool cmp(node a, node b){
if(a.x ^ b.x)return a.x < b.x;
if(a.y ^ b.y)return a.y < b.y;
if(a.z ^ b.z)return a.z < b.z;
return a.w > b.w;
}
int lb(int x){
return x & - x;
}
void upd(int x, ll y){
for(; x <= n; x += lb(x))t[x] += y;
}
ll qry(int x){
ll sum = 0; for(; x; x -= lb(x))sum += t[x]; return sum;
}
void cdq(int l, int r){
if(l == r)return; int mid = l + r >> 1;
cdq(l, mid); cdq(mid + 1, r);
int i = l, j = mid + 1, cur = l;
while(i <= mid and j <= r)
if(a[i].y <= a[j].y){
upd(a[i].z, a[i].w);
b[cur++] = a[i++];
}
else{
if(a[j].op != - 1){
int id = a[j].op / 4 + 1; ll o = (a[j].op % 4) & 1 ? 1 : - 1;
ans[id] += o * qry(a[j].z);
}
b[cur++] = a[j++];
}
while(j <= r){
if(a[j].op != - 1){
int id = a[j].op / 4 + 1; ll o = (a[j].op % 4) & 1 ? 1 : - 1;
ans[id] += o * qry(a[j].z);
}
b[cur++] = a[j++];
}
for(int nw = l; nw < i; ++nw)upd(a[nw].z, - a[nw].w);
while(i <= mid)b[cur++] = a[i++];
for(i = l; i <= r; ++i)a[i] = b[i];
}
signed main(){
cnt = rd(); n = rd();
for(int x, y, z, w, t, i = 1; ; ++i){
x = rd(); if(x == 3)break;
y = rd(), z = rd(), w = rd();
if(x ^ 1){
++w, t = rd() + 1; a[++tot] = {y, t, i, cnt++};
a[++tot] = {y, z, i, cnt++}; a[++tot] = {w, z, i, cnt++};
a[++tot] = {w, t, i, cnt++};
}
else a[++tot] = {y + 1, z + 1, i, - 1, w};
}
sort(a + 1, a + 1 + tot, cmp);
cdq(1, tot); cnt >>= 2;
for(int i = 1; i <= cnt; ++i)printf("%lld\n", ans[i]);
return 0;
}