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;
namespace IO {
const int SIZE = 1 << 20;
char buf[SIZE + 10], *iS, *iT;
inline char Getc() {
  return iS == iT && (iT = (iS = buf) + fread(buf, 1, SIZE, stdin), iS == iT)
             ? EOF
             : *iS++;
}
template <class TT>
inline void Read(TT &x) {
  x = 0;
  register char cc = '\0';
  TT fff = 1;
  for (; cc < '0' || cc > '9'; cc = Getc())
    if (cc == '-') fff = -1;
  for (; cc >= '0' && cc <= '9'; cc = Getc())
    x = (x << 1) + (x << 3) + (cc & 15);
  x *= fff;
}
}  // namespace IO
using IO::Read;
const int U = 5088, N = 1e5 + 10;
struct BIT {
  int Tree[U + 10];
  inline void Update(int x, int ad) {
    for (int i = x; i; i -= i & -i) Tree[i] += ad;
  }
  inline int Query(int x) {
    int fsum = 0;
    for (int i = x; i <= U; i += i & -i) fsum += Tree[i];
    return fsum;
  }
} ta, tb;
struct asknode {
  int tm, dir, x, y, alen;
} ak[N];
struct qrynode {
  int tp, x, y, dis, ad;
  inline void Getdis(int z) { dis = x + y + z; }
  bool operator<(const qrynode &Other) const {
    return dis == Other.dis ? tp > Other.tp : dis < Other.dis;
  }
} b[2 * N], c[2 * N];
bool mk[2 * N];
int n, q, cnt, fans[N];
void Solve(int nl, int nr) {
  if (nl == nr) return;
  int nm = (nl + nr) >> 1;
  Solve(nl, nm), Solve(nm + 1, nr);
  int i = nl, j = nm + 1, k = nl;
  for (k = nl; k <= nr; ++k)
    if ((i <= nm && b[i] < b[j]) || j > nr)
      c[k] = b[i++], mk[k] = false;
    else
      c[k] = b[j++], mk[k] = true;
  int qans = 0;
  for (k = nl; k <= nr; ++k) {
    if (!c[k].tp && mk[k]) {
      fans[c[k].ad] += qans - (ta.Query(c[k].x) + tb.Query(c[k].y));
    }
    if (c[k].tp && !mk[k]) {
      qans += c[k].ad;
      ta.Update(c[k].x - 1, c[k].ad);
      tb.Update(c[k].y - 1, c[k].ad);
    }
  }
  for (k = nl; k <= nr; ++k) {
    b[k] = c[k];
    if (c[k].tp && !mk[k]) {
      ta.Update(c[k].x - 1, -c[k].ad);
      tb.Update(c[k].y - 1, -c[k].ad);
    }
  }
}
int main() {
  Read(n), Read(q);
  for (int i = 1, op; i <= q; ++i) {
    Read(op);
    ak[i].tm = i;
    if (op == 1) {
      Read(ak[i].dir);
      Read(ak[i].x), Read(ak[i].y), Read(ak[i].alen);
    } else {
      ak[i].dir = 0;
      Read(ak[i].x), Read(ak[i].y);
    }
  }
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 1) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, ak[i].y, 0,
                           (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, ak[i].y, 0,
                             (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 2) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, n - ak[i].y + 1, 0,
                           (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, n - ak[i].y + 1, 0,
                             (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 3) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1, ak[i].y, 0,
                           (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1, ak[i].y, 0,
                             (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 4) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1,
                           n - ak[i].y + 1, 0, (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1,
                             n - ak[i].y + 1, 0, (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  for (int i = 1; i <= q; ++i)
    if (!ak[i].dir) printf("%d\n", fans[i]);
  return 0;
}