#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int maxn = 1e5 + 10;
const int maxm = (maxn << 7);
const long long mod = 1e9 + 7;
int n, m, k, cnt = 1;
int lg[maxn], a[maxn], dp[maxn][32];
int mn[maxm], lazy[maxm], ls[maxm], rs[maxm];
int rmq_query(int l, int r) {
  int len = lg[r - l + 1];
  return min(dp[l][len], dp[r - (1 << len) + 1][len]);
}
void init() {
  lg[0] = -1;
  for (int i = 1; i <= n; ++i) lg[i] = lg[i / 2] + 1, dp[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
    }
  }
  mn[1] = rmq_query(1, n);
}
int query(int l, int r) {
  if (r - l + 1 >= n)
    return rmq_query(1, n);
  else {
    l = (l - 1) % n + 1;
    r = (r - 1) % n + 1;
    if (l <= r)
      return rmq_query(l, r);
    else
      return min(rmq_query(1, r), rmq_query(l, n));
  }
}
void pushdown(int p, int l, int r) {
  if (!ls[p]) ls[p] = ++cnt;
  if (!rs[p]) rs[p] = ++cnt;
  if (~lazy[p]) {
    int mid = (l + r) >> 1;
    lazy[ls[p]] = lazy[rs[p]] = lazy[p];
    mn[ls[p]] = lazy[ls[p]] ? lazy[ls[p]] : query(l, mid);
    mn[rs[p]] = lazy[rs[p]] ? lazy[rs[p]] : query(mid + 1, r);
    return;
  }
}
void update(int p, int l, int r, int L, int R, int x) {
  if (L <= l && r <= R) {
    mn[p] = lazy[p] = x;
    return;
  }
  pushdown(p, l, r);
  lazy[p] = -1;
  int mid = (l + r) >> 1;
  if (L <= mid) update(ls[p], l, mid, L, R, x);
  if (R > mid) update(rs[p], mid + 1, r, L, R, x);
  mn[p] = min(mn[ls[p]], mn[rs[p]]);
}
int seg_query(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return mn[p];
  pushdown(p, l, r);
  lazy[p] = -1;
  int mid = (l + r) >> 1;
  int ans = 1e9;
  if (L <= mid) ans = min(ans, seg_query(ls[p], l, mid, L, R));
  if (R > mid) ans = min(ans, seg_query(rs[p], mid + 1, r, L, R));
  return ans;
}
int main() {
  int op, l, r, x;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  init();
  scanf("%d", &m);
  while (m--) {
    scanf("%d %d %d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &x);
      update(1, 1, n * k, l, r, x);
    }
    if (op == 2) {
      cout << seg_query(1, 1, n * k, l, r) << '\n';
    }
  }
  return 0;
}

### Prompt

Please provide a cpp coded solution 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 double pi = acos(-1);
const int maxn = 1e5 + 10;
const int maxm = (maxn << 7);
const long long mod = 1e9 + 7;
int n, m, k, cnt = 1;
int lg[maxn], a[maxn], dp[maxn][32];
int mn[maxm], lazy[maxm], ls[maxm], rs[maxm];
int rmq_query(int l, int r) {
  int len = lg[r - l + 1];
  return min(dp[l][len], dp[r - (1 << len) + 1][len]);
}
void init() {
  lg[0] = -1;
  for (int i = 1; i <= n; ++i) lg[i] = lg[i / 2] + 1, dp[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
    }
  }
  mn[1] = rmq_query(1, n);
}
int query(int l, int r) {
  if (r - l + 1 >= n)
    return rmq_query(1, n);
  else {
    l = (l - 1) % n + 1;
    r = (r - 1) % n + 1;
    if (l <= r)
      return rmq_query(l, r);
    else
      return min(rmq_query(1, r), rmq_query(l, n));
  }
}
void pushdown(int p, int l, int r) {
  if (!ls[p]) ls[p] = ++cnt;
  if (!rs[p]) rs[p] = ++cnt;
  if (~lazy[p]) {
    int mid = (l + r) >> 1;
    lazy[ls[p]] = lazy[rs[p]] = lazy[p];
    mn[ls[p]] = lazy[ls[p]] ? lazy[ls[p]] : query(l, mid);
    mn[rs[p]] = lazy[rs[p]] ? lazy[rs[p]] : query(mid + 1, r);
    return;
  }
}
void update(int p, int l, int r, int L, int R, int x) {
  if (L <= l && r <= R) {
    mn[p] = lazy[p] = x;
    return;
  }
  pushdown(p, l, r);
  lazy[p] = -1;
  int mid = (l + r) >> 1;
  if (L <= mid) update(ls[p], l, mid, L, R, x);
  if (R > mid) update(rs[p], mid + 1, r, L, R, x);
  mn[p] = min(mn[ls[p]], mn[rs[p]]);
}
int seg_query(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) return mn[p];
  pushdown(p, l, r);
  lazy[p] = -1;
  int mid = (l + r) >> 1;
  int ans = 1e9;
  if (L <= mid) ans = min(ans, seg_query(ls[p], l, mid, L, R));
  if (R > mid) ans = min(ans, seg_query(rs[p], mid + 1, r, L, R));
  return ans;
}
int main() {
  int op, l, r, x;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  init();
  scanf("%d", &m);
  while (m--) {
    scanf("%d %d %d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &x);
      update(1, 1, n * k, l, r, x);
    }
    if (op == 2) {
      cout << seg_query(1, 1, n * k, l, r) << '\n';
    }
  }
  return 0;
}

```