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;
int n, q;
struct opt {
  int tp, dir, x, y, len, ans;
} op[100000];
struct data_structure {
  int n, m, data[5005][10005];
  void init(int N, int M) {
    n = N;
    m = M;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) data[i][j] = 0;
    return;
  }
  inline int lb(int x) { return x & (-x); }
  void upd(int x, int y, int k) {
    if (x > n || y > m) return;
    for (int i = x; i <= n; i += lb(i))
      for (int j = y; j <= m; j += lb(j)) data[i][j] += k;
    return;
  }
  void update(int l, int r, int d, int u, int k) {
    l = max(l, 0);
    d = max(d, 0);
    r = min(r, n);
    u = min(u, m);
    upd(l, d, k);
    upd(r + 1, u + 1, k);
    upd(l, u + 1, -k);
    upd(r + 1, d, -k);
    return;
  }
  int query(int x, int y) {
    int res = 0;
    for (int i = x; i > 0; i -= lb(i))
      for (int j = y; j > 0; j -= lb(j)) res += data[i][j];
    return res;
  }
} ds;
int main(void) {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &op[i].tp);
    if (op[i].tp == 1)
      scanf("%d%d%d%d", &op[i].dir, &op[i].x, &op[i].y, &op[i].len);
    else
      scanf("%d%d", &op[i].x, &op[i].y);
    op[i].ans = 0;
  }
  ds.init(n, n + n + 1);
  for (int i = 0; i < q; i++) {
    int x = op[i].x, y = op[i].y, len = op[i].len;
    if (op[i].tp == 1 && op[i].dir == 1) ds.update(x, n, x + y, x + y + len, 1);
    if (op[i].tp == 1 && op[i].dir == 4) ds.update(1, x, x + y - len, x + y, 1);
    if (op[i].tp == 2) op[i].ans += ds.query(x, x + y);
  }
  ds.init(n, n + n + 1);
  for (int i = 0; i < q; i++) {
    int x = op[i].x, y = op[i].y, len = op[i].len;
    if (op[i].tp == 1 && op[i].dir == 1)
      ds.update(1, y - 1, x + y, x + y + len, -1);
    if (op[i].tp == 1 && op[i].dir == 4)
      ds.update(y + 1, n, x + y - len, x + y, -1);
    if (op[i].tp == 2) op[i].ans += ds.query(y, x + y);
  }
  ds.init(n, n + n + 1);
  for (int i = 0; i < q; i++) {
    int x = op[i].x, y = op[i].y, len = op[i].len;
    if (op[i].tp == 1 && op[i].dir == 2)
      ds.update(x, n, x - y + n, x - y + n + len, 1);
    if (op[i].tp == 1 && op[i].dir == 3)
      ds.update(1, x, x - y + n - len, x - y + n, 1);
    if (op[i].tp == 2) op[i].ans += ds.query(x, x - y + n);
  }
  ds.init(n, n + n + 1);
  for (int i = 0; i < q; i++) {
    int x = op[i].x, y = op[i].y, len = op[i].len;
    if (op[i].tp == 1 && op[i].dir == 2)
      ds.update(y + 1, n, x - y + n, x - y + n + len, -1);
    if (op[i].tp == 1 && op[i].dir == 3)
      ds.update(1, y - 1, x - y + n - len, x - y + n, -1);
    if (op[i].tp == 2) {
      op[i].ans += ds.query(y, x - y + n);
      printf("%d\n", op[i].ans);
    }
  }
  return 0;
}