#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = std::numeric_limits<long long>::max();
const int MX = 100101;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first + b.first, a.second + b.second);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first - b.first, a.second - b.second);
}
template <typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.first + a.second * b.second);
}
template <typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.second - a.second * b.first);
}
vector<int> sk;
int N;
struct node {
  int l, r;
  int lazy;
  int maz;
  node *left = NULL, *right = NULL;
  node(int a, int b) : l(a), r(b), lazy(0) {}
  void add_left();
  void add_right();
  int gauk_min(int a, int b) {
    int ret;
    if (r < a or b < l)
      ret = MOD;
    else if (a <= l and r <= b)
      ret = maz;
    else
      ret = min(left->gauk_min(a, b), right->gauk_min(a, b));
    return ret;
  }
  void push() {
    if (!lazy) return;
    add_left();
    add_right();
    left->lazy = lazy;
    right->lazy = lazy;
    maz = lazy;
    lazy = 0;
  }
  int get_min(int a, int b) {
    int mid = (l + r) / 2;
    push();
    if (a <= l and r <= b) {
      return maz;
    } else if (b <= mid) {
      add_left();
      return left->get_min(a, b);
    } else if (mid < a) {
      add_right();
      return right->get_min(a, b);
    } else {
      add_left();
      add_right();
      return min(left->get_min(a, b), right->get_min(a, b));
    }
  }
  void set_lazy(int a, int b, int first) {
    int mid = (l + r) / 2;
    push();
    if (a <= l and r <= b) {
      lazy = first;
    } else if (b <= mid) {
      add_left();
      left->set_lazy(a, b, first);
    } else if (mid < a) {
      add_right();
      right->set_lazy(a, b, first);
    } else {
      add_left();
      add_right();
      left->set_lazy(a, b, first);
      right->set_lazy(a, b, first);
    }
    push();
    if (l != r) {
      add_left();
      add_right();
      left->push();
      right->push();
      maz = min(left->maz, right->maz);
    }
  }
  void print() {
    if (l != r) {
      add_left();
      left->print();
      printf("l = %d, r = %d, maz = %d\n", l, r, maz);
      add_right();
      right->print();
    } else {
      printf("l = %d, r = %d, maz = %d\n", l, r, maz);
    }
  }
};
node *pradinis;
int gauk(int a, int b) {
  int ret = -MOD;
  if (b - a >= N - 1)
    ret = pradinis->gauk_min(0, N - 1);
  else {
    a %= N;
    b %= N;
    if (a <= b)
      ret = pradinis->gauk_min(a, b);
    else
      ret = min(pradinis->gauk_min(a, N - 1), pradinis->gauk_min(0, b));
  }
  return ret;
}
void node::add_left() {
  if (!left) {
    left = new node(l, (l + r) / 2);
    left->maz = gauk(l, (l + r) / 2);
  }
}
void node::add_right() {
  if (!right) {
    right = new node((l + r) / 2 + 1, r);
    right->maz = gauk((l + r) / 2 + 1, r);
  }
}
void build(node *curr) {
  int l = curr->l;
  int r = curr->r;
  if (curr->l == curr->r) {
    curr->maz = sk[l];
  } else {
    curr->left = new node(l, (l + r) / 2);
    curr->right = new node((l + r) / 2 + 1, r);
    build(curr->left);
    build(curr->right);
    curr->maz = min(curr->left->maz, curr->right->maz);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int K;
  cin >> N >> K;
  sk = vector<int>(N);
  for (int i = 0; i < N; ++i) cin >> sk[i];
  pradinis = new node(0, N - 1);
  build(pradinis);
  int Q;
  cin >> Q;
  node tikras(0, N * K - 1);
  tikras.maz = gauk(0, N - 1);
  for (int i = 0; i < Q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b, first;
      cin >> a >> b >> first;
      a--;
      b--;
      tikras.set_lazy(a, b, first);
    } else {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      printf("%d\n", tikras.get_min(a, b));
    }
  }
}

### 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 int MOD = 1000000007;
const long long INF = std::numeric_limits<long long>::max();
const int MX = 100101;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first + b.first, a.second + b.second);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first - b.first, a.second - b.second);
}
template <typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.first + a.second * b.second);
}
template <typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.second - a.second * b.first);
}
vector<int> sk;
int N;
struct node {
  int l, r;
  int lazy;
  int maz;
  node *left = NULL, *right = NULL;
  node(int a, int b) : l(a), r(b), lazy(0) {}
  void add_left();
  void add_right();
  int gauk_min(int a, int b) {
    int ret;
    if (r < a or b < l)
      ret = MOD;
    else if (a <= l and r <= b)
      ret = maz;
    else
      ret = min(left->gauk_min(a, b), right->gauk_min(a, b));
    return ret;
  }
  void push() {
    if (!lazy) return;
    add_left();
    add_right();
    left->lazy = lazy;
    right->lazy = lazy;
    maz = lazy;
    lazy = 0;
  }
  int get_min(int a, int b) {
    int mid = (l + r) / 2;
    push();
    if (a <= l and r <= b) {
      return maz;
    } else if (b <= mid) {
      add_left();
      return left->get_min(a, b);
    } else if (mid < a) {
      add_right();
      return right->get_min(a, b);
    } else {
      add_left();
      add_right();
      return min(left->get_min(a, b), right->get_min(a, b));
    }
  }
  void set_lazy(int a, int b, int first) {
    int mid = (l + r) / 2;
    push();
    if (a <= l and r <= b) {
      lazy = first;
    } else if (b <= mid) {
      add_left();
      left->set_lazy(a, b, first);
    } else if (mid < a) {
      add_right();
      right->set_lazy(a, b, first);
    } else {
      add_left();
      add_right();
      left->set_lazy(a, b, first);
      right->set_lazy(a, b, first);
    }
    push();
    if (l != r) {
      add_left();
      add_right();
      left->push();
      right->push();
      maz = min(left->maz, right->maz);
    }
  }
  void print() {
    if (l != r) {
      add_left();
      left->print();
      printf("l = %d, r = %d, maz = %d\n", l, r, maz);
      add_right();
      right->print();
    } else {
      printf("l = %d, r = %d, maz = %d\n", l, r, maz);
    }
  }
};
node *pradinis;
int gauk(int a, int b) {
  int ret = -MOD;
  if (b - a >= N - 1)
    ret = pradinis->gauk_min(0, N - 1);
  else {
    a %= N;
    b %= N;
    if (a <= b)
      ret = pradinis->gauk_min(a, b);
    else
      ret = min(pradinis->gauk_min(a, N - 1), pradinis->gauk_min(0, b));
  }
  return ret;
}
void node::add_left() {
  if (!left) {
    left = new node(l, (l + r) / 2);
    left->maz = gauk(l, (l + r) / 2);
  }
}
void node::add_right() {
  if (!right) {
    right = new node((l + r) / 2 + 1, r);
    right->maz = gauk((l + r) / 2 + 1, r);
  }
}
void build(node *curr) {
  int l = curr->l;
  int r = curr->r;
  if (curr->l == curr->r) {
    curr->maz = sk[l];
  } else {
    curr->left = new node(l, (l + r) / 2);
    curr->right = new node((l + r) / 2 + 1, r);
    build(curr->left);
    build(curr->right);
    curr->maz = min(curr->left->maz, curr->right->maz);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int K;
  cin >> N >> K;
  sk = vector<int>(N);
  for (int i = 0; i < N; ++i) cin >> sk[i];
  pradinis = new node(0, N - 1);
  build(pradinis);
  int Q;
  cin >> Q;
  node tikras(0, N * K - 1);
  tikras.maz = gauk(0, N - 1);
  for (int i = 0; i < Q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b, first;
      cin >> a >> b >> first;
      a--;
      b--;
      tikras.set_lazy(a, b, first);
    } else {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      printf("%d\n", tikras.get_min(a, b));
    }
  }
}

```