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 ck, n, q;
int dir[120000];
int opt[120000];
int ans[120000];
int pos[120000][2];
struct bit {
  int tag[5200][5200];
  int val[5200][5200];
  inline int query(int x, int y) {
    int ss = 0;
    int yy = y;
    while (x != 0) {
      y = yy;
      while (y != 0) {
        if (tag[x][y] != ck) {
          tag[x][y] = ck;
          val[x][y] = 0;
        }
        ss += val[x][y];
        y -= (y & (-y));
      }
      x -= (x & (-x));
    }
    return ss;
  }
  inline void edit(int x, int y, int va) {
    int yy = y;
    while (x <= n) {
      y = yy;
      while (y <= n) {
        if (tag[x][y] != ck) {
          tag[x][y] = ck;
          val[x][y] = 0;
        }
        val[x][y] += va;
        y += (y & (-y));
      }
      x += (x & (-x));
    }
  }
} sgt;
struct query {
  int x, y, type, comp, id;
} qu[120000], tmp[120000];
int tot, ctot;
inline bool cmp(query x, query y) {
  if (x.comp == y.comp) return x.type < y.type;
  return x.comp > y.comp;
}
inline void solve(int le, int ri) {
  if (le == ri) return;
  int mi = ((le + ri) >> 1), c1 = 0, c2 = 0;
  solve(le, mi);
  solve(mi + 1, ri);
  ctot = 0;
  for (int i = le; i <= mi; i++) {
    if (qu[i].type == 1) {
      c1++;
      ctot++;
      tmp[ctot] = qu[i];
    }
  }
  for (int i = mi + 1; i <= ri; i++) {
    if (qu[i].type == 2) {
      c2++;
      ctot++;
      tmp[ctot] = qu[i];
    }
  }
  if (c1 * c2 == 0) return;
  ck++;
  sort(tmp + 1, tmp + ctot + 1, cmp);
  for (int i = 1; i <= ctot; i++) {
    if (tmp[i].type == 1) {
      sgt.edit(tmp[i].x, tmp[i].y, 1);
    } else {
      ans[tmp[i].id] += sgt.query(tmp[i].x, tmp[i].y);
    }
  }
}
int lee[120000];
inline void work(int di) {
  tot = 0;
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 2 || dir[i] == di) {
      tot++;
      int x1, x2;
      if (di == 1) {
        x1 = pos[i][0];
        x2 = pos[i][1];
      } else if (di == 2) {
        x1 = pos[i][0];
        x2 = n + 1 - pos[i][1];
      } else if (di == 3) {
        x1 = n + 1 - pos[i][0];
        x2 = pos[i][1];
      } else {
        x1 = n + 1 - pos[i][0];
        x2 = n + 1 - pos[i][1];
      }
      qu[tot].x = x1;
      qu[tot].y = x2;
      qu[tot].type = opt[i];
      qu[tot].id = i;
      if (opt[i] == 2) {
        qu[tot].comp = x1 + x2;
      } else {
        qu[tot].comp = x1 + x2 + lee[i];
      }
    }
  }
  solve(1, tot);
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &opt[i]);
    if (opt[i] == 1)
      scanf("%d %d %d %d", &dir[i], &pos[i][0], &pos[i][1], &lee[i]);
    else
      scanf("%d %d", &pos[i][0], &pos[i][1]);
  }
  for (int i = 1; i <= 4; i++) {
    work(i);
  }
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 2) printf("%d\n", ans[i]);
  }
  return 0;
}