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 = 5005;
const int M = 400005;
struct TARR {
  int a[N * 2];
  void change(int x, int v) {
    for (; x < N * 2; x += x & (-x)) a[x] += v;
  }
  int ask(int x) {
    int ans = 0;
    for (; x; x -= x & (-x)) ans += a[x];
    return ans;
  }
} T[5];
struct node {
  int tp, x, y, v, id;
} q[M], qq[M];
int n, Q, id, top;
int ans[M];
bool cmp(node x, node y) { return x.x == y.x ? x.tp < y.tp : x.x < y.x; }
void CDQ(int l, int r) {
  if (l == r) return;
  int mid = (l + r) / 2;
  CDQ(l, mid);
  CDQ(mid + 1, r);
  int p1 = l, p2 = mid + 1, p3 = l;
  for (; p1 <= mid || p2 <= r;)
    if (p2 > r || (p1 <= mid && cmp(q[p1], q[p2])))
      qq[p3++] = q[p1++];
    else
      qq[p3++] = q[p2++];
  for (int i = (int)(l); i <= (int)(r); i++) q[i] = qq[i];
  for (int i = (int)(l); i <= (int)(r); i++)
    if (q[i].id <= mid && q[i].tp <= 3) {
      if (q[i].tp == 1) T[1].change(q[i].y, q[i].v);
      if (q[i].tp == 2) T[2].change(q[i].y + q[i].x, q[i].v);
      if (q[i].tp == 3) T[3].change(q[i].y - q[i].x + N, q[i].v);
    } else if (q[i].id > mid && q[i].tp == 4) {
      ans[q[i].v] += T[1].ask(q[i].y);
      ans[q[i].v] += T[2].ask(q[i].y + q[i].x);
      ans[q[i].v] += T[3].ask(q[i].y - q[i].x + N);
    }
  for (int i = (int)(l); i <= (int)(r); i++)
    if (q[i].id <= mid && q[i].tp <= 3) {
      if (q[i].tp == 1) T[1].change(q[i].y, -q[i].v);
      if (q[i].tp == 2) T[2].change(q[i].y + q[i].x, -q[i].v);
      if (q[i].tp == 3) T[3].change(q[i].y - q[i].x + N, -q[i].v);
    }
}
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = (int)(1); i <= (int)(Q); i++) {
    int tp, x, y, d;
    scanf("%d", &tp);
    if (tp == 2) {
      scanf("%d%d", &x, &y);
      q[++top] = (node){4, x, y, ++id};
    } else {
      scanf("%d%d%d%d", &tp, &x, &y, &d);
      if (tp == 1) {
        q[++top] = (node){1, x, y, 1};
        q[++top] = (node){1, x + d + 1, y, -1};
        q[++top] = (node){2, x, y + d + 1, -1};
        q[++top] = (node){2, x + d + 1, y, 1};
      }
      if (tp == 2) {
        q[++top] = (node){1, x, y + 1, -1};
        q[++top] = (node){1, x + d + 1, y + 1, 1};
        q[++top] = (node){3, x, y - d, 1};
        q[++top] = (node){3, x + d + 1, y + 1, -1};
      }
      if (tp == 3) {
        q[++top] = (node){1, x - d, y, 1};
        q[++top] = (node){1, x + 1, y, -1};
        q[++top] = (node){3, x - d, y + 1, -1};
        q[++top] = (node){3, x + 1, y + d + 2, 1};
      }
      if (tp == 4) {
        q[++top] = (node){1, x - d, y + 1, -1};
        q[++top] = (node){1, x + 1, y + 1, 1};
        q[++top] = (node){2, x - d, y, 1};
        q[++top] = (node){2, x + 1, y - d - 1, -1};
      }
    }
  }
  for (int i = (int)(1); i <= (int)(top); i++) q[i].id = i;
  CDQ(1, top);
  for (int i = (int)(1); i <= (int)(id); i++) printf("%d\n", ans[i]);
}