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;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
const double pi = asin(1.0) * 2;
const int N = 1 << 13;
int n;
int m;
vector<int> f[2 * N];
int ct;
int t[100000];
int x[100000];
int y[100000];
int len[100000];
int dir[100000];
int res[100000];
int build(int x, int l, int r) {
  f[x].resize(n + r - l + 2);
  if (l == r) return 0;
  int s = (l + r) / 2;
  build(x * 2 + 1, l, s);
  build(x * 2 + 2, s + 1, r);
  return 0;
}
int build2(int x, int l, int r) {
  memset(&f[x][0], 0, ((int)(f[x]).size()) * sizeof(int));
  if (l == r) return 0;
  int s = (l + r) / 2;
  build2(x * 2 + 1, l, s);
  build2(x * 2 + 2, s + 1, r);
  return 0;
}
int get(int x, int t, int y) {
  if (t != ct) return 0;
  y++;
  int s = 0;
  while (y < ((int)(f[x]).size())) {
    s += f[x][y];
    y |= y + 1;
  }
  return s;
}
void upd(int x, int t, int y, int z) {
  if (t != ct) return;
  y++;
  assert(y < ((int)(f[x]).size()));
  while (y > 0) {
    f[x][y] += z;
    y = (y & (y + 1)) - 1;
  }
}
int getf(int x, int l, int r, int xc, int yc) {
  return get(x, 0, yc) + get(x, 1, yc - xc + r) + get(x, 2, xc + yc - l);
}
int get(int x, int l, int r, int xc, int yc) {
  if (r < xc || l > xc) return 0;
  if (l == r) return getf(x, l, r, xc, yc);
  int s = (l + r) / 2;
  return get(x * 2 + 1, l, s, xc, yc) + get(x * 2 + 2, s + 1, r, xc, yc) +
         getf(x, l, r, xc, yc);
}
void upd(int x, int l, int r, int lc, int rc, int t, int y, int z) {
  if (t != ct) return;
  if (r < lc || l > rc) return;
  if (l >= lc && r <= rc) {
    if (t == 0) upd(x, t, y, z);
    if (t == 1) upd(x, t, y + r, z);
    if (t == 2) upd(x, t, y - l, z);
    return;
  }
  int s = (l + r) / 2;
  upd(x * 2 + 1, l, s, lc, rc, t, y, z);
  upd(x * 2 + 2, s + 1, r, lc, rc, t, y, z);
}
int main() {
  scanf("%d%d", &n, &m);
  build(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    scanf("%d", &t[i]);
    if (t[i] == 1) {
      scanf("%d%d%d%d", &dir[i], &x[i], &y[i], &len[i]);
      x[i]--;
      y[i]--;
    } else {
      scanf("%d%d", &x[i], &y[i]);
      x[i]--;
      y[i]--;
    }
  }
  for (ct = 0; ct < 3; ct++) {
    build2(0, 0, n - 1);
    for (int i = 0; i < m; i++) {
      int t = ::t[i];
      if (t == 1) {
        int dir = ::dir[i], x = ::x[i], y = ::y[i], len = ::len[i];
        if (dir == 1) {
          upd(0, 0, n - 1, x, x + len, 0, y - 1, -1);
          upd(0, 0, n - 1, x, x + len, 2, x + y + len, 1);
        }
        if (dir == 2) {
          upd(0, 0, n - 1, x, x + len, 0, y, 1);
          upd(0, 0, n - 1, x, x + len, 1, y - len - x - 1, -1);
        }
        if (dir == 3) {
          upd(0, 0, n - 1, x - len, x, 0, y - 1, -1);
          upd(0, 0, n - 1, x - len, x, 1, y + len - x, 1);
        }
        if (dir == 4) {
          upd(0, 0, n - 1, x - len, x, 0, y, 1);
          upd(0, 0, n - 1, x - len, x, 2, x + y - len - 1, -1);
        }
      } else {
        int x = ::x[i], y = ::y[i];
        res[i] += get(0, 0, n - 1, x, y);
      }
    }
  }
  for (int i = 0; i < m; i++)
    if (t[i] == 2) printf("%d\n", res[i]);
  return 0;
}