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("Ofast")
#pragma GCC optimize("inline", "no-stack-protector", "unroll-loops")
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class I>
inline void gi(I &x) {
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = (x << 1) + (x << 3) + (c & 15);
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::gi;
using io ::print;
using io ::putc;
const int N = 5005, M = 1e5 + 5;
int opt[M];
struct Node {
  int d, l, r, len;
} q[M];
int ans[M];
int n, m, id = 0;
void init(Node &now) {
  if (now.d == 1)
    return;
  else if (now.d == 2)
    swap(now.l, now.r), now.l = n - now.l + 1;
  else if (now.d == 3)
    now.l = n - now.l + 1;
  else
    now.l = n - now.l + 1, now.r = n - now.r + 1;
}
struct Query {
  int opt, x, l, r, v;
};
bool cmp(Query a, Query b) { return a.x < b.x; }
struct BIT {
  int c[N], tot;
  Query q[M * 6];
  void update(int x, int v) {
    for (; x <= n; x += (x & (-x))) c[x] += v;
  }
  int query(int x) {
    int ans = 0;
    for (; x; x -= (x & (-x))) ans += c[x];
    return ans;
  }
  void update(int x1, int x2, int y1, int y2, int v) {
    q[++tot] = (Query){1, x1, y1, y2, v};
    q[++tot] = (Query){1, x2 + 1, y1, y2, -v};
  }
  void query(int x, int y, int pos) { q[++tot] = (Query){0, x, y, y, pos}; }
  void solve(int l, int r) {
    if (l == r) return;
    int mid = (l + r) >> 1, c1 = 0, c2 = 0;
    static Query upd[M * 3], qry[M * 3];
    for (int i = l; i <= mid; i++)
      if (q[i].opt) upd[++c1] = q[i];
    for (int i = mid + 1; i <= r; i++)
      if (!q[i].opt) qry[++c2] = q[i];
    sort(upd + 1, upd + c1 + 1, cmp);
    sort(qry + 1, qry + c2 + 1, cmp);
    int lst = 1;
    for (int i = 1; i <= c2; i++) {
      for (; lst <= c1 && upd[lst].x <= qry[i].x; lst++) {
        update(upd[lst].l, upd[lst].v);
        update(upd[lst].r + 1, -upd[lst].v);
      }
      ans[qry[i].v] += query(qry[i].l);
    }
    for (int i = 1; i < lst; i++) {
      update(upd[i].l, -upd[i].v);
      update(upd[i].r + 1, upd[i].v);
    }
    solve(l, mid);
    solve(mid + 1, r);
  }
} bit[2];
void work(int now) {
  for (int i = 1; i <= m; i++)
    if (opt[i] == 1) {
      if (q[i].d != now) continue;
      int l = q[i].l + q[i].r, r = q[i].l + q[i].r + q[i].len;
      r = min(r, n * 2);
      bit[0].update(l, r, 1, n, 1);
      bit[0].update(l, r, 1, q[i].l - 1, -1);
      bit[1].update(l, r, 1, q[i].r - 1, -1);
    } else {
      Node x = q[i];
      x.d = now;
      init(x);
      bit[0].query(x.l + x.r, x.l, x.len);
      bit[1].query(x.l + x.r, x.r, x.len);
    }
  bit[0].solve(1, bit[0].tot);
  bit[0].tot = 0;
  bit[1].solve(1, bit[1].tot);
  bit[1].tot = 0;
}
int main() {
  int Num;
  gi(n), gi(m);
  for (int i = 1; i <= m; i++) {
    gi(opt[i]);
    if (opt[i] == 1)
      gi(q[i].d), gi(q[i].l), gi(q[i].r), gi(q[i].len), init(q[i]);
    else
      gi(q[i].l), gi(q[i].r), q[i].len = ++id;
  }
  for (int i = 1; i <= 4; i++) work(i);
  for (int i = 1; i <= id; i++) print(ans[i]), putc('\n');
  return 0;
}