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("O2")
using namespace std;
int num, n, q;
int ans[100005], tot[5];
struct qry {
  int t, x, y;
} qr[100005];
struct mdy {
  int t, x, y, z;
} md[5][100005];
struct node {
  int x, y, z;
  bool isQry, isAdd;
} a[100005 * 3], tmp[100005 * 3];
bool cmpNode(const node &u, const node &v) {
  if (u.x == v.x) {
    if (u.y == v.y) {
      if (u.z == v.z) {
        return u.isQry < v.isQry;
      }
      return u.z < v.z;
    }
    return u.y < v.y;
  }
  return u.x < v.x;
}
namespace BIT {
int c[100005];
inline void update(int p, int v) {
  for (int i = p; i <= q; i += (i & -i)) c[i] += v;
}
inline int sum(int p) {
  int res = 0;
  for (int i = p; i > 0; i -= (i & -i)) res += c[i];
  return res;
}
}  // namespace BIT
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
void merge(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  merge(l, mid), merge(mid + 1, r);
  int lp = l, rp = mid + 1, p = l - 1;
  while (lp <= mid && rp <= r) {
    if (a[lp].y <= a[rp].y) {
      tmp[++p] = a[lp], ++lp;
      if (!tmp[p].isQry) BIT::update(tmp[p].z, tmp[p].isAdd ? 1 : -1);
    } else {
      tmp[++p] = a[rp], ++rp;
      if (tmp[p].isQry) ans[tmp[p].z] += BIT::sum(tmp[p].z);
    }
  }
  for (; rp <= r; ++rp) {
    tmp[++p] = a[rp];
    if (tmp[p].isQry) ans[tmp[p].z] += BIT::sum(tmp[p].z);
  }
  for (int tp = l; tp < lp; ++tp)
    if (!a[tp].isQry) BIT::update(a[tp].z, a[tp].isAdd ? -1 : 1);
  for (; lp <= mid; ++lp) tmp[++p] = a[lp];
  for (p = l; p <= r; ++p) a[p] = tmp[p];
}
int main() {
  n = read(), q = read();
  for (int i = 1, opt, type, x, y, z; i <= q; ++i) {
    opt = read();
    if (opt == 1) {
      type = read();
      ++tot[type];
      x = read(), y = read(), z = read();
      md[type][tot[type]] = (mdy){i, x, y, z};
    } else {
      x = read(), y = read();
      qr[++tot[0]] = (qry){i, x, y};
    }
  }
  int total;
  mdy tm;
  total = 0;
  for (int i = 1; i <= tot[0]; ++i)
    a[++total] = (node){-(qr[i].x + qr[i].y), qr[i].x, qr[i].t, true, false};
  for (int i = 1, x, y; i <= tot[1]; ++i) {
    tm = md[1][i];
    x = tm.x, y = tm.y + tm.z;
    a[++total] = (node){-(x + y), x, tm.t, false, true};
  }
  for (int i = 1, x, y; i <= tot[4]; ++i) {
    tm = md[4][i];
    x = tm.x + 1, y = tm.y - tm.z - 2;
    a[++total] = (node){-(x + y), x, tm.t, false, true};
  }
  sort(a + 1, a + total + 1, cmpNode);
  merge(1, total);
  total = 0;
  for (int i = 1; i <= tot[0]; ++i)
    a[++total] = (node){qr[i].y - qr[i].x, qr[i].x, qr[i].t, true, false};
  for (int i = 1, x, y; i <= tot[2]; ++i) {
    tm = md[2][i];
    x = tm.x, y = tm.y - tm.z;
    a[++total] = (node){y - x, x, tm.t, false, true};
  }
  for (int i = 1, x, y; i <= tot[3]; ++i) {
    tm = md[3][i];
    x = tm.x + 1, y = tm.y + tm.z + 2;
    a[++total] = (node){y - x, x, tm.t, false, true};
  }
  sort(a + 1, a + total + 1, cmpNode);
  merge(1, total);
  total = 0;
  for (int i = 1; i <= tot[0]; ++i)
    a[++total] = (node){qr[i].x - qr[i].y, qr[i].y, qr[i].t, true, false};
  for (int i = 1, x, y; i <= tot[3]; ++i) {
    tm = md[3][i];
    x = tm.x - tm.z, y = tm.y;
    a[++total] = (node){x - y, y, tm.t, false, true};
  }
  for (int i = 1, x, y; i <= tot[2]; ++i) {
    tm = md[2][i];
    x = tm.x + tm.z + 2, y = tm.y + 1;
    a[++total] = (node){x - y, y, tm.t, false, true};
  }
  sort(a + 1, a + total + 1, cmpNode);
  merge(1, total);
  total = 0;
  for (int i = 1; i <= tot[0]; ++i)
    a[++total] = (node){-qr[i].y, qr[i].x + qr[i].y, qr[i].t, true, false};
  for (int i = 1, x, y; i <= tot[4]; ++i) {
    tm = md[4][i];
    x = tm.x - tm.z, y = tm.y;
    a[++total] = (node){-y, x + y, tm.t, false, true};
  }
  for (int i = 1, x, y; i <= tot[1]; ++i) {
    tm = md[1][i];
    x = tm.x + tm.z + 2, y = tm.y - 1;
    a[++total] = (node){-y, x + y, tm.t, false, true};
  }
  sort(a + 1, a + total + 1, cmpNode);
  merge(1, total);
  total = 0;
  for (int i = 1; i <= tot[0]; ++i)
    a[++total] = (node){-qr[i].y, qr[i].x, qr[i].t, true, false};
  for (int i = 1, x, y; i <= tot[1]; ++i) {
    tm = md[1][i];
    x = tm.x, y = tm.y - 1;
    a[++total] = (node){-y, x, tm.t, false, false};
  }
  for (int i = 1, x, y; i <= tot[4]; ++i) {
    tm = md[4][i];
    x = tm.x + 1, y = tm.y;
    a[++total] = (node){-y, x, tm.t, false, false};
  }
  sort(a + 1, a + total + 1, cmpNode);
  merge(1, total);
  total = 0;
  for (int i = 1; i <= tot[0]; ++i)
    a[++total] = (node){qr[i].x, qr[i].y, qr[i].t, true, false};
  for (int i = 1, x, y; i <= tot[2]; ++i) {
    tm = md[2][i];
    x = tm.x, y = tm.y + 1;
    a[++total] = (node){x, y, tm.t, false, false};
  }
  for (int i = 1, x, y; i <= tot[3]; ++i) {
    tm = md[3][i];
    x = tm.x + 1, y = tm.y;
    a[++total] = (node){x, y, tm.t, false, false};
  }
  sort(a + 1, a + total + 1, cmpNode);
  merge(1, total);
  for (int i = 1; i <= tot[0]; ++i) printf("%d\n", ans[qr[i].t]);
  return 0;
}