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 = 1e5 + 5, M = 5005;
int n, q, qs;
struct op {
  int op, x, y, len;
} a[N], b[N], c[N];
int t[M][M * 2], an[N];
void chx(int x, int y, int v) {
  for (; x <= n; x += (x & -x))
    for (int i = y; i; i -= (i & -i)) t[x][i] += v;
}
int qu(int x, int y) {
  int s = 0;
  for (; x; x -= (x & -x))
    for (int i = y; i <= n + n; i += (i & -i)) s += t[x][i];
  return s;
}
void cdq(int l, int r) {
  if (l == r) return;
  int m = l + r >> 1;
  cdq(l, m);
  cdq(m + 1, r);
  int can = 0;
  for (int i = l, _e = m; i <= _e; ++i)
    if (b[i].op != 5) {
      can = 1;
      break;
    }
  if (can) {
    can = 0;
    for (int i = m + 1, _e = r; i <= _e; ++i)
      if (b[i].op == 5) {
        can = 1;
        break;
      }
  }
  int j = l, w = l;
  for (int i = m + 1, _e = r; i <= _e; ++i) {
    for (; j <= m && b[j].x <= b[i].x;) {
      can &&b[j].op < 5 ? (chx(b[j].y, b[j].x + b[j].y + b[j].len, 1)), 0 : 0;
      c[w++] = b[j++];
    }
    can&& b[i].op == 5 ? an[b[i].len] += qu(b[i].y, b[i].x + b[i].y) : 0;
    c[w++] = b[i];
  }
  if (can)
    for (int i = l, _e = j - 1; i <= _e; ++i)
      b[i].op < 5 ? (chx(b[i].y, b[i].x + b[i].y + b[i].len, -1)), 0 : 0;
  for (; j <= m;) c[w++] = b[j++];
  memcpy(b + l, c + l, sizeof(op) * (r - l + 1));
}
void get(int o, int r1, int r2) {
  int bs = 0;
  for (int i = 1, _e = q; i <= _e; ++i)
    if (a[i].op == o || a[i].op == 5)
      b[++bs] = a[i], (r1 ? b[bs].x = n - b[bs].x + 1 : 0),
      (r2 ? b[bs].y = n - b[bs].y + 1 : 0);
  cdq(1, bs);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 1, _e = q; i <= _e; ++i) {
    cin >> a[i].op;
    if (a[i].op == 1)
      cin >> a[i].op >> a[i].x >> a[i].y >> a[i].len;
    else
      a[i].op = 5, cin >> a[i].x >> a[i].y, a[i].len = ++qs;
  }
  get(1, 0, 0);
  get(2, 0, 1);
  get(3, 1, 0);
  get(4, 1, 1);
  for (int i = 1, _e = qs; i <= _e; ++i) cout << an[i] << endl;
}