#include<cstdio>
#include<cmath>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<utility>
const int UMAX=60002,SMAX=1024;
using namespace std;
typedef long long ll;
int m[SMAX+2][SMAX+2]={};//Start Menu
//Version ↑
int main(){
freopen("mobilephones.in","r",stdin);
freopen("mobilephones.out","w",stdout);
int i,S;
for(i=0;i<UMAX;i++){
int mode;
int i1,i2,i3,i4;
cin>>mode;//Get in
if(mode==3){
break;
}
if(mode==0){
cin>>S;
}
if(mode==1){
cin>>i1>>i2>>i3;//X,Y,A(+/-)
m[i1][i2]+=i3;
}else if(mode==2){
int L,B,R,T;
cin>>L>>B>>R>>T;//L,B,R,T
int o,p;
ll out=0;
for(o=L;o<=R;o++){
for(p=B;p<=T;p++){
out+=m[o][p];
}
}
cout<<out<<endl;
}
}
return 0;
}