#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3", "omit-frame-pointer", "inline")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
const long long mod = 1000000007;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
const int mxN = 100010;
int b[mxN];
int org[mxN << 2];
int N, K;
void build(int n = 1, int l = 0, int r = N - 1) {
  if (l == r) {
    org[n] = b[l];
    return;
  }
  int md = (l + r) >> 1;
  build(n << 1, l, md);
  build(n << 1 | 1, md + 1, r);
  org[n] = min(org[n << 1], org[n << 1 | 1]);
}
struct node {
  int val = 0, lz = 0;
  node *left, *right;
  node() { left = nullptr, right = nullptr; }
  node(int x) { val = lz = x, left = nullptr, right = nullptr; }
  void prop(int l, int r) {
    if (!lz || l == r) return;
    if (left == nullptr)
      left = new node(lz);
    else
      left->val = left->lz = lz;
    if (right == nullptr)
      right = new node(lz);
    else
      right->val = right->lz = lz;
    lz = 0;
  }
  void upd(int a, int b, int x, int n = 1, int l = 0, int r = N - 1) {
    prop(l, r);
    if (l == a && b == r) {
      val = lz = x;
      return;
    }
    int md = (l + r) >> 1;
    if (left == nullptr) left = new node(), left->val = org[n << 1];
    if (right == nullptr) right = new node(), right->val = org[n << 1 | 1];
    if (a <= md) left->upd(a, min(b, md), x, n << 1, l, md);
    if (b > md) right->upd(max(a, md + 1), b, x, n << 1 | 1, md + 1, r);
    val = min(left->val, right->val);
  }
  int get(int a, int b, int n = 1, int l = 0, int r = N - 1) {
    if (lz) return lz;
    prop(l, r);
    if (l == a && r == b) {
      return val;
    }
    int md = (l + r) >> 1;
    int res = INT_MAX;
    if (a <= md) {
      if (left == nullptr) left = new node(), left->val = org[n << 1];
      res = left->get(a, min(b, md), n << 1, l, md);
    }
    if (b > md) {
      if (right == nullptr) right = new node(), right->val = org[n << 1 | 1];
      res = min(res, right->get(max(a, md + 1), b, n << 1 | 1, md + 1, r));
    }
    return res;
  }
} roots[mxN];
int tree[mxN << 2];
int lz[mxN << 2];
void prop(int n, int l, int r) {
  if (!lz[n]) return;
  if (l == r) {
    roots[l] = node(lz[n]);
    lz[n] = 0;
    return;
  }
  tree[n << 1] = lz[n << 1] = lz[n];
  tree[n << 1 | 1] = lz[n << 1 | 1] = lz[n];
  lz[n] = 0;
}
void upd(int a, int b, int val, int n = 1, int l = 0, int r = K - 1) {
  prop(n, l, r);
  if (l == a && b == r) {
    tree[n] = lz[n] = val;
    return;
  }
  int md = (l + r) >> 1;
  if (a <= md) upd(a, min(b, md), val, n << 1, l, md);
  if (b > md) upd(max(a, md + 1), b, val, n << 1 | 1, md + 1, r);
  tree[n] = min(tree[n << 1], tree[n << 1 | 1]);
}
void dfs_upd(int a, int b, int idx, int val, int n = 1, int l = 0,
             int r = K - 1) {
  prop(n, l, r);
  if (l == r) {
    assert(l == idx);
    roots[l].upd(a, b, val);
    tree[n] = roots[l].val;
    return;
  }
  int md = (l + r) >> 1;
  if (idx <= md)
    dfs_upd(a, b, idx, val, n << 1, l, md);
  else
    dfs_upd(a, b, idx, val, n << 1 | 1, md + 1, r);
  tree[n] = min(tree[n << 1], tree[n << 1 | 1]);
}
int get(int a, int b, int n = 1, int l = 0, int r = K - 1) {
  prop(n, l, r);
  if (l == a && r == b) {
    return tree[n];
  }
  int md = (l + r) >> 1;
  int res = INT_MAX;
  if (a <= md) res = get(a, min(b, md), n << 1, l, md);
  if (b > md) res = min(res, get(max(a, md + 1), b, n << 1 | 1, md + 1, r));
  return res;
}
int dfs_get(int a, int b, int idx, int n = 1, int l = 0, int r = K - 1) {
  prop(n, l, r);
  if (l == r) {
    assert(l == idx);
    return roots[l].get(a, b);
  }
  int md = (l + r) >> 1;
  if (idx <= md) return dfs_get(a, b, idx, n << 1, l, md);
  return dfs_get(a, b, idx, n << 1 | 1, md + 1, r);
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(time(NULL));
  cout << fixed << setprecision(9);
  int t = 1;
  while (t--) {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> b[i];
    build();
    int mn = *min_element(b, b + N);
    fill(tree, tree + (mxN << 2), mn);
    for (int i = 0; i < K; i++) roots[i].val = mn;
    int q;
    cin >> q;
    while (q--) {
      int t, l, r, x;
      cin >> t >> l >> r;
      l--, r--;
      int a = (l == 0 ? 0 : (l - 1) / N + 1);
      int b = (r + 1) / N - 1;
      if (t == 1) {
        cin >> x;
        if (a <= b) upd(a, b, x);
        if (l % N) dfs_upd(l % N, min(a * N - 1, r) % N, a - 1, x);
        if ((r + 1) % N) dfs_upd(max(l, (b + 1) * N) % N, r % N, b + 1, x);
      } else {
        int res = INT_MAX;
        if (a <= b) res = get(a, b);
        if (l % N) res = min(res, dfs_get(l % N, min(a * N - 1, r) % N, a - 1));
        if ((r + 1) % N)
          res = min(res, dfs_get(max(l, (b + 1) * N) % N, r % N, b + 1));
        cout << res << '\n';
      }
    }
  }
  return 0;
}

### Prompt

Create a solution in cpp for 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>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3", "omit-frame-pointer", "inline")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
const long long mod = 1000000007;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
const int mxN = 100010;
int b[mxN];
int org[mxN << 2];
int N, K;
void build(int n = 1, int l = 0, int r = N - 1) {
  if (l == r) {
    org[n] = b[l];
    return;
  }
  int md = (l + r) >> 1;
  build(n << 1, l, md);
  build(n << 1 | 1, md + 1, r);
  org[n] = min(org[n << 1], org[n << 1 | 1]);
}
struct node {
  int val = 0, lz = 0;
  node *left, *right;
  node() { left = nullptr, right = nullptr; }
  node(int x) { val = lz = x, left = nullptr, right = nullptr; }
  void prop(int l, int r) {
    if (!lz || l == r) return;
    if (left == nullptr)
      left = new node(lz);
    else
      left->val = left->lz = lz;
    if (right == nullptr)
      right = new node(lz);
    else
      right->val = right->lz = lz;
    lz = 0;
  }
  void upd(int a, int b, int x, int n = 1, int l = 0, int r = N - 1) {
    prop(l, r);
    if (l == a && b == r) {
      val = lz = x;
      return;
    }
    int md = (l + r) >> 1;
    if (left == nullptr) left = new node(), left->val = org[n << 1];
    if (right == nullptr) right = new node(), right->val = org[n << 1 | 1];
    if (a <= md) left->upd(a, min(b, md), x, n << 1, l, md);
    if (b > md) right->upd(max(a, md + 1), b, x, n << 1 | 1, md + 1, r);
    val = min(left->val, right->val);
  }
  int get(int a, int b, int n = 1, int l = 0, int r = N - 1) {
    if (lz) return lz;
    prop(l, r);
    if (l == a && r == b) {
      return val;
    }
    int md = (l + r) >> 1;
    int res = INT_MAX;
    if (a <= md) {
      if (left == nullptr) left = new node(), left->val = org[n << 1];
      res = left->get(a, min(b, md), n << 1, l, md);
    }
    if (b > md) {
      if (right == nullptr) right = new node(), right->val = org[n << 1 | 1];
      res = min(res, right->get(max(a, md + 1), b, n << 1 | 1, md + 1, r));
    }
    return res;
  }
} roots[mxN];
int tree[mxN << 2];
int lz[mxN << 2];
void prop(int n, int l, int r) {
  if (!lz[n]) return;
  if (l == r) {
    roots[l] = node(lz[n]);
    lz[n] = 0;
    return;
  }
  tree[n << 1] = lz[n << 1] = lz[n];
  tree[n << 1 | 1] = lz[n << 1 | 1] = lz[n];
  lz[n] = 0;
}
void upd(int a, int b, int val, int n = 1, int l = 0, int r = K - 1) {
  prop(n, l, r);
  if (l == a && b == r) {
    tree[n] = lz[n] = val;
    return;
  }
  int md = (l + r) >> 1;
  if (a <= md) upd(a, min(b, md), val, n << 1, l, md);
  if (b > md) upd(max(a, md + 1), b, val, n << 1 | 1, md + 1, r);
  tree[n] = min(tree[n << 1], tree[n << 1 | 1]);
}
void dfs_upd(int a, int b, int idx, int val, int n = 1, int l = 0,
             int r = K - 1) {
  prop(n, l, r);
  if (l == r) {
    assert(l == idx);
    roots[l].upd(a, b, val);
    tree[n] = roots[l].val;
    return;
  }
  int md = (l + r) >> 1;
  if (idx <= md)
    dfs_upd(a, b, idx, val, n << 1, l, md);
  else
    dfs_upd(a, b, idx, val, n << 1 | 1, md + 1, r);
  tree[n] = min(tree[n << 1], tree[n << 1 | 1]);
}
int get(int a, int b, int n = 1, int l = 0, int r = K - 1) {
  prop(n, l, r);
  if (l == a && r == b) {
    return tree[n];
  }
  int md = (l + r) >> 1;
  int res = INT_MAX;
  if (a <= md) res = get(a, min(b, md), n << 1, l, md);
  if (b > md) res = min(res, get(max(a, md + 1), b, n << 1 | 1, md + 1, r));
  return res;
}
int dfs_get(int a, int b, int idx, int n = 1, int l = 0, int r = K - 1) {
  prop(n, l, r);
  if (l == r) {
    assert(l == idx);
    return roots[l].get(a, b);
  }
  int md = (l + r) >> 1;
  if (idx <= md) return dfs_get(a, b, idx, n << 1, l, md);
  return dfs_get(a, b, idx, n << 1 | 1, md + 1, r);
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(time(NULL));
  cout << fixed << setprecision(9);
  int t = 1;
  while (t--) {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> b[i];
    build();
    int mn = *min_element(b, b + N);
    fill(tree, tree + (mxN << 2), mn);
    for (int i = 0; i < K; i++) roots[i].val = mn;
    int q;
    cin >> q;
    while (q--) {
      int t, l, r, x;
      cin >> t >> l >> r;
      l--, r--;
      int a = (l == 0 ? 0 : (l - 1) / N + 1);
      int b = (r + 1) / N - 1;
      if (t == 1) {
        cin >> x;
        if (a <= b) upd(a, b, x);
        if (l % N) dfs_upd(l % N, min(a * N - 1, r) % N, a - 1, x);
        if ((r + 1) % N) dfs_upd(max(l, (b + 1) * N) % N, r % N, b + 1, x);
      } else {
        int res = INT_MAX;
        if (a <= b) res = get(a, b);
        if (l % N) res = min(res, dfs_get(l % N, min(a * N - 1, r) % N, a - 1));
        if ((r + 1) % N)
          res = min(res, dfs_get(max(l, (b + 1) * N) % N, r % N, b + 1));
        cout << res << '\n';
      }
    }
  }
  return 0;
}

```