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>
using namespace std;
const int N = 100005;
const int M = 5005;
int n, m;
int c[M][M];
int type[N], X[N], Y[N], len[N], dir[N], res[N];
int w[N], nw, v[N], nv;
bool cmp1(const int& A, const int& B) {
  return X[A] + Y[A] + len[A] > X[B] + Y[B] + len[B];
}
bool cmp2(const int& A, const int& B) {
  return X[A] - Y[A] + len[A] > X[B] - Y[B] + len[B];
}
bool cmp3(const int& A, const int& B) {
  return X[A] + Y[A] - len[A] < X[B] + Y[B] - len[B];
}
bool cmp4(const int& A, const int& B) {
  return X[A] - Y[A] - len[A] < X[B] - Y[B] - len[B];
}
void divide(int l, int r) {
  if (l >= r) return;
  int mid = l + r >> 1;
  divide(l, mid);
  nv = 0;
  for (int i = mid + 1; i <= r; ++i)
    if (type[i] == 2) v[nv++] = i;
  nw = 0;
  for (int i = l; i <= mid; ++i)
    if (type[i] == 1 && dir[i] == 1) w[nw++] = i;
  sort(w, w + nw, cmp1);
  sort(v, v + nv, cmp1);
  for (int i = 0, j = 0; i < nv; ++i) {
    int x = v[i];
    while (j < nw) {
      int y = w[j];
      if (!(X[x] + Y[x] <= X[y] + Y[y] + len[y])) break;
      for (int k = X[y]; k <= n; k += k & -k)
        for (int l = Y[y]; l <= n; l += l & -l) ++c[k][l];
      ++j;
    }
    int& ret = res[x];
    for (int k = X[x]; k > 0; k -= k & -k)
      for (int l = Y[x]; l > 0; l -= l & -l) ret += c[k][l];
  }
  for (int j = 0; j < nw; ++j) {
    int y = w[j];
    for (int k = X[y]; k <= n; k += k & -k)
      for (int l = Y[y]; l <= n; l += l & -l) c[k][l] = 0;
  }
  nw = 0;
  for (int i = l; i <= mid; ++i)
    if (type[i] == 1 && dir[i] == 3) w[nw++] = i;
  sort(w, w + nw, cmp3);
  sort(v, v + nv, cmp3);
  for (int i = 0, j = 0; i < nv; ++i) {
    int x = v[i];
    while (j < nw) {
      int y = w[j];
      if (!(X[x] + Y[x] >= X[y] + Y[y] - len[y])) break;
      for (int k = X[y]; k > 0; k -= k & -k)
        for (int l = Y[y]; l > 0; l -= l & -l) ++c[k][l];
      ++j;
    }
    int& ret = res[x];
    for (int k = X[x]; k <= n; k += k & -k)
      for (int l = Y[x]; l <= n; l += l & -l) ret += c[k][l];
  }
  for (int j = 0; j < nw; ++j) {
    int y = w[j];
    for (int k = X[y]; k > 0; k -= k & -k)
      for (int l = Y[y]; l > 0; l -= l & -l) c[k][l] = 0;
  }
  nw = 0;
  for (int i = l; i <= mid; ++i)
    if (type[i] == 1 && dir[i] == 2) w[nw++] = i;
  sort(w, w + nw, cmp2);
  sort(v, v + nv, cmp2);
  for (int i = 0, j = 0; i < nv; ++i) {
    int x = v[i];
    while (j < nw) {
      int y = w[j];
      if (!(X[x] - Y[x] <= X[y] - Y[y] + len[y])) break;
      for (int k = X[y]; k <= n; k += k & -k)
        for (int l = Y[y]; l > 0; l -= l & -l) ++c[k][l];
      ++j;
    }
    int& ret = res[x];
    for (int k = X[x]; k > 0; k -= k & -k)
      for (int l = Y[x]; l <= n; l += l & -l) ret += c[k][l];
  }
  for (int j = 0; j < nw; ++j) {
    int y = w[j];
    for (int k = X[y]; k <= n; k += k & -k)
      for (int l = Y[y]; l > 0; l -= l & -l) c[k][l] = 0;
  }
  nw = 0;
  for (int i = l; i <= mid; ++i)
    if (type[i] == 1 && dir[i] == 4) w[nw++] = i;
  sort(w, w + nw, cmp4);
  sort(v, v + nv, cmp4);
  for (int i = 0, j = 0; i < nv; ++i) {
    int x = v[i];
    while (j < nw) {
      int y = w[j];
      if (!(X[x] - Y[x] >= X[y] - Y[y] - len[y])) break;
      for (int k = X[y]; k > 0; k -= k & -k)
        for (int l = Y[y]; l <= n; l += l & -l) ++c[k][l];
      ++j;
    }
    int& ret = res[x];
    for (int k = X[x]; k <= n; k += k & -k)
      for (int l = Y[x]; l > 0; l -= l & -l) ret += c[k][l];
  }
  for (int j = 0; j < nw; ++j) {
    int y = w[j];
    for (int k = X[y]; k > 0; k -= k & -k)
      for (int l = Y[y]; l <= n; l += l & -l) c[k][l] = 0;
  }
  divide(mid + 1, r);
}
void work() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &type[i]);
    if (type[i] == 1) {
      scanf("%d%d%d%d", &dir[i], &X[i], &Y[i], &len[i]);
      if (dir[i] == 3 || dir[i] == 4) dir[i] = 7 - dir[i];
    } else {
      scanf("%d%d", &X[i], &Y[i]);
    }
  }
  divide(0, m - 1);
  for (int i = 0; i < m; ++i)
    if (type[i] == 2) printf("%d\n", res[i]);
}
int main() {
  work();
  return 0;
}