#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int inf = 1e9 + 2277;
class Query {
 public:
  int l, r, type, val;
  Query(int l, int r, int type, int val) {
    this->l = l;
    this->r = r;
    this->type = type;
    this->val = val;
  }
};
int n, k, a[N], rmq[N][20], node[4 * N], lazy[4 * N], q;
vector<int> indices;
vector<Query> queries;
void input() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  indices.push_back(0);
  indices.push_back(1);
  indices.push_back(n * k + 1);
  while (q--) {
    int type, l, r, x;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d %d", &l, &r, &x);
      queries.push_back(Query(l, r, type, x));
    } else {
      scanf("%d %d", &l, &r);
      queries.push_back(Query(l, r, type, 0));
    }
    indices.push_back(l);
    indices.push_back(r + 1);
  }
}
void prep() {
  for (int i = 1; i <= n; i++) rmq[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int get(int u, int v) {
  int LG = log2(v - u + 1);
  return min(rmq[u][LG], rmq[v - (1 << LG) + 1][LG]);
}
void build_tree(int i, int l, int r) {
  if (l > r) return;
  if (l == r) {
    lazy[i] = 0;
    int left = indices[l];
    int right = indices[r + 1] - 1;
    int nxt_left = (left + n - 1) / n;
    int nxt_right = (right + n - 1) / n;
    left = (left % n == 0 ? n : left % n);
    right = (right % n == 0 ? n : right % n);
    if (nxt_right - nxt_left > 1)
      node[i] = get(1, n);
    else if (nxt_right - nxt_left == 1)
      node[i] = min(get(1, right), get(left, n));
    else
      node[i] = get(left, right);
    return;
  }
  lazy[i] = 0;
  int m = (l + r) >> 1;
  build_tree(i << 1, l, m);
  build_tree(i << 1 | 1, m + 1, r);
  node[i] = min(node[i << 1], node[i << 1 | 1]);
}
void dolazy(int i, int l, int r) {
  if (lazy[i]) {
    node[i] = lazy[i];
    if (l != r) {
      lazy[i << 1] = lazy[i];
      lazy[i << 1 | 1] = lazy[i];
    }
    lazy[i] = 0;
  }
}
void update(int i, int l, int r, int a, int b, int val) {
  dolazy(i, l, r);
  if (l > r || a > r || b < l) return;
  if (a <= l && r <= b) {
    node[i] = val;
    if (l != r) {
      lazy[i << 1] = val;
      lazy[i << 1 | 1] = val;
    }
    return;
  }
  int m = (l + r) >> 1;
  update(i << 1, l, m, a, b, val);
  update(i << 1 | 1, m + 1, r, a, b, val);
  node[i] = min(node[i << 1], node[i << 1 | 1]);
}
int query(int i, int l, int r, int a, int b) {
  if (l > r || a > r || b < l) return inf;
  dolazy(i, l, r);
  if (a <= l && r <= b) return node[i];
  int m = (l + r) >> 1;
  return min(query(i << 1, l, m, a, b), query(i << 1 | 1, m + 1, r, a, b));
}
void solve() {
  sort(indices.begin(), indices.end());
  indices.resize(unique(indices.begin(), indices.end()) - indices.begin());
  build_tree(1, 1, (int)indices.size() - 2);
  for (int i = 0; i < queries.size(); i++) {
    int a = lower_bound(indices.begin(), indices.end(), queries[i].l) -
            indices.begin();
    int b = upper_bound(indices.begin(), indices.end(), queries[i].r) -
            indices.begin() - 1;
    if (queries[i].type == 1)
      update(1, 1, (int)indices.size() - 2, a, b, queries[i].val);
    else
      printf("%d\n", query(1, 1, (int)indices.size() - 2, a, b));
  }
}
int main() {
  input();
  prep();
  solve();
  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;
const int N = 2e5 + 5;
const int inf = 1e9 + 2277;
class Query {
 public:
  int l, r, type, val;
  Query(int l, int r, int type, int val) {
    this->l = l;
    this->r = r;
    this->type = type;
    this->val = val;
  }
};
int n, k, a[N], rmq[N][20], node[4 * N], lazy[4 * N], q;
vector<int> indices;
vector<Query> queries;
void input() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  indices.push_back(0);
  indices.push_back(1);
  indices.push_back(n * k + 1);
  while (q--) {
    int type, l, r, x;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d %d", &l, &r, &x);
      queries.push_back(Query(l, r, type, x));
    } else {
      scanf("%d %d", &l, &r);
      queries.push_back(Query(l, r, type, 0));
    }
    indices.push_back(l);
    indices.push_back(r + 1);
  }
}
void prep() {
  for (int i = 1; i <= n; i++) rmq[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int get(int u, int v) {
  int LG = log2(v - u + 1);
  return min(rmq[u][LG], rmq[v - (1 << LG) + 1][LG]);
}
void build_tree(int i, int l, int r) {
  if (l > r) return;
  if (l == r) {
    lazy[i] = 0;
    int left = indices[l];
    int right = indices[r + 1] - 1;
    int nxt_left = (left + n - 1) / n;
    int nxt_right = (right + n - 1) / n;
    left = (left % n == 0 ? n : left % n);
    right = (right % n == 0 ? n : right % n);
    if (nxt_right - nxt_left > 1)
      node[i] = get(1, n);
    else if (nxt_right - nxt_left == 1)
      node[i] = min(get(1, right), get(left, n));
    else
      node[i] = get(left, right);
    return;
  }
  lazy[i] = 0;
  int m = (l + r) >> 1;
  build_tree(i << 1, l, m);
  build_tree(i << 1 | 1, m + 1, r);
  node[i] = min(node[i << 1], node[i << 1 | 1]);
}
void dolazy(int i, int l, int r) {
  if (lazy[i]) {
    node[i] = lazy[i];
    if (l != r) {
      lazy[i << 1] = lazy[i];
      lazy[i << 1 | 1] = lazy[i];
    }
    lazy[i] = 0;
  }
}
void update(int i, int l, int r, int a, int b, int val) {
  dolazy(i, l, r);
  if (l > r || a > r || b < l) return;
  if (a <= l && r <= b) {
    node[i] = val;
    if (l != r) {
      lazy[i << 1] = val;
      lazy[i << 1 | 1] = val;
    }
    return;
  }
  int m = (l + r) >> 1;
  update(i << 1, l, m, a, b, val);
  update(i << 1 | 1, m + 1, r, a, b, val);
  node[i] = min(node[i << 1], node[i << 1 | 1]);
}
int query(int i, int l, int r, int a, int b) {
  if (l > r || a > r || b < l) return inf;
  dolazy(i, l, r);
  if (a <= l && r <= b) return node[i];
  int m = (l + r) >> 1;
  return min(query(i << 1, l, m, a, b), query(i << 1 | 1, m + 1, r, a, b));
}
void solve() {
  sort(indices.begin(), indices.end());
  indices.resize(unique(indices.begin(), indices.end()) - indices.begin());
  build_tree(1, 1, (int)indices.size() - 2);
  for (int i = 0; i < queries.size(); i++) {
    int a = lower_bound(indices.begin(), indices.end(), queries[i].l) -
            indices.begin();
    int b = upper_bound(indices.begin(), indices.end(), queries[i].r) -
            indices.begin() - 1;
    if (queries[i].type == 1)
      update(1, 1, (int)indices.size() - 2, a, b, queries[i].val);
    else
      printf("%d\n", query(1, 1, (int)indices.size() - 2, a, b));
  }
}
int main() {
  input();
  prep();
  solve();
  return 0;
}

```