#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int n, k, q;
int a[maxn];
int lg2[maxn];
int mn[maxn][20];
void RMQ_init() {
  lg2[1] = 0;
  for (int i = 2; i <= n; i++) {
    if ((i & (i - 1)) == 0)
      lg2[i] = lg2[i - 1] + 1;
    else
      lg2[i] = lg2[i - 1];
  }
  for (int i = 1; i <= n; i++) mn[i][0] = a[i];
  for (int i = 1; i <= lg2[n]; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      mn[j][i] = min(mn[j][i - 1], mn[j + (1 << (i - 1))][i - 1]);
    }
  }
}
int ask(int l, int r) {
  int k = lg2[r - l + 1];
  return min(mn[l][k], mn[r - (1 << k) + 1][k]);
}
int ls[maxn * 50], rs[maxn * 50], v[maxn * 50], cnt, root;
int lazy[maxn * 50];
int getmn(int l, int r) {
  if (r - l + 1 >= n) return ask(1, n);
  l = (l - 1) % n + 1;
  r = (r - 1) % n + 1;
  if (l <= r) return ask(l, r);
  return min(ask(1, r), ask(l, n));
}
int newnode(int l, int r) {
  ++cnt;
  ls[cnt] = rs[cnt] = 0;
  lazy[cnt] = -1;
  v[cnt] = getmn(l, r);
  return cnt;
}
void push_down(int x) {
  if (!ls[x]) ls[x] = newnode(1, 1);
  if (!rs[x]) rs[x] = newnode(1, 1);
  v[ls[x]] = v[rs[x]] = lazy[x];
  lazy[ls[x]] = lazy[rs[x]] = lazy[x];
  lazy[x] = -1;
}
void modify(int &x, int L, int R, int l, int r, int c) {
  if (!x) x = newnode(L, R);
  if (l <= L && R <= r) {
    lazy[x] = v[x] = c;
    return;
  }
  if (lazy[x] != -1) {
    push_down(x);
  }
  int mid = (L + R) >> 1;
  if (l <= mid) modify(ls[x], L, mid, l, r, c);
  if (r > mid) modify(rs[x], mid + 1, R, l, r, c);
  v[x] = inf;
  if (ls[x])
    v[x] = min(v[x], v[ls[x]]);
  else
    v[x] = min(v[x], getmn(L, mid));
  if (rs[x])
    v[x] = min(v[x], v[rs[x]]);
  else
    v[x] = min(v[x], getmn(mid + 1, R));
}
int qry(int &x, int L, int R, int l, int r) {
  if (!x) x = newnode(L, R);
  if (l <= L && R <= r) return v[x];
  if (lazy[x] != -1) push_down(x);
  int mid = (L + R) >> 1;
  int ans = inf;
  if (l <= mid) ans = min(ans, qry(ls[x], L, mid, l, r));
  if (r > mid) ans = min(ans, qry(rs[x], mid + 1, R, l, r));
  return ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  root = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  RMQ_init();
  cin >> q;
  while (q--) {
    int op, l, r, x;
    cin >> op >> l >> r;
    if (op == 1) {
      cin >> x;
      modify(root, 1, k * n, l, r, x);
    } else {
      cout << qry(root, 1, k * n, l, r) << endl;
    }
  }
  return 0;
}

### Prompt

Please create a solution in CPP to the following problem:

You are given an array a consisting of positive integers and q queries to this array. There are two types of queries: 

  * 1 l r x — for each index i such that l ≤ i ≤ r set ai = x. 
  * 2 l r — find the minimum among such ai that l ≤ i ≤ r. 



We decided that this problem is too easy. So the array a is given in a compressed form: there is an array b consisting of n elements and a number k in the input, and before all queries a is equal to the concatenation of k arrays b (so the size of a is n·k).

Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104).

The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109).

The third line contains one integer q (1 ≤ q ≤ 105).

Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the segment from l till r (including borders) to x (1 ≤ l ≤ r ≤ n·k, 1 ≤ x ≤ 109) or as 2 l r — find the minimum among all elements in the segment from l till r (1 ≤ l ≤ r ≤ n·k).

Output

For each query of type 2 print the answer to this query — the minimum on the corresponding segment.

Examples

Input

3 1
1 2 3
3
2 1 3
1 1 2 4
2 1 3


Output

1
3


Input

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


Output

1
5
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int n, k, q;
int a[maxn];
int lg2[maxn];
int mn[maxn][20];
void RMQ_init() {
  lg2[1] = 0;
  for (int i = 2; i <= n; i++) {
    if ((i & (i - 1)) == 0)
      lg2[i] = lg2[i - 1] + 1;
    else
      lg2[i] = lg2[i - 1];
  }
  for (int i = 1; i <= n; i++) mn[i][0] = a[i];
  for (int i = 1; i <= lg2[n]; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      mn[j][i] = min(mn[j][i - 1], mn[j + (1 << (i - 1))][i - 1]);
    }
  }
}
int ask(int l, int r) {
  int k = lg2[r - l + 1];
  return min(mn[l][k], mn[r - (1 << k) + 1][k]);
}
int ls[maxn * 50], rs[maxn * 50], v[maxn * 50], cnt, root;
int lazy[maxn * 50];
int getmn(int l, int r) {
  if (r - l + 1 >= n) return ask(1, n);
  l = (l - 1) % n + 1;
  r = (r - 1) % n + 1;
  if (l <= r) return ask(l, r);
  return min(ask(1, r), ask(l, n));
}
int newnode(int l, int r) {
  ++cnt;
  ls[cnt] = rs[cnt] = 0;
  lazy[cnt] = -1;
  v[cnt] = getmn(l, r);
  return cnt;
}
void push_down(int x) {
  if (!ls[x]) ls[x] = newnode(1, 1);
  if (!rs[x]) rs[x] = newnode(1, 1);
  v[ls[x]] = v[rs[x]] = lazy[x];
  lazy[ls[x]] = lazy[rs[x]] = lazy[x];
  lazy[x] = -1;
}
void modify(int &x, int L, int R, int l, int r, int c) {
  if (!x) x = newnode(L, R);
  if (l <= L && R <= r) {
    lazy[x] = v[x] = c;
    return;
  }
  if (lazy[x] != -1) {
    push_down(x);
  }
  int mid = (L + R) >> 1;
  if (l <= mid) modify(ls[x], L, mid, l, r, c);
  if (r > mid) modify(rs[x], mid + 1, R, l, r, c);
  v[x] = inf;
  if (ls[x])
    v[x] = min(v[x], v[ls[x]]);
  else
    v[x] = min(v[x], getmn(L, mid));
  if (rs[x])
    v[x] = min(v[x], v[rs[x]]);
  else
    v[x] = min(v[x], getmn(mid + 1, R));
}
int qry(int &x, int L, int R, int l, int r) {
  if (!x) x = newnode(L, R);
  if (l <= L && R <= r) return v[x];
  if (lazy[x] != -1) push_down(x);
  int mid = (L + R) >> 1;
  int ans = inf;
  if (l <= mid) ans = min(ans, qry(ls[x], L, mid, l, r));
  if (r > mid) ans = min(ans, qry(rs[x], mid + 1, R, l, r));
  return ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  root = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  RMQ_init();
  cin >> q;
  while (q--) {
    int op, l, r, x;
    cin >> op >> l >> r;
    if (op == 1) {
      cin >> x;
      modify(root, 1, k * n, l, r, x);
    } else {
      cout << qry(root, 1, k * n, l, r) << endl;
    }
  }
  return 0;
}

```