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;
namespace TYC {
const int N = 5e6 + 5, M = 5005, MX = M * 3;
int n, ans[N], C[MX + 5];
struct node {
  int x, y, opt;
} A[N];
vector<node> V[3];
inline int read() {
  int x = 0, f = 0, ch = getchar();
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
inline void add(int x, int w) {
  x += M;
  for (; x <= MX; x += (x & (-x))) C[x] += w;
}
inline int query(int x) {
  x += M;
  int sum = 0;
  for (; x; x -= (x & (-x))) sum += C[x];
  return sum;
}
void solve(const int l, const int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  static node tmp[N];
  for (int i = l, j = mid + 1, k = 0; i <= mid || j <= r;)
    if (i <= mid && (j > r || A[i].x <= A[j].x)) {
      if (A[i].opt <= 0) add(A[i].y, A[i].opt == -1 ? -1 : 1);
      tmp[++k] = A[i++];
    } else {
      if (A[j].opt > 0) ans[A[j].opt] += query(A[j].y);
      tmp[++k] = A[j++];
    }
  for (int i = l; i <= mid; i++)
    if (A[i].opt <= 0) add(A[i].y, A[i].opt == -1 ? 1 : -1);
  memcpy(A + l, tmp + 1, sizeof(node[r - l + 1]));
}
inline void getv(vector<node> &ve, const int x1, const int x2, const int y1,
                 const int y2, const int t = 0) {
  if (x1 > x2 || y1 > y2) return;
  int a = 0, b = -1;
  if (t) swap(a, b);
  ve.push_back((node){x1, y1, a});
  ve.push_back((node){x2 + 1, y1, b});
  ve.push_back((node){x1, y2 + 1, b});
  ve.push_back((node){x2 + 1, y2 + 1, a});
}
inline void upd1(const int x, const int y, const int len, const int t = 0) {
  getv(V[0], x, x + len, 0, x + y + len, t);
  getv(V[2], x, x + len, 1, y - 1, t ^ 1);
}
inline void upd2(const int x, const int y, const int len, const int t = 0) {
  getv(V[1], x, x + len, -n, x - y + len, t);
  getv(V[2], x, x + len, y + 1, n, t ^ 1);
}
void work() {
  n = read();
  int m = read(), q = 0;
  for (int i = 1; i <= m; i++) {
    if (read() == 1) {
      int dir = read(), x = read(), y = read(), len = read();
      switch (dir) {
        case 1:
          upd1(x, y, len);
          break;
        case 2:
          upd2(x, y, len);
          break;
        case 3:
          getv(V[2], x - len, x, y, y + len);
          upd2(x - len, y + len, len - 1, 1);
          break;
        case 4:
          getv(V[2], x - len, x, y - len, y);
          upd1(x - len, y - len, len - 1, 1);
          break;
      }
    } else {
      ++q;
      int x = read(), y = read();
      V[0].push_back((node){x, x + y, q});
      V[1].push_back((node){x, x - y, q});
      V[2].push_back((node){x, y, q});
    }
  }
  for (int i = 0; i < 3; i++) {
    int cnt = 0;
    for (auto p : V[i]) A[++cnt] = p;
    solve(1, cnt);
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
}  // namespace TYC
int main() {
  TYC::work();
  return 0;
}