Problem: Company "Robots industries" produces robots for territory protection. Robots protect triangle territories — right isosceles triangles with catheti parallel to North-South and East-West directions.

Owner of some land buys and sets robots on his territory to protect it. From time to time, businessmen want to build offices on that land and want to know how many robots will guard it. You are to handle these queries. 

Input

The first line contains integer N — width and height of the land, and integer Q — number of queries to handle.

Next Q lines contain queries you need to process.

Two types of queries: 

  1. 1 dir x y len — add a robot to protect a triangle. Depending on the value of dir, the values of x, y and len represent a different triangle: 
    * dir = 1: Triangle is defined by the points (x, y), (x + len, y), (x, y + len)
    * dir = 2: Triangle is defined by the points (x, y), (x + len, y), (x, y - len)
    * dir = 3: Triangle is defined by the points (x, y), (x - len, y), (x, y + len)
    * dir = 4: Triangle is defined by the points (x, y), (x - len, y), (x, y - len)
  2. 2 x y — output how many robots guard this point (robot guards a point if the point is inside or on the border of its triangle) 


  * 1 ≤ N ≤ 5000
  * 1 ≤ Q ≤ 105
  * 1 ≤ dir ≤ 4
  * All points of triangles are within range [1, N]
  * All numbers are positive integers 

Output

For each second type query output how many robots guard this point. Each answer should be in a separate line.

Examples

Input

17 10
1 1 3 2 4
1 3 10 3 7
1 2 6 8 2
1 3 9 4 2
2 4 4
1 4 15 10 6
2 7 7
2 9 4
2 12 2
2 13 8


Output

2
2
2
0
1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int RAND() { return (rand() << 16) + rand(); }
const int M = 100000 + 5;
const int N = 5000 + 100;
int n, Q;
int ty[M], a[M], b[M], c[M], d[M];
int dx[] = {1, 1, -1, -1};
int dy[] = {1, -1, 1, -1};
int f[N][2 * N];
int Sx, Sy;
int sum(int X, int Y) {
  int res = 0;
  for (int x = X; x; x -= x & (-x))
    for (int y = Y; y; y -= y & (-y)) res += f[x][y];
  return res;
}
void add(int X, int Y, int val) {
  for (int x = X; x <= Sx; x += x & (-x))
    for (int y = Y; y <= Sy; y += y & (-y)) f[x][y] += val;
}
pair<int, int> F(int x, int y) { return make_pair(Sx - x, Sy - y); }
pair<int, int> T(int x, int y) { return make_pair(x, Sy - x - y); }
void ADDF(int x, int y, int val) { add(F(x, y).first, F(x, y).second, val); }
void ADDT(int x, int y, int val) { add(T(x, y).first, T(x, y).second, val); }
int ans[M];
void funct() {
  memset(f, 0, sizeof f);
  Sx = n + 1;
  Sy = n + 1;
  for (int i = 0; i < (int)(Q); ++i) {
    if (ty[i] == 2) {
      ans[i] += sum(F(a[i], b[i]).first, F(a[i], b[i]).second);
      continue;
    }
    if (d[i] == 0) {
      ADDF(a[i] + c[i], b[i] - 1, -1);
      ADDF(a[i] - 1, b[i] - 1, 1);
    }
    if (d[i] == 3) {
      ADDF(a[i], b[i], 1);
      ADDF(a[i] - c[i] - 1, b[i], -1);
    }
  }
  memset(f, 0, sizeof f);
  Sx = n + 1;
  Sy = 2 * (n + 1);
  for (int i = 0; i < (int)(Q); ++i) {
    if (ty[i] == 2) {
      ans[i] += sum(T(a[i], b[i]).first, T(a[i], b[i]).second);
      continue;
    }
    if (d[i] == 0) {
      ADDT(a[i], b[i] + c[i], 1);
      ADDT(a[i] + c[i] + 1, b[i] - 1, -1);
    }
    if (d[i] == 3) {
      ADDT(a[i] - c[i], b[i] - 1, -1);
      ADDT(a[i] + 1, b[i] - c[i] - 2, 1);
    }
  }
}
void solve() {
  scanf("%d", &n);
  scanf("%d", &Q);
  for (int i = 0; i < (int)(Q); ++i) {
    scanf("%d%d%d", &ty[i], &d[i], &a[i]);
    if (ty[i] == 2) {
      swap(a[i], b[i]);
      a[i] = d[i];
      d[i] = -1;
    }
    if (ty[i] == 1) {
      scanf("%d%d", &b[i], &c[i]);
      --d[i];
    }
    a[i] += 5, b[i] += 5;
  }
  n += 10;
  funct();
  for (int i = 0; i < (int)(Q); ++i) {
    a[i] = n - a[i];
    if (ty[i] == 2) continue;
    if (d[i] == 1) {
      d[i] = 3;
    } else if (d[i] == 2) {
      d[i] = 0;
    } else {
      d[i] = 1;
    }
  }
  funct();
  for (int i = 0; i < (int)(Q); ++i) {
    if (ty[i] == 2) printf("%d\n", ans[i]);
  }
}
void testgen() {
  FILE* f = fopen("input.txt", "w");
  fclose(f);
}
int main() {
  cout << fixed;
  cout.precision(16);
  cerr << fixed;
  cerr.precision(3);
  solve();
  return 0;
}