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_ = 5030;
const int MAXC = N_ * 2;
int N, Q;
struct Fenwick2D {
  int tree[MAXC + 5][N_];
  int x_min;
  void upd(int r, int c, int d) {
    r -= x_min;
    r += 1;
    c += 1;
    assert(r >= 0 && c > 0);
    for (int i = r; i < MAXC; i += i & -i) {
      for (int j = c; j <= N + 10; j += j & -j) {
        tree[i][j] += d;
      }
    }
  }
  void upd(int r1, int r2, int c1, int c2, int d) {
    if (r1 > r2) return;
    assert(c1 <= c2);
    upd(r1, c1, +d);
    upd(r1, c2 + 1, -d);
    upd(r2 + 1, c1, -d);
    upd(r2 + 1, c2 + 1, +d);
  }
  int get(int r, int c) {
    r -= x_min;
    r += 1;
    c += 1;
    if (r == 0 || c == 0) return 0;
    int ret = 0;
    for (int i = r; i > 0; i -= i & -i) {
      for (int j = c; j > 0; j -= j & -j) {
        ret += tree[i][j];
      }
    }
    return ret;
  }
  void init() { memset(tree, 0, sizeof tree); }
};
Fenwick2D fenwick;
const int Q_ = 100500;
tuple<int, int, int, int, int> queries[Q_];
int ans[Q_];
int main() {
  scanf("%d%d", &N, &Q);
  fenwick.init();
  for (int i = 1; i <= Q; i++) {
    int t, dir = -1, x, y, len = -1;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d%d%d", &dir, &x, &y, &len);
      if (dir == 1) {
        fenwick.upd(1, x - 1, y, y + len, -1);
      } else if (dir == 2) {
        fenwick.upd(1, x - 1, y - len, y, -1);
      } else if (dir == 3) {
        fenwick.upd(x + 1, N, y, y + len, -1);
      } else if (dir == 4) {
        fenwick.upd(x + 1, N, y - len, y, -1);
      }
    } else {
      scanf("%d%d", &x, &y);
      ans[i] += fenwick.get(x, y);
    }
    queries[i] = tie(t, dir, x, y, len);
  }
  for (int cur_dir = 1; cur_dir <= 4; cur_dir++) {
    fenwick.x_min = (cur_dir == 2 || cur_dir == 3)
                        ? (1 - N)
                        : ((cur_dir == 4) ? (-N - N) : 0);
    fenwick.init();
    for (int i = 1; i <= Q; i++) {
      int t, dir, x, y, len;
      tie(t, dir, x, y, len) = queries[i];
      if (t == 1) {
        if (cur_dir != dir) continue;
        if (dir == 1) {
          fenwick.upd(1, x + y + len, y, y + len, +1);
        } else if (dir == 2) {
          fenwick.upd(1 - N, x - y + len, y - len, y, +1);
        } else if (dir == 3) {
          fenwick.upd(1 - N, y - x + len, y, y + len, +1);
        } else if (dir == 4) {
          fenwick.upd(-N - N, -x - y + len, y - len, y, +1);
        }
      } else {
        if (cur_dir == 1) ans[i] += fenwick.get(x + y, y);
        if (cur_dir == 2) ans[i] += fenwick.get(x - y, y);
        if (cur_dir == 3) ans[i] += fenwick.get(y - x, y);
        if (cur_dir == 4) ans[i] += fenwick.get(-x - y, y);
      }
    }
  }
  for (int i = 1; i <= Q; i++) {
    int t, dir, x, y, len;
    tie(t, dir, x, y, len) = queries[i];
    if (t == 2) printf("%d\n", ans[i]);
  }
  return 0;
}