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;
struct node {
  int t, x, y, z;
} d[300007], tmp[1500007];
struct tree {
  int t[600017], tot;
  int add(int x, int v) {
    x += 300005;
    while (x <= 600005) t[x] += v, x += x & -x;
    tot += v;
    return 0;
  }
  int ask(int x) {
    x += 300005;
    int res = 0;
    while (x) res += t[x], x -= x & -x;
    return res;
  }
} t[3];
int num, n, q, cnt, res[300007];
int read() {
  int num = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  return num;
}
int add(int l, int r, int x, int y, int z) {
  tmp[++cnt] = node{x, l, y, z};
  tmp[++cnt] = node{x, r + 1, y, -z};
  return 0;
}
int cmp(node a, node b) {
  if (a.x == b.x) return a.t > b.t;
  return a.x < b.x;
}
int solve(int l, int r) {
  if (l == r) return 0;
  int mid = (l + r) / 2;
  solve(l, mid);
  solve(mid + 1, r);
  cnt = 0;
  for (int i = l; i <= mid; i++) {
    if (d[i].t == 1) {
      add(d[i].x, d[i].x + d[i].z, 0, d[i].y, 1);
      add(d[i].x, d[i].x + d[i].z, 1, d[i].x + d[i].y + d[i].z + 1, -1);
    }
    if (d[i].t == 2) {
      add(d[i].x, d[i].x + d[i].z, 2, d[i].y - d[i].x - d[i].z, 1);
      add(d[i].x, d[i].x + d[i].z, 0, d[i].y + 1, -1);
    }
    if (d[i].t == 3) {
      add(d[i].x - d[i].z, d[i].x, 0, d[i].y, 1);
      add(d[i].x - d[i].z, d[i].x, 2, d[i].y - d[i].x + d[i].z + 1, -1);
    }
    if (d[i].t == 4) {
      add(d[i].x - d[i].z, d[i].x, 1, d[i].x + d[i].y - d[i].z, 1);
      add(d[i].x - d[i].z, d[i].x, 0, d[i].y + 1, -1);
    }
  }
  for (int i = mid + 1; i <= r; i++)
    if (!d[i].t) tmp[++cnt] = node{-d[i].z, d[i].x, d[i].y, 0};
  sort(tmp + 1, tmp + cnt + 1, cmp);
  for (int i = 1; i <= cnt; i++)
    if (tmp[i].t >= 0)
      t[tmp[i].t].add(tmp[i].y, tmp[i].z);
    else {
      res[-tmp[i].t] += t[0].ask(tmp[i].y);
      res[-tmp[i].t] += t[1].ask(tmp[i].x + tmp[i].y);
      res[-tmp[i].t] += t[2].ask(tmp[i].y - tmp[i].x);
    }
  return 0;
}
int main() {
  n = read();
  q = read();
  for (int i = 1; i <= q; i++) {
    int tp = read();
    if (tp == 1) {
      d[i].t = read();
      d[i].x = read();
      d[i].y = read();
      d[i].z = read();
    } else {
      d[i].x = read();
      d[i].y = read();
      d[i].z = ++cnt;
    }
  }
  int tot = cnt;
  solve(1, q);
  for (int i = 1; i <= tot; i++) printf("%d\n", res[i]);
  return 0;
}