/**
 * a template matrix (2d array), with a sample application - solving the ioi mobile problem.
 */

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef unsigned int uint;

template <class T> class matrix {
protected:
  uint myRows, myCols;
  vector<T> myData;
public:
  matrix<T> () {}
  matrix<T> (uint rows, uint cols): 
    myRows(rows), myCols(cols),
    myData(rows*cols) {} 

  void resize (int rows, int cols) {
    myRows=rows; myCols=cols;
    myData.resize(rows*cols);
  }

  T& at(uint row, uint col) { return myData[row*myCols+col]; }
  const T& at(uint row, uint col) const { return myData[row*myCols+col]; }

  void fill (T value) { ::fill(myData.begin(), myData.end(), value); }

  void print(ostream& out) const {
    for (uint row=0; row<myRows; ++row) {
      const T* temp = &myData[row*myCols];
      for (uint col=0; col<myCols; ++col) {
        out << temp[col] << " ";
      }
      out << endl;
    }
  }

  friend ostream& operator<< (ostream& out, const matrix<T>& m) { m.print(out); return out; }
};


class MobileNetworkKeepsValues: public matrix<short> {
  // myData[r,c] holds the number of phones in row r, column c

public:
  void add(uint X, uint Y, short A) {
    at(X,Y) += A;
  }

  uint sum(uint left, uint bottom, uint right, uint top) const {
    uint result=0;
    for (uint row=left; row<=right; ++row) {
      const short* temp = &myData[row*myCols];
      for (uint col=bottom; col<=top; ++col) {
        result += temp[col];
      }
    }
    return result;
  } 

};


class MobileNetworkKeepsSums: public matrix<int> {
  // myData[r,c] holds the sum of phones in row r, columns [0..c]

public:
  void add(uint X, uint Y, short A) {
    int* temp = &myData[X*myCols];
    for (uint col=Y; col<myCols; ++col) {
      temp[col] += A;
    }
  }

  uint sum(uint left, uint bottom, uint right, uint top) const {
    uint result=0;
    for (uint row=left; row<=right; ++row) {
      // sum from bottom to top = sum from 0 to top - sum from 0 to (bottom-1)
      result += (at(row,top)-(bottom>0? at(row,bottom-1): 0));
    }
    return result;
  } 
};


int main() {
  MobileNetworkKeepsSums network;

  char commandCode;
  uint S, //for command 0
       X,Y, // for command 1
       L,B,R,T; // for command 2
  short A; // for command 1
  
  while (1) {
    cin >> commandCode;
    //cout << "command='" << commandCode << "'" << endl;
    if (cin.eof()) break;
    switch(commandCode) {
      case '0':
        cin >>  S;
        network.resize(S,S);
        network.fill(0);
        break;
      case '1':
        cin >> X >> Y >> A;
        network.add(X,Y,A);
        //network.print(cout);
        break;
      case '2':
        cin >> L >> B >> R >> T;
        cout << network.sum(L,B,R,T) << endl;
        break;
      case '3':
        return 0;
      default:
        cerr << "Unknown command " << commandCode << endl;
    }
  }
}


