#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int NN = 1e7 + 7;
const long long mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
int G = 1, k;
int a[N];
int b[N];
int lg[N];
int d[N][20];
int L[NN];
int R[NN];
int t[NN];
int lz[NN];
void push(int x) {
  if (lz[x] != 0) {
    lz[L[x]] = lz[R[x]] = lz[x];
    t[L[x]] = t[R[x]] = lz[x];
    lz[x] = 0;
  }
}
int get(int l, int r) {
  if (r - l + 1 >= n) {
    int x = lg[n];
    return min(d[1][x], d[n - (1 << x) + 1][x]);
  }
  int nl = l % n, nr = r % n;
  if (!nl) nl = n;
  if (!nr) nr = n;
  if (nl <= nr) {
    int x = lg[nr - nl + 1];
    return min(d[nl][x], d[nr - (1 << x) + 1][x]);
  } else {
    int x = lg[n - nl + 1];
    int y = lg[nr];
    return min(
        {d[1][y], d[nr - (1 << y) + 1][y], d[nl][x], d[n - (1 << x) + 1][x]});
  }
}
void upd(int x, int l, int r, int tl, int tr, int val) {
  if (tl > tr) return;
  int m = (l + r) / 2;
  if (!L[x]) {
    L[x] = ++G;
    t[G] = get(l, m);
  }
  if (!R[x]) {
    R[x] = ++G;
    t[G] = get(m + 1, r);
  }
  if (l == tl && r == tr) {
    t[x] = val;
    lz[x] = val;
    return;
  }
  push(x);
  upd(L[x], l, m, tl, min(tr, m), val);
  upd(R[x], m + 1, r, max(tl, m + 1), tr, val);
  t[x] = min(t[L[x]], t[R[x]]);
}
int get(int x, int l, int r, int tl, int tr) {
  if (tl > tr) return 1e9;
  if (l == tl && r == tr) {
    return t[x];
  }
  int m = (l + r) / 2;
  if (!L[x]) {
    L[x] = ++G;
    t[G] = get(l, m);
  }
  if (!R[x]) {
    R[x] = ++G;
    t[G] = get(m + 1, r);
  }
  push(x);
  int res = 1e9;
  res = get(L[x], l, m, tl, min(tr, m));
  res = min(res, get(R[x], m + 1, r, max(tl, m + 1), tr));
  return res;
}
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[i][0] = a[i];
  }
  for (int i = 2; i < N; i++) {
    lg[i] = lg[i / 2] + 1;
  }
  for (int it = 1; it < 20; it++) {
    for (int i = 1; i + (1 << it) - 1 <= n; i++) {
      d[i][it] = min(d[i][it - 1], d[i + (1 << it - 1)][it - 1]);
    }
  }
  t[1] = get(1, n * k);
  cin >> q;
  while (q--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      upd(1, 1, n * k, l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << get(1, 1, n * k, l, r) << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int T = 1;
  while (T--) {
    solve();
  }
}

### Prompt

Develop a solution in Cpp to the problem described below:

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;
const int N = 1e5 + 7;
const int NN = 1e7 + 7;
const long long mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
int G = 1, k;
int a[N];
int b[N];
int lg[N];
int d[N][20];
int L[NN];
int R[NN];
int t[NN];
int lz[NN];
void push(int x) {
  if (lz[x] != 0) {
    lz[L[x]] = lz[R[x]] = lz[x];
    t[L[x]] = t[R[x]] = lz[x];
    lz[x] = 0;
  }
}
int get(int l, int r) {
  if (r - l + 1 >= n) {
    int x = lg[n];
    return min(d[1][x], d[n - (1 << x) + 1][x]);
  }
  int nl = l % n, nr = r % n;
  if (!nl) nl = n;
  if (!nr) nr = n;
  if (nl <= nr) {
    int x = lg[nr - nl + 1];
    return min(d[nl][x], d[nr - (1 << x) + 1][x]);
  } else {
    int x = lg[n - nl + 1];
    int y = lg[nr];
    return min(
        {d[1][y], d[nr - (1 << y) + 1][y], d[nl][x], d[n - (1 << x) + 1][x]});
  }
}
void upd(int x, int l, int r, int tl, int tr, int val) {
  if (tl > tr) return;
  int m = (l + r) / 2;
  if (!L[x]) {
    L[x] = ++G;
    t[G] = get(l, m);
  }
  if (!R[x]) {
    R[x] = ++G;
    t[G] = get(m + 1, r);
  }
  if (l == tl && r == tr) {
    t[x] = val;
    lz[x] = val;
    return;
  }
  push(x);
  upd(L[x], l, m, tl, min(tr, m), val);
  upd(R[x], m + 1, r, max(tl, m + 1), tr, val);
  t[x] = min(t[L[x]], t[R[x]]);
}
int get(int x, int l, int r, int tl, int tr) {
  if (tl > tr) return 1e9;
  if (l == tl && r == tr) {
    return t[x];
  }
  int m = (l + r) / 2;
  if (!L[x]) {
    L[x] = ++G;
    t[G] = get(l, m);
  }
  if (!R[x]) {
    R[x] = ++G;
    t[G] = get(m + 1, r);
  }
  push(x);
  int res = 1e9;
  res = get(L[x], l, m, tl, min(tr, m));
  res = min(res, get(R[x], m + 1, r, max(tl, m + 1), tr));
  return res;
}
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[i][0] = a[i];
  }
  for (int i = 2; i < N; i++) {
    lg[i] = lg[i / 2] + 1;
  }
  for (int it = 1; it < 20; it++) {
    for (int i = 1; i + (1 << it) - 1 <= n; i++) {
      d[i][it] = min(d[i][it - 1], d[i + (1 << it - 1)][it - 1]);
    }
  }
  t[1] = get(1, n * k);
  cin >> q;
  while (q--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      upd(1, 1, n * k, l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << get(1, 1, n * k, l, r) << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int T = 1;
  while (T--) {
    solve();
  }
}

```