#include <bits/stdc++.h>
using namespace std;
int ins,S,X,Y,A,L,B,R,T,Tempere[1030][1030]={0};
int main()
{
freopen("mobilephones.in","r",stdin);
freopen("mobilephones.out","w",stdout);
while ( cin >> ins )
{
if ( ins == 0 ) cin >> S;
if ( ins == 1 )
{
cin >> X >> Y >>A;
Tempere[X][Y]+=A;
}
if ( ins == 2)
{
int sum=0;
cin >> L >> B >> R >> T;
for( int i=L;i <= R;i ++)
{
for(int j=B;j<=T;j++)
{
sum+=Tempere[i][j];
}
}
cout<<sum<<endl;
}
if (ins == 3)break;
}
return 0;
}