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 maxn = 5005;
const int maxm = 100005;
int n, q, dir;
int qt[maxm], qd[maxm], qx[maxm], qy[maxm], qlen[maxm], ans[maxm];
namespace Segtree {
const int maxs = maxn * 500;
int tot;
int ls[maxs], rs[maxs], rtx[maxs], rty[maxs], sum[maxs], tots[maxs];
void clear(int cur, int l, int r) {
  tot = 0;
  rtx[cur] = rty[cur] = tots[cur] = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  clear(cur << 1, l, mid);
  clear(cur << 1 | 1, mid + 1, r);
}
void sub_update(int &cur, int l, int r, int vl, int vr) {
  if (vl > vr) return;
  if (!cur) {
    cur = ++tot;
    ls[cur] = rs[cur] = sum[cur] = 0;
  }
  if (l >= vl && r <= vr) {
    sum[cur]++;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= vl) sub_update(ls[cur], l, mid, vl, vr);
  if (mid < vr) sub_update(rs[cur], mid + 1, r, vl, vr);
}
void update(int cur, int l, int r, int vl, int vr, int vx, int vy) {
  if (l >= vl && r <= vr) {
    tots[cur]++;
    sub_update(rtx[cur], 1, n, 1, vx);
    sub_update(rty[cur], 1, n, 1, vy);
    return;
  }
  int mid = l + r >> 1;
  if (mid >= vl) update(cur << 1, l, mid, vl, vr, vx, vy);
  if (mid < vr) update(cur << 1 | 1, mid + 1, r, vl, vr, vx, vy);
}
int sub_query(int cur, int l, int r, int k) {
  if (!cur) return 0;
  int res = sum[cur];
  if (l == r) return res;
  int mid = l + r >> 1;
  if (k <= mid)
    res += sub_query(ls[cur], l, mid, k);
  else
    res += sub_query(rs[cur], mid + 1, r, k);
  return res;
}
int query(int cur, int l, int r, int k, int kx, int ky) {
  int res =
      tots[cur] - sub_query(rtx[cur], 1, n, kx) - sub_query(rty[cur], 1, n, ky);
  if (l == r) return res;
  int mid = l + r >> 1;
  if (k <= mid)
    res += query(cur << 1, l, mid, k, kx, ky);
  else
    res += query(cur << 1 | 1, mid + 1, r, k, kx, ky);
  return res;
}
}  // namespace Segtree
void solve(int dir) {
  Segtree::clear(1, 1, 2 * n);
  for (int i = 1; i <= (q); i++) {
    if (qt[i] == 2) {
      ans[i] += Segtree::query(1, 1, 2 * n, qx[i] + qy[i], qx[i], qy[i]);
    } else if (qd[i] == dir) {
      Segtree::update(1, 1, 2 * n, qx[i] + qy[i], qx[i] + qy[i] + qlen[i],
                      qx[i] - 1, qy[i] - 1);
    }
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= (q); i++) {
    scanf("%d", &qt[i]);
    if (qt[i] == 1)
      scanf("%d%d%d%d", &qd[i], &qx[i], &qy[i], &qlen[i]);
    else
      scanf("%d%d", &qx[i], &qy[i]);
  }
  solve(1);
  for (int i = 1; i <= (q); i++) qy[i] = n - qy[i] + 1;
  solve(2);
  for (int i = 1; i <= (q); i++) qy[i] = n - qy[i] + 1, qx[i] = n - qx[i] + 1;
  solve(3);
  for (int i = 1; i <= (q); i++) qy[i] = n - qy[i] + 1;
  solve(4);
  for (int i = 1; i <= (q); i++)
    if (qt[i] == 2) printf("%d\n", ans[i]);
  return 0;
}