#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
inline string to_string(char c) {
  string r = "'";
  return r + c + '\'';
}
inline string to_string(const basic_string<char> &s) { return "\"" + s + "\""; }
template <typename T, typename V>
inline string to_string(const pair<T, V> &p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}
template <typename T>
inline string to_string(const vector<T> &a) {
  string r = "(";
  for (int i = 0; i < a.size(); i++) {
    r += to_string(a[i]);
    r += i + 1 == a.size() ? ")" : ",";
  }
  return r;
}
inline void put_debug() { cerr << "]" << endl; }
template <typename T, typename... V>
inline void put_debug(T t, V... v) {
  cerr << to_string(t);
  sizeof...(v) ? cerr << ", ", put_debug(v...) : put_debug();
}
inline int bit(ll x, int i) { return (x >> i) & 1; }
inline int bits(ll x) { return __builtin_popcountll(x); }
inline int next_int() { return abs(rand() + (rand() << 15)); }
inline bool YES(bool x) {
  cout << (x ? "YES\n" : "NO\n");
  return x;
}
inline bool Yes(bool x) {
  cout << (x ? "Yes\n" : "No\n");
  return x;
}
inline bool yes(bool x) {
  cout << (x ? "yes\n" : "no\n");
  return x;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
const double PI = acos(-1);
inline ll powr(ll a, ll x, ll p = MOD) {
  ll r = 1;
  for (; x; x >>= 1) {
    if (x & 1) r = r * a % p;
    a = a * a % p;
  }
  return r;
}
inline ll lmul(ll a, ll b, ll p = MOD) {
  ll r = 0;
  for (; b; b >>= 1) {
    if (b & 1) r = (r + a) % p;
    a = (a + a) % p;
  }
  return r;
}
inline ll inv(ll a, ll p = MOD) { return powr(a % p, p - 2, p); }
template <typename T>
inline void mul(T &a, ll b, ll p = MOD) {
  a = a * b % p;
}
template <typename T>
inline void add(T &a, ll b, ll p = MOD) {
  a = (a + b) % p;
}
template <typename T>
inline void sub(T &a, ll b, ll p = MOD) {
  a = (a - b) % p;
  if (a < 0) a += p;
}
template <typename T>
inline T lcm(T a, T b) {
  return a / __gcd(a, b) * b;
}
template <typename T>
inline T toggle(T x, int i) {
  return x ^ (1ll << i);
}
template <typename T>
inline bool tomax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
inline bool tomin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T, class V>
bool contain(const T &x, const V &y) {
  return x.find(y) != x.end();
}
const int LIN = 2e5 + 8;
int pos[LIN], b[LIN];
int n, m;
int s_buf, s_sz;
struct node {
  int sum;
  node *l, *r;
  node() {
    sum = 0;
    l = r = NULL;
  }
  ~node() {
    if (l) delete l;
    if (r) delete r;
  }
};
vector<pair<int, int> > p(1);
vector<node *> t(1);
int id(int i) { return (i + s_buf - 1) / s_buf; }
void update(node *&t, int l, int r, int i, int v) {
  if (l > i || r < i) return;
  if (t == NULL) t = new node();
  if (l == r) {
    t->sum += v;
    return;
  }
  if (l < r) {
    int m = (l + r) >> 1;
    update(t->l, l, m, i, v);
    update(t->r, m + 1, r, i, v);
    t->sum = t->l ? t->l->sum : 0;
    t->sum += t->r ? t->r->sum : 0;
  }
}
int get(node *&t, int l, int r, int x, int y) {
  if (t == NULL || l > y || r < x) return 0;
  if (l >= x && r <= y) return t->sum;
  int m = (l + r) >> 1;
  return get(t->l, l, m, x, y) + get(t->r, m + 1, r, x, y);
}
int get(int x, int y, int l, int r) {
  int u = id(l);
  int v = id(r);
  int res = 0;
  if (u == v) {
    for (int i = l; i <= r; i++) {
      res += (int)(b[i] >= x && b[i] <= y);
    }
  } else {
    for (int i = u + 1; i <= v - 1; i++) {
      res += get(t[i], 1, n, x, y);
    }
    for (int i = l; i <= min(n, u * s_buf); i++) {
      res += (int)(b[i] >= x && b[i] <= y);
    }
    for (int i = (v - 1) * s_buf + 1; i <= r; i++) {
      res += (int)(b[i] >= x && b[i] <= y);
    }
  }
  return res;
}
void solve(int test_number) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    pos[a] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    b[i] = pos[b[i]];
  }
  s_buf = 8 * sqrt(n);
  s_sz = id(n);
  for (int i = 1; i <= s_sz; i++) {
    node *tmp = new node();
    for (int j = (i - 1) * s_buf + 1; j <= min(n, i * s_buf); j++) {
      update(tmp, 1, n, b[j], 1);
    }
    t.push_back(tmp);
  }
  for (int i = 1; i <= m; i++) {
    int tp;
    scanf("%d", &tp);
    if (tp == 1) {
      int la, ra, lb, rb;
      scanf("%d %d %d %d", &la, &ra, &lb, &rb);
      printf("%d\n", get(la, ra, lb, rb));
    } else {
      int x, y;
      scanf("%d %d", &x, &y);
      update(t[id(x)], 1, n, b[x], -1);
      update(t[id(y)], 1, n, b[y], -1);
      swap(b[x], b[y]);
      update(t[id(x)], 1, n, b[x], 1);
      update(t[id(y)], 1, n, b[y], 1);
    }
  }
  t.clear();
}
void solve() {
  int test = 1;
  for (int i = 1; i <= test; i++) {
    solve(i);
  }
}
int main(int argc, char *argv[]) {
  if (argc > 1) {
    freopen("E:/C++/cp/.inp", "r", stdin);
    freopen("E:/C++/cp/.out", "w", stdout);
  }
  srand(time(NULL));
  solve();
  return 0;
}

### Prompt

In cpp, your task is to solve the following problem:

You are given two permutations a and b, both consisting of n elements. Permutation of n elements is such a integer sequence that each value from 1 to n appears exactly once in it.

You are asked to perform two types of queries with them:

  * 1~l_a~r_a~l_b~r_b — calculate the number of values which appear in both segment [l_a; r_a] of positions in permutation a and segment [l_b; r_b] of positions in permutation b; 
  * 2~x~y — swap values on positions x and y in permutation b. 



Print the answer for each query of the first type.

It is guaranteed that there will be at least one query of the first type in the input.

Input

The first line contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the number of elements in both permutations and the number of queries.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — permutation a. It is guaranteed that each value from 1 to n appears in a exactly once.

The third line contains n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ n) — permutation b. It is guaranteed that each value from 1 to n appears in b exactly once.

Each of the next m lines contains the description of a certain query. These are either:

  * 1~l_a~r_a~l_b~r_b (1 ≤ l_a ≤ r_a ≤ n, 1 ≤ l_b ≤ r_b ≤ n); 
  * 2~x~y (1 ≤ x, y ≤ n, x ≠ y). 

Output

Print the answers for the queries of the first type, each answer in the new line — the number of values which appear in both segment [l_a; r_a] of positions in permutation a and segment [l_b; r_b] of positions in permutation b.

Example

Input


6 7
5 1 4 2 3 6
2 5 3 1 4 6
1 1 2 4 5
2 2 4
1 1 2 4 5
1 2 3 3 5
1 1 6 1 2
2 4 1
1 4 4 1 3


Output


1
1
1
2
0

Note

Consider the first query of the first example. Values on positions [1; 2] of a are [5, 1] and values on positions [4; 5] of b are [1, 4]. Only value 1 appears in both segments.

After the first swap (the second query) permutation b becomes [2, 1, 3, 5, 4, 6].

After the second swap (the sixth query) permutation b becomes [5, 1, 3, 2, 4, 6].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
inline string to_string(char c) {
  string r = "'";
  return r + c + '\'';
}
inline string to_string(const basic_string<char> &s) { return "\"" + s + "\""; }
template <typename T, typename V>
inline string to_string(const pair<T, V> &p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}
template <typename T>
inline string to_string(const vector<T> &a) {
  string r = "(";
  for (int i = 0; i < a.size(); i++) {
    r += to_string(a[i]);
    r += i + 1 == a.size() ? ")" : ",";
  }
  return r;
}
inline void put_debug() { cerr << "]" << endl; }
template <typename T, typename... V>
inline void put_debug(T t, V... v) {
  cerr << to_string(t);
  sizeof...(v) ? cerr << ", ", put_debug(v...) : put_debug();
}
inline int bit(ll x, int i) { return (x >> i) & 1; }
inline int bits(ll x) { return __builtin_popcountll(x); }
inline int next_int() { return abs(rand() + (rand() << 15)); }
inline bool YES(bool x) {
  cout << (x ? "YES\n" : "NO\n");
  return x;
}
inline bool Yes(bool x) {
  cout << (x ? "Yes\n" : "No\n");
  return x;
}
inline bool yes(bool x) {
  cout << (x ? "yes\n" : "no\n");
  return x;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
const double PI = acos(-1);
inline ll powr(ll a, ll x, ll p = MOD) {
  ll r = 1;
  for (; x; x >>= 1) {
    if (x & 1) r = r * a % p;
    a = a * a % p;
  }
  return r;
}
inline ll lmul(ll a, ll b, ll p = MOD) {
  ll r = 0;
  for (; b; b >>= 1) {
    if (b & 1) r = (r + a) % p;
    a = (a + a) % p;
  }
  return r;
}
inline ll inv(ll a, ll p = MOD) { return powr(a % p, p - 2, p); }
template <typename T>
inline void mul(T &a, ll b, ll p = MOD) {
  a = a * b % p;
}
template <typename T>
inline void add(T &a, ll b, ll p = MOD) {
  a = (a + b) % p;
}
template <typename T>
inline void sub(T &a, ll b, ll p = MOD) {
  a = (a - b) % p;
  if (a < 0) a += p;
}
template <typename T>
inline T lcm(T a, T b) {
  return a / __gcd(a, b) * b;
}
template <typename T>
inline T toggle(T x, int i) {
  return x ^ (1ll << i);
}
template <typename T>
inline bool tomax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
inline bool tomin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T, class V>
bool contain(const T &x, const V &y) {
  return x.find(y) != x.end();
}
const int LIN = 2e5 + 8;
int pos[LIN], b[LIN];
int n, m;
int s_buf, s_sz;
struct node {
  int sum;
  node *l, *r;
  node() {
    sum = 0;
    l = r = NULL;
  }
  ~node() {
    if (l) delete l;
    if (r) delete r;
  }
};
vector<pair<int, int> > p(1);
vector<node *> t(1);
int id(int i) { return (i + s_buf - 1) / s_buf; }
void update(node *&t, int l, int r, int i, int v) {
  if (l > i || r < i) return;
  if (t == NULL) t = new node();
  if (l == r) {
    t->sum += v;
    return;
  }
  if (l < r) {
    int m = (l + r) >> 1;
    update(t->l, l, m, i, v);
    update(t->r, m + 1, r, i, v);
    t->sum = t->l ? t->l->sum : 0;
    t->sum += t->r ? t->r->sum : 0;
  }
}
int get(node *&t, int l, int r, int x, int y) {
  if (t == NULL || l > y || r < x) return 0;
  if (l >= x && r <= y) return t->sum;
  int m = (l + r) >> 1;
  return get(t->l, l, m, x, y) + get(t->r, m + 1, r, x, y);
}
int get(int x, int y, int l, int r) {
  int u = id(l);
  int v = id(r);
  int res = 0;
  if (u == v) {
    for (int i = l; i <= r; i++) {
      res += (int)(b[i] >= x && b[i] <= y);
    }
  } else {
    for (int i = u + 1; i <= v - 1; i++) {
      res += get(t[i], 1, n, x, y);
    }
    for (int i = l; i <= min(n, u * s_buf); i++) {
      res += (int)(b[i] >= x && b[i] <= y);
    }
    for (int i = (v - 1) * s_buf + 1; i <= r; i++) {
      res += (int)(b[i] >= x && b[i] <= y);
    }
  }
  return res;
}
void solve(int test_number) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    pos[a] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    b[i] = pos[b[i]];
  }
  s_buf = 8 * sqrt(n);
  s_sz = id(n);
  for (int i = 1; i <= s_sz; i++) {
    node *tmp = new node();
    for (int j = (i - 1) * s_buf + 1; j <= min(n, i * s_buf); j++) {
      update(tmp, 1, n, b[j], 1);
    }
    t.push_back(tmp);
  }
  for (int i = 1; i <= m; i++) {
    int tp;
    scanf("%d", &tp);
    if (tp == 1) {
      int la, ra, lb, rb;
      scanf("%d %d %d %d", &la, &ra, &lb, &rb);
      printf("%d\n", get(la, ra, lb, rb));
    } else {
      int x, y;
      scanf("%d %d", &x, &y);
      update(t[id(x)], 1, n, b[x], -1);
      update(t[id(y)], 1, n, b[y], -1);
      swap(b[x], b[y]);
      update(t[id(x)], 1, n, b[x], 1);
      update(t[id(y)], 1, n, b[y], 1);
    }
  }
  t.clear();
}
void solve() {
  int test = 1;
  for (int i = 1; i <= test; i++) {
    solve(i);
  }
}
int main(int argc, char *argv[]) {
  if (argc > 1) {
    freopen("E:/C++/cp/.inp", "r", stdin);
    freopen("E:/C++/cp/.out", "w", stdout);
  }
  srand(time(NULL));
  solve();
  return 0;
}

```