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;
template <class T>
inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
int a[5010][10050], n, m;
void add(int x, int y, int t) {
  if (x < 0 || y < 0) return;
  for (int i = x; i; i -= i & -i)
    for (int j = y; j; j -= j & -j) a[i][j] += t;
}
int query(int x, int y) {
  int ans = 0;
  for (int i = x; i <= n; i += i & -i)
    for (int j = y; j <= m; j += j & -j) ans += a[i][j];
  return ans;
}
struct item {
  int p, l, r, y, t;
};
vector<item> D[3];
int Qt[100010], Qx[100010], Qy[100010], ans[100010], Q, q;
int main() {
  rd(n), rd(q);
  for (int i = 1, op, x, y, len, dir; i <= q; ++i) {
    rd(op);
    if (op == 1) {
      rd(dir), rd(x), rd(y), rd(len);
      item A, B;
      if (dir <= 2)
        A.l = B.l = x, A.r = B.r = x + len;
      else
        A.l = B.l = x - len, A.r = B.r = x;
      A.p = B.p = i;
      if (dir == 1) {
        B.y = x + y + len, B.t = 1;
        D[1].push_back(B);
        A.y = y - 1, A.t = -1;
        D[0].push_back(A);
      } else if (dir == 2) {
        B.y = y - x - len - 1, B.t = -1;
        D[2].push_back(B);
        A.y = y, A.t = 1;
        D[0].push_back(A);
      } else if (dir == 3) {
        B.y = y - x + len, B.t = 1;
        D[2].push_back(B);
        A.y = y - 1, A.t = -1;
        D[0].push_back(A);
      } else {
        B.y = x + y - len - 1, B.t = -1;
        D[1].push_back(B);
        A.y = y, A.t = 1;
        D[0].push_back(A);
      }
    } else {
      Q++;
      Qt[Q] = i;
      rd(Qx[Q]), rd(Qy[Q]);
    }
  }
  for (int c = 0; c < 3; ++c) {
    memset(a, 0, sizeof(a));
    const int B = (c == 2 ? n + 1 : 0);
    m = c == 0 ? n : 2 * n;
    int cur = 1;
    while (D[c].size() && cur <= Q && D[c][0].p > Qt[cur]) cur++;
    for (int i = 0; i < D[c].size(); ++i) {
      add(D[c][i].l - 1, D[c][i].y + B, -D[c][i].t);
      add(D[c][i].r, D[c][i].y + B, D[c][i].t);
      while (cur <= Q && (i + 1 == D[c].size() || D[c][i + 1].p > Qt[cur])) {
        int x = Qx[cur], y = Qy[cur];
        if (c == 1) y = x + y;
        if (c == 2) y = y - x;
        ans[cur] += query(x, y + B);
        cur++;
      }
    }
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}