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>
int type, n, q, OPT[1000005], OPT1[1000005], OPT2[1000005], OPT3[1000005],
    OPT4[1000005], ans[1000005], BIT[1000005];
int change[5] = {0, 2, 4, 1, 3};
int read() {
  char c = getchar();
  int ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans;
}
void Write(int x) {
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x < y ? x : y; }
void Insert(int x, int y) {
  for (register int i = x; i <= n * 2 + 1; i += (i & (-i))) BIT[i] += y;
  return;
}
int query(int x) {
  int ans = 0;
  for (register int i = x; i; i &= (i - 1)) ans += BIT[i];
  return ans;
}
struct node {
  int X1, X2, X3, X4, id, key;
} S[1000005], tmp[1000005];
bool cmp1(node x, node y) { return x.X1 < y.X1; }
bool cmp2(node x, node y) {
  if (x.X2 != y.X2) return x.X2 < y.X2;
  return x.X1 < y.X1;
}
void CDQ2(int L, int R) {
  if (L == R) return;
  int mid = (L + R) >> 1, p1 = L, p2 = mid + 1, p = 0;
  CDQ2(L, mid), CDQ2(mid + 1, R);
  while (p1 <= mid && p2 <= R)
    if (S[p1].X3 <= S[p2].X3) {
      if (S[p1].key == 0 && S[p1].id == 0) Insert(S[p1].X4, 1);
      tmp[++p] = S[p1++];
    } else {
      if (S[p2].key == 1 && S[p2].id) ans[S[p2].id] += query(S[p2].X4);
      tmp[++p] = S[p2++];
    }
  while (p1 <= mid) {
    if (S[p1].key == 0 && S[p1].id == 0) Insert(S[p1].X4, 1);
    tmp[++p] = S[p1++];
  }
  while (p2 <= R) {
    if (S[p2].key == 1 && S[p2].id) ans[S[p2].id] += query(S[p2].X4);
    tmp[++p] = S[p2++];
  }
  for (register int i = L; i <= mid; i++)
    if (S[i].key == 0 && S[i].id == 0) Insert(S[i].X4, -1);
  for (register int i = L; i <= R; i++) S[i] = tmp[i - L + 1];
  return;
}
void CDQ1(int L, int R) {
  if (L == R) return;
  int mid = (L + R) >> 1;
  CDQ1(L, mid), CDQ1(mid + 1, R);
  for (register int i = L; i <= mid; i++) S[i].key = 0;
  for (register int i = mid + 1; i <= R; i++) S[i].key = 1;
  std::sort(S + L, S + R + 1, cmp2);
  CDQ2(L, R);
  return;
}
void calc() {
  int cnt = 0;
  for (register int i = 1; i <= q; i++) {
    if (OPT[i] == 1 && OPT1[i] != 1) continue;
    if (OPT[i] == 1)
      S[++cnt] =
          (node){i,       OPT2[i],
                 OPT3[i], max(1, n * 2 + 1 - (OPT2[i] + OPT3[i] + OPT4[i])),
                 0,       0};
    else
      S[++cnt] =
          (node){i, OPT1[i], OPT2[i], n * 2 + 1 - (OPT1[i] + OPT2[i]), i, 0};
  }
  CDQ1(1, cnt);
  return;
}
int main() {
  n = read(), q = read();
  for (register int i = 1; i <= q; i++) {
    OPT[i] = read(), OPT1[i] = read(), OPT2[i] = read();
    if (OPT[i] == 1) OPT3[i] = read(), OPT4[i] = read();
  }
  for (register int _ = 0; _ < 4; _++) {
    calc();
    for (register int i = 1; i <= q; i++)
      if (OPT[i] == 1)
        std::swap(OPT2[i], OPT3[i]), OPT3[i] = n + 1 - OPT3[i],
                                     OPT1[i] = change[OPT1[i]];
      else
        std::swap(OPT1[i], OPT2[i]), OPT2[i] = n + 1 - OPT2[i];
  }
  for (register int i = 1; i <= q; i++)
    if (OPT[i] == 2) Write(ans[i]), putchar('\n');
  return 0;
}