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 wa {
  int v;
  int child[2];
} wat;
struct wb {
  vector<wa> v;
  int child[2];
} wbt;
int n, q, ta, tb, tc, td, add, mo, ya, yb;
vector<wb> x[3];
void f2(vector<wa>& v, int a, int b, int c, int d, int e) {
  if (b == d && c == e) {
    v[a].v += add;
    return;
  }
  int bc = (b + c) / 2;
  if (d < bc) {
    if (v[a].child[0] == 0) {
      v[a].child[0] = v.size();
      v.push_back(wat);
    }
    f2(v, v[a].child[0], b, bc, d, min(e, bc));
  }
  if (e > bc) {
    if (v[a].child[1] == 0) {
      v[a].child[1] = v.size();
      v.push_back(wat);
    }
    f2(v, v[a].child[1], bc, c, max(d, bc), e);
  }
}
void f1(int a, int b, int c, int d, int e) {
  if (b == d && c == e) {
    f2(x[mo][a].v, 0, 0, 1 << 14, ya, yb);
    return;
  }
  int bc = (b + c) / 2;
  if (d < bc) {
    if (x[mo][a].child[0] == 0) {
      x[mo][a].child[0] = x[mo].size();
      x[mo].push_back(wbt);
    }
    f1(x[mo][a].child[0], b, bc, d, min(e, bc));
  }
  if (e > bc) {
    if (x[mo][a].child[1] == 0) {
      x[mo][a].child[1] = x[mo].size();
      x[mo].push_back(wbt);
    }
    f1(x[mo][a].child[1], bc, c, max(d, bc), e);
  }
}
void f4(vector<wa>& v, int a, int b, int c) {
  tc += v[a].v;
  int bc = (b + c) / 2;
  if (ya < bc) {
    if (v[a].child[0]) f4(v, v[a].child[0], b, bc);
  } else {
    if (v[a].child[1]) f4(v, v[a].child[1], bc, c);
  }
}
void f3(int a, int b, int c) {
  f4(x[mo][a].v, 0, 0, 1 << 14);
  int bc = (b + c) / 2;
  if (ta < bc) {
    if (x[mo][a].child[0]) f3(x[mo][a].child[0], b, bc);
  } else {
    if (x[mo][a].child[1]) f3(x[mo][a].child[1], bc, c);
  }
}
int main() {
  wbt.v.push_back(wat);
  for (int a = 0; a < 3; a++) x[a].push_back(wbt);
  scanf("%d", &n);
  yb = n * 2 + 2;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &ta);
    if (ta == 1) {
      scanf("%d%d%d%d", &ta, &tb, &tc, &td);
      add = ta & 1 ? 1 : -1;
      mo = 0;
      ya = ta & 1 ? tc : tc + 1;
      if (ta < 3)
        f1(0, 0, 1 << 14, tb, tb + td + 1);
      else
        f1(0, 0, 1 << 14, tb - td, tb + 1);
      add *= -1;
      mo = abs(5 - ta * 2) == 1 ? 1 : 2;
      if (ta == 1)
        ya = tc + td + 1 + tb;
      else if (ta == 2)
        ya = tc - td - tb + n;
      else if (ta == 3)
        ya = tc + td + 1 - tb + n;
      else
        ya = tc - td + tb;
      if (ta < 3)
        f1(0, 0, 1 << 14, tb, tb + td + 1);
      else
        f1(0, 0, 1 << 14, tb - td, tb + 1);
    } else {
      scanf("%d%d", &ta, &tb);
      tc = 0;
      mo = 0;
      ya = tb;
      f3(0, 0, 1 << 14);
      mo = 1;
      ya = tb - ta + n;
      f3(0, 0, 1 << 14);
      mo = 2;
      ya = tb + ta;
      f3(0, 0, 1 << 14);
      printf("%d\n", tc);
    }
  }
  return 0;
}