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 = 1e5 + 5;
int flag[N], dic[N], xx[N], yy[N], len[N];
int n, q, tot;
int mx;
int ans[N];
int f[N], g[N], id[N];
int p[N << 2];
int cmp(int a, int b) {
  pair<int, int> A, B;
  if (a < 0)
    A = make_pair(xx[-a] + len[-a], 1);
  else {
    A = make_pair(xx[a], -1);
    if (flag[a] == 2) A.second = 0;
  }
  if (b < 0)
    B = make_pair(xx[-b] + len[-b], 1);
  else {
    B = make_pair(xx[b], -1);
    if (flag[b] == 2) B.second = 0;
  }
  return A < B;
}
int find(int x) {
  int ans = 0;
  while (x > 0) {
    if (g[x] != tot) {
      g[x] = tot;
      f[x] = 0;
    }
    ans += f[x];
    x -= x & -x;
  }
  return ans;
}
void add(int x, int s) {
  while (x <= mx) {
    if (g[x] != tot) {
      g[x] = tot;
      f[x] = 0;
    }
    f[x] += s;
    x += x & -x;
  }
}
void solve(int dic1, int l1, int r1, int l2, int r2) {
  int r = 0;
  for (int i = l1; i <= r1; ++i)
    if (dic[i] == dic1 && flag[i] == 1) {
      p[++r] = i;
      p[++r] = -i;
    }
  for (int i = l2; i <= r2; ++i)
    if (flag[i] == 2) {
      p[++r] = i;
    }
  sort(p + 1, p + 1 + r, cmp);
  ++tot;
  mx = n;
  for (int i = 1; i <= r; ++i) {
    if (flag[abs(p[i])] == 1) {
      if (p[i] > 0)
        add(yy[p[i]], 1);
      else
        add(yy[-p[i]], -1);
    } else {
      ans[p[i]] -= find(mx) - find(yy[p[i]]);
    }
  }
  ++tot;
  mx = n * 3;
  for (int i = 1; i <= r; ++i) {
    if (flag[abs(p[i])] == 1) {
      if (p[i] > 0)
        add(yy[p[i]] + len[p[i]] + xx[p[i]], 1);
      else
        add(yy[-p[i]] + len[-p[i]] + xx[-p[i]], -1);
    } else
      ans[p[i]] -= find(yy[p[i]] + xx[p[i]] - 1);
  }
}
void divide(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  divide(l, mid);
  divide(mid + 1, r);
  solve(1, l, mid, mid + 1, r);
  for (int i = l; i <= r; ++i) yy[i] = n - yy[i] + 1;
  solve(2, l, mid, mid + 1, r);
  for (int i = l; i <= r; ++i) yy[i] = n - yy[i] + 1;
  for (int i = l; i <= r; ++i) xx[i] = n - xx[i] + 1;
  solve(3, l, mid, mid + 1, r);
  for (int i = l; i <= r; ++i) yy[i] = n - yy[i] + 1;
  solve(4, l, mid, mid + 1, r);
  for (int i = l; i <= r; ++i) {
    xx[i] = n - xx[i] + 1;
    yy[i] = n - yy[i] + 1;
  }
}
int main() {
  scanf("%d%d", &n, &q);
  tot = 1;
  mx = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &flag[i]);
    if (flag[i] == 1) {
      scanf("%d", &dic[i]);
      scanf("%d%d%d", &xx[i], &yy[i], &len[i]);
      if (dic[i] <= 2) {
        add(xx[i], 1);
        add(xx[i] + len[i] + 1, -1);
      } else {
        add(xx[i] - len[i], 1);
        add(xx[i] + 1, -1);
      }
    } else {
      scanf("%d%d", &xx[i], &yy[i]);
      ans[i] = find(xx[i]);
    }
  }
  divide(1, q);
  for (int i = 1; i <= q; ++i)
    if (flag[i] == 2) printf("%d\n", ans[i]);
  return 0;
}