//hdu1166 二维树状数组
#include <iostream>
using namespace std;
int n;
//int a[1025][1025];
int c[1025][1025];
int lowbit(int x)
{
return x&(-x);
}
void insert(int x,int y,int value)
{
while(y<=n)
{
int i=x;
while(i<=n)
{
c[i][y]+=value;
i+=lowbit(i);
}
y+=lowbit(y);
}
}
int getsum(int x,int y){
if(x<=0||y<=0)
return 0;
int i=0,j=y;
while(x>0)
{
y=j;
while(y>0)
{
i+=c[x][y];
y-=lowbit(y);
}
x-=lowbit(x);
}
return i;
}
int main()
{
int f,x,y,x1,y1,x2,y2,value;
while(scanf("%d",&f))
{
if(f==0)
{
//memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
scanf("%d",&n);
}
if(f==1)
{
scanf("%d%d%d",&x,&y,&value);
insert(x+1,y+1,value);
}
if(f==2)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int sum=getsum(x2+1,y2+1)+getsum(x1,y1)-getsum(x2+1,y1)-getsum(x1,y2+1);
printf("%d\n",sum);
}
if(f==3)
break;
}
return 0;
}