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>
inline int read() {
  static char ch;
  while (ch = getchar(), ch < '0' || ch > '9')
    ;
  int res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  return res;
}
inline unsigned int Rand() {
  static unsigned int x = 998666131;
  return x += x << 2 | 1;
}
const int N = 5001, M = 1e5 + 5, T = 2e6;
int n, m, Q, ans[M];
bool vis[M];
struct QueryT {
  int op, x, y, dir, len, lab;
  inline void Reset1(const int &_op, const int &_dir, const int &_x,
                     const int &_y, const int &_len) {
    op = _op;
    dir = _dir;
    x = _x;
    y = _y;
    len = _len;
  }
  inline void Reset2(const int &_op, const int &_dir, const int &_x,
                     const int &_y, const int &_lab) {
    op = _op;
    dir = _dir;
    x = _x;
    y = _y;
    lab = _lab;
    len = x + y;
  }
  inline bool operator<=(const QueryT &rhs) {
    if (x != rhs.x) return x < rhs.x;
    return op < rhs.op;
  }
} qry[M * 4], tmp[M * 4];
struct node {
  node *lc, *rc;
  int val, sze;
  unsigned int pri;
  inline void Update() { sze = (lc ? lc->sze : 0) + (rc ? rc->sze : 0) + 1; }
} used[T], *pool = used;
node *rt[5][N];
inline node *new_node() {
  node *res = pool++;
  res->lc = res->rc = NULL;
  return res;
}
inline void Zig(node *&u) {
  node *v = u->lc;
  u->lc = v->rc;
  v->rc = u;
  v->sze = u->sze;
  u->Update();
  u = v;
}
inline void Zag(node *&u) {
  node *v = u->rc;
  u->rc = v->lc;
  v->lc = u;
  v->sze = u->sze;
  u->Update();
  u = v;
}
inline void Insert(node *&u, const int &val) {
  if (!u) {
    u = new_node();
    u->val = val;
    u->sze = 1;
    u->pri = Rand();
    return;
  }
  ++u->sze;
  if (val <= u->val) {
    Insert(u->lc, val);
    if (u->lc->pri < u->pri) Zig(u);
  } else {
    Insert(u->rc, val);
    if (u->rc->pri < u->pri) Zag(u);
  }
}
inline int moreQuery(node *u, const int &val) {
  if (!u) return 0;
  if (u->val < val) return moreQuery(u->rc, val);
  return (u->rc ? u->rc->sze + 1 : 1) + moreQuery(u->lc, val);
}
inline void add(node **R, int x, const int &val) {
  for (; x <= n; x += x & -x) Insert(R[x], val);
}
inline int Query(node **R, int x, const int &val) {
  int res = 0;
  for (; x > 0; x -= x & -x) res += moreQuery(R[x], val);
  return res;
}
inline void Clear(node **R, int x) {
  for (; x <= n && R[x]; x += x & -x) R[x] = NULL;
}
inline void cdqSolve(const int &l, const int &r) {
  if (l == r) return;
  int mid = l + r >> 1;
  cdqSolve(l, mid);
  cdqSolve(mid + 1, r);
  int ql = l, qr = mid + 1;
  for (int i = (l); i <= (r); ++i) {
    if (qr > r || (ql <= mid && qry[ql] <= qry[qr])) {
      tmp[i] = qry[ql++];
      if (tmp[i].op == 1) add(rt[tmp[i].dir], tmp[i].y, tmp[i].len);
    } else {
      tmp[i] = qry[qr++];
      if (tmp[i].op == 2)
        ans[tmp[i].lab] += Query(rt[tmp[i].dir], tmp[i].y, tmp[i].len);
    }
  }
  for (int i = (l); i <= (r); ++i) {
    qry[i] = tmp[i];
    if (qry[i].op == 1) Clear(rt[qry[i].dir], qry[i].y);
  }
  pool = used;
}
int main() {
  n = read();
  Q = read();
  int op, x, y, len, dir;
  for (int i = (1); i <= (Q); ++i) {
    op = read();
    if (op == 1) {
      dir = read(), x = read(), y = read(), len = read();
      if (dir == 2) y = n - y + 1;
      if (dir == 3) x = n - x + 1;
      if (dir == 4) x = n - x + 1, y = n - y + 1;
      len += x + y;
      qry[++m].Reset1(op, dir, x, y, len);
    } else {
      x = read(), y = read();
      qry[++m].Reset2(op, 1, x, y, i);
      qry[++m].Reset2(op, 2, x, n - y + 1, i);
      qry[++m].Reset2(op, 3, n - x + 1, y, i);
      qry[++m].Reset2(op, 4, n - x + 1, n - y + 1, i);
      vis[i] = true;
    }
  }
  cdqSolve(1, m);
  for (int i = (1); i <= (Q); ++i)
    if (vis[i]) printf("%d\n", ans[i]);
  return 0;
}