#include <stdio.h>
#include <cstring>
const int maxn=1050;
int c[maxn][maxn];
inline int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int p)
{
for(int i=x; i<maxn; i+=lowbit(i))
for(int j=y; j<maxn; j+=lowbit(j))
{
c[i][j]+=p;
if(c[i][j]<0) c[i][j]=0;
}
}
int query(int x,int y)
{
int ans=0;
for(int i=x; i>0; i-=lowbit(i))
for(int j=y; j>0; j-=lowbit(j))
ans+=c[i][j];
return ans;
}
int main()
{
int op,s,x1,y1,x2,y2,b;
while(scanf("%d",&op)==1)
{
if(op==3) break;
else if(op==0) scanf("%d",&s),memset(c,0,sizeof(c));
else if(op==1) scanf("%d%d%d",&x1,&y1,&b),update(x1+1,y1+1,b);
else if(op==2)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int ans=query(x2+1,y2+1)-query(x1,y2+1)-query(x2+1,y1)+query(x1,y1);
printf("%d\n",ans);
}
}
return 0;
}