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>
#pragma GCC optimize(3)
using namespace std;
const int maxn = 1e6 + 5;
int n, inp[maxn][5], ans[maxn], Q;
struct BIT {
  int c[maxn];
  void _modify(int x, int v) {
    for (; x <= n * 2; x += (x & -x)) c[x] += v;
  }
  void modify(int l, int r, int v) {
    _modify(l, v);
    _modify(r + 1, -v);
  }
  int query(int x) {
    int ret = 0;
    for (; x; x -= (x & -x)) ret += c[x];
    return ret;
  }
} t1, t2;
struct rec {
  int p1, p2, p3, p4;
} qry[maxn], pro[maxn];
bool cmp(rec a, rec b) {
  int k1 = a.p1 == -1 ? a.p2 + a.p4 : a.p2,
      k2 = b.p1 == -1 ? b.p2 + b.p4 : b.p2;
  if (k1 != k2) return k1 < k2;
  if (a.p1 == 0)
    k1 = 1;
  else if (a.p1 == -1)
    k1 = 3;
  else
    k1 = 2;
  if (b.p1 == 0)
    k2 = 1;
  else if (b.p1 == -1)
    k2 = 3;
  else
    k2 = 2;
  return k1 < k2;
}
void solve(int nl, int nr) {
  if (nl >= nr) return;
  int mid = nl + nr >> 1, cnt = 0;
  for (int i = nl; i <= mid; i++)
    if (!qry[i].p1) pro[++cnt] = qry[i], pro[++cnt] = qry[i], pro[cnt].p1 = -1;
  for (int i = mid + 1; i <= nr; i++)
    if (qry[i].p1) pro[++cnt] = qry[i];
  sort(pro + 1, pro + 1 + cnt, cmp);
  for (int i = 1; i <= cnt; i++) {
    if (pro[i].p1 == 0)
      t1.modify(1, pro[i].p2 + pro[i].p3 + pro[i].p4, 1),
          t2.modify(1, pro[i].p3 - 1, 1);
    if (pro[i].p1 == -1)
      t1.modify(1, pro[i].p2 + pro[i].p3 + pro[i].p4, -1),
          t2.modify(1, pro[i].p3 - 1, -1);
    if (pro[i].p1 > 0)
      ans[pro[i].p1] += t1.query(pro[i].p2 + pro[i].p3) - t2.query(pro[i].p3);
  }
  solve(nl, mid);
  solve(mid + 1, nr);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int query_cnt = 0;
  cin >> n >> Q;
  for (int i = 1; i <= Q; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      cin >> inp[i][1] >> inp[i][2] >> inp[i][3] >> inp[i][4];
    } else {
      inp[i][0] = ++query_cnt;
      cin >> inp[i][1] >> inp[i][2];
    }
  }
  int cnt = 0;
  for (int i = 1; i <= Q; i++)
    if (inp[i][0])
      qry[++cnt] = (rec){inp[i][0], inp[i][1], inp[i][2]};
    else if (inp[i][1] == 1)
      qry[++cnt] = (rec){0, inp[i][2], inp[i][3], inp[i][4]};
  solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= Q; i++)
    if (inp[i][0])
      qry[++cnt] = (rec){inp[i][0], n + 1 - inp[i][2], inp[i][1]};
    else if (inp[i][1] == 2)
      qry[++cnt] = (rec){0, n + 1 - inp[i][3], inp[i][2], inp[i][4]};
  solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= Q; i++)
    if (inp[i][0])
      qry[++cnt] = (rec){inp[i][0], inp[i][2], n + 1 - inp[i][1]};
    else if (inp[i][1] == 3)
      qry[++cnt] = (rec){0, inp[i][3], n + 1 - inp[i][2], inp[i][4]};
  solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= Q; i++)
    if (inp[i][0])
      qry[++cnt] = (rec){inp[i][0], n + 1 - inp[i][1], n + 1 - inp[i][2]};
    else if (inp[i][1] == 4)
      qry[++cnt] = (rec){0, n + 1 - inp[i][2], n + 1 - inp[i][3], inp[i][4]};
  solve(1, cnt);
  for (int i = 1; i <= query_cnt; i++) cout << ans[i] << '\n';
  return 0;
}