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;
const int N = 1e5 + 50, M = 5e3 + 50;
int n, m, as[N];
struct node {
  int t, vl, coe;
};
namespace BIT {
int c[N];
void mdf(int x, int v) {
  for (; x <= m; x += x & -x) c[x] += v;
}
int ask(int x) {
  int as = 0;
  for (; x; x -= x & -x) as += c[x];
  return as;
}
}  // namespace BIT
namespace SGT {
const int N = ::M << 2;
vector<node> mdf[3][N];
void ins(int x, int l, int r, int L, int R, int op, node now) {
  if (L <= l && r <= R) {
    mdf[op][x].push_back(now);
    return;
  }
  if (L <= ((l + r) >> 1)) ins(x << 1, l, ((l + r) >> 1), L, R, op, now);
  if (R > ((l + r) >> 1)) ins(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, op, now);
}
void qry(int u, int l, int r, int p, int t, int x, int y) {
  mdf[0][u].push_back({t, y, 0});
  mdf[1][u].push_back({t, x + y, 0});
  mdf[2][u].push_back({t, y - x, 0});
  if (l == r) return;
  if (p <= ((l + r) >> 1))
    qry(u << 1, l, ((l + r) >> 1), p, t, x, y);
  else
    qry(u << 1 | 1, ((l + r) >> 1) + 1, r, p, t, x, y);
}
void subwork(vector<node> &A) {
  if (!A.size()) return;
  sort(A.begin(), A.end(), [](const node &a, const node &b) {
    if (a.vl == b.vl) return abs(a.coe) > abs(b.coe);
    return a.vl > b.vl;
  });
  for (auto a : A) {
    if (a.coe)
      BIT::mdf(a.t, a.coe);
    else
      as[a.t] += BIT::ask(a.t);
  }
  for (auto a : A)
    if (a.coe) BIT::mdf(a.t, -a.coe);
}
void work(int u, int l, int r) {
  subwork(mdf[0][u]);
  subwork(mdf[1][u]);
  subwork(mdf[2][u]);
  if (l == r) return;
  work(u << 1, l, ((l + r) >> 1));
  work(u << 1 | 1, ((l + r) >> 1) + 1, r);
}
}  // namespace SGT
int main() {
  scanf("%d%d", &n, &m);
  static bool vs[N];
  for (int i = 1, op, dir, x, y, len; i <= m; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d%d", &dir, &x, &y, &len);
      if (dir == 1) {
        SGT::ins(1, 1, n, x, x + len, 1, {i, x + y + len, 1});
        SGT::ins(1, 1, n, x, x + len, 0, {i, y - 1, -1});
      }
      if (dir == 2) {
        SGT::ins(1, 1, n, x, x + len, 0, {i, y, 1});
        SGT::ins(1, 1, n, x, x + len, 2, {i, y - len - 1 - x, -1});
      }
      if (dir == 3) {
        SGT::ins(1, 1, n, x - len, x, 2, {i, y + len - x, 1});
        SGT::ins(1, 1, n, x - len, x, 0, {i, y - 1, -1});
      }
      if (dir == 4) {
        SGT::ins(1, 1, n, x - len, x, 0, {i, y, 1});
        SGT::ins(1, 1, n, x - len, x, 1, {i, x + y - len - 1, -1});
      }
    }
    if (op == 2) {
      scanf("%d%d", &x, &y);
      vs[i] = true;
      SGT::qry(1, 1, n, x, i, x, y);
    }
  }
  SGT::work(1, 1, n);
  for (int i = 1; i <= m; i++)
    if (vs[i]) cout << as[i] << '\n';
  return 0;
}