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>
template <typename _Tp>
void read(_Tp &x) {
  char ch(getchar());
  bool f(false);
  while (!isdigit(ch)) f |= ch == 45, ch = getchar();
  x = ch & 15, ch = getchar();
  while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
  if (f) x = -x;
}
template <typename _Tp, typename... Args>
void read(_Tp &t, Args &...args) {
  read(t);
  read(args...);
}
const int N = 5005, NN = 10005, M = 100005;
struct node {
  int x, y, z;
};
int ans[M], O[M], D[M], X[M], Y[M], L[M];
namespace DS {
int c[NN];
void add(int x, int C) {
  for (; x; x -= ((x) & (-(x)))) c[x] += C;
}
int ask(int x) {
  int ans = 0;
  for (; x < NN; x += ((x) & (-(x)))) ans += c[x];
  return ans;
}
}  // namespace DS
int c[N][NN];
void add(int x, int y, int C) {
  for (; x; x -= ((x) & (-(x))))
    for (int i = y; i; i -= ((i) & (-(i)))) c[x][i] += C;
}
int ask(int x, int y) {
  int ans = 0;
  for (; x < N; x += ((x) & (-(x))))
    for (int i = y; i < NN; i += ((i) & (-(i)))) ans += c[x][i];
  return ans;
}
void solve(const std::vector<node> &Q) {
  memset(DS::c, 0, sizeof(DS::c));
  for (auto [x, y, z] : Q) {
    if (z < 0)
      ans[-z] += DS::ask(std::min(x + y, NN - 1));
    else
      DS::add(std::min(x + y + z, NN - 1), 1);
  }
  memset(c, 0, sizeof(c));
  for (auto [x, y, z] : Q) {
    if (z < 0)
      ans[-z] += ask(x, std::min(x + y, NN - 1));
    else
      add(x - 1, std::min(x + y + z, NN - 1), -1);
  }
  memset(c, 0, sizeof(c));
  for (auto [x, y, z] : Q) {
    if (z < 0)
      ans[-z] += ask(y, std::min(x + y, NN - 1));
    else
      add(y - 1, std::min(x + y + z, NN - 1), -1);
  }
  memset(c, 0, sizeof(c));
  for (auto [x, y, z] : Q) {
    if (z < 0)
      ans[-z] += ask(x, y);
    else
      add(x - 1, y - 1, 1);
  }
}
int main() {
  int n, q;
  read(n, q);
  for (int i = 1; i <= q; ++i) {
    read(O[i]);
    if (O[i] == 1)
      read(D[i], X[i], Y[i], L[i]), --D[i];
    else
      read(X[i], Y[i]);
  }
  for (int d = 0; d < 4; ++d) {
    std::vector<node> Q;
    for (int i = 1; i <= q; ++i) {
      int x = X[i], y = Y[i];
      if (d & 1) y = n - y + 1;
      if (d & 2) x = n - x + 1;
      if (O[i] == 2)
        Q.push_back({x, y, -i});
      else if (D[i] == d)
        Q.push_back({x, y, L[i]});
    }
    solve(Q);
  }
  for (int i = 1; i <= q; ++i)
    if (O[i] == 2) printf("%d\n", ans[i]);
  return 0;
}