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>
const int N = 600000 + 7;
int n, q;
int t[N], x[N], y[N], z[N];
int ans[N];
struct BIT {
  int n, bit[N];
  void add(int i, int v) {
    if (i == 0 || i > n) return;
    for (; i <= n; i += i & -i) bit[i] += v;
  }
  int sum(int i) {
    if (i == 0 || i > n) return 0;
    int t = 0;
    for (; i; i -= i & -i) t += bit[i];
    return t;
  }
};
struct str {
  int x, y, z, t, v;
};
bool operator<(const str& a, const str& b) {
  return a.z == b.z ? a.t < b.t : a.z < b.z;
}
void work();
void cdq(str a[], int l, int r);
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d", t + i);
    if (t[i] == 1)
      scanf("%d%d%d%d", t + i, x + i, y + i, z + i);
    else
      t[i] = 0, scanf("%d%d", x + i, y + i);
    if (t[i] == 3) {
      t[i] = 4;
      continue;
    }
    if (t[i] == 4) {
      t[i] = 3;
      continue;
    }
  }
  for (int d = 0; d < 4; ++d) {
    work();
    for (int i = 1; i <= q; ++i) {
      std::swap(x[i], y[i]), x[i] = n - x[i] + 1;
      if (t[i]) t[i] = (t[i] + 2) % 4 + 1;
    }
  }
  for (int i = 1; i <= q; ++i)
    if (!t[i]) printf("%d\n", ans[i]);
  return 0;
}
void work() {
  static BIT bit;
  static str u[N], v[N];
  bit.n = n << 1;
  int k = 0;
  for (int i = 1; i <= q; ++i) {
    if (t[i] == 1) {
      bit.add(x[i] + y[i] - 1, 1), bit.add(x[i] + y[i] + z[i], -1),
          u[++k] =
              (str){x[i] + y[i] - 1, x[i] + y[i] + z[i] - 1, x[i] - 1, i, 1},
          v[k] = (str){x[i] + y[i] - 1, x[i] + y[i] + z[i] - 1, y[i] - 1, i, 1};
    }
    if (t[i] == 0) {
      ans[i] += bit.sum(x[i] + y[i] - 1),
          u[++k] = (str){x[i] + y[i] - 1, 0, x[i], i, 0},
          v[k] = (str){x[i] + y[i] - 1, 0, y[i], i, 0};
    }
  }
  cdq(u, 1, k);
  cdq(v, 1, k);
  for (int i = 0; i <= bit.n; ++i) bit.bit[i] = 0;
}
BIT bit;
str b[N];
void cdq(str a[], int l, int r) {
  if (l >= r) return;
  int mid = l + r >> 1;
  cdq(a, l, mid), cdq(a, mid + 1, r);
  bit.n = n << 1;
  int i, j, k;
  for (i = r, j = mid; i > mid; --i) {
    if (a[i].v) continue;
    for (; j >= l && (!a[j].v || a[j].z >= a[i].z); --j)
      if (a[j].v) bit.add(a[j].x, 1), bit.add(a[j].y + 1, -1);
    ans[a[i].t] -= bit.sum(a[i].x);
  }
  for (++j; j <= mid; ++j)
    if (a[j].v) bit.add(a[j].x, -1), bit.add(a[j].y + 1, 1);
  for (i = k = l, j = mid + 1; i <= mid; ++i) {
    for (; j <= r && a[j] < a[i]; ++j) b[k++] = a[j];
    b[k++] = a[i];
  }
  for (; j <= r; ++j) b[k++] = a[j];
  for (i = l; i <= r; ++i) a[i] = b[i];
}