#include <bits/stdc++.h>
using namespace std;
int arr[200003];
int n, k;
int T[200003][21];
struct Node {
  int val, lazy;
  Node *r, *l;
  Node() {}
  Node(int a, int b, Node *x, Node *z) {
    val = a;
    lazy = b;
    r = x;
    l = z;
  }
};
Node *root;
void preorder(Node *curr) {
  if (curr == NULL) return;
  printf("%d|%d ", curr->val, curr->lazy);
  preorder(curr->l);
  preorder(curr->r);
}
int value(Node *nod) {
  if (nod == NULL)
    return INT_MAX;
  else
    return nod->val;
}
int got(int kir, int kan) {
  int res = INT_MAX;
  int temp = kir % n;
  if (temp == 0) temp = n;
  kan = kan - (kir - temp);
  kan = min(kan, n + temp - 1);
  kir = temp;
  for (int i = 20; i >= 0; i--) {
    if (kir + (1 << i) - 1 <= kan) {
      res = min(res, T[kir][i]), kir += 1 << i;
    }
  }
  return res;
}
void update(Node *curr, int kir, int kan, int qkir, int qkan, int v) {
  if (curr->lazy != 0) {
    int x = curr->lazy;
    curr->lazy = 0;
    if (kir != kan) {
      if (curr->l == NULL)
        curr->l = new Node(x, x, NULL, NULL);
      else
        curr->l->val = x, curr->l->lazy = x;
      if (curr->r == NULL)
        curr->r = new Node(x, x, NULL, NULL);
      else
        curr->r->val = x, curr->r->lazy = x;
    }
  }
  if (qkir > kan || qkan < kir)
    return;
  else if (qkir <= kir && qkan >= kan) {
    curr->val = v;
    if (kir != kan) {
      if (curr->l == NULL)
        curr->l = new Node(v, v, NULL, NULL);
      else
        curr->l->val = v, curr->l->lazy = v;
      if (curr->r == NULL)
        curr->r = new Node(v, v, NULL, NULL);
      else
        curr->r->val = v, curr->r->lazy = v;
    }
  } else {
    int mid = (kir + kan) / 2;
    if (curr->l == NULL) curr->l = new Node(got(kir, mid), 0, NULL, NULL);
    if (curr->r == NULL) curr->r = new Node(got(mid + 1, kan), 0, NULL, NULL);
    update(curr->l, kir, mid, qkir, qkan, v);
    update(curr->r, mid + 1, kan, qkir, qkan, v);
    curr->val = min(value(curr->l), value(curr->r));
  }
}
int query(Node *curr, int kir, int kan, int qkir, int qkan) {
  if (curr->lazy != 0) {
    int x = curr->lazy;
    curr->lazy = 0;
    if (kir != kan) {
      if (curr->l == NULL)
        curr->l = new Node(x, x, NULL, NULL);
      else
        curr->l->val = x, curr->l->lazy = x;
      if (curr->r == NULL)
        curr->r = new Node(x, x, NULL, NULL);
      else
        curr->r->val = x, curr->r->lazy = x;
    }
  }
  if (kan < qkir || qkan < kir)
    return INT_MAX;
  else if (kir >= qkir && qkan >= kan)
    return curr->val;
  else {
    int mid = (kir + kan) / 2;
    if (curr->l == NULL) curr->l = new Node(got(kir, mid), 0, NULL, NULL);
    if (curr->r == NULL) curr->r = new Node(got(mid + 1, kan), 0, NULL, NULL);
    int a = query(curr->l, kir, mid, qkir, qkan);
    int b = query(curr->r, mid + 1, kan, qkir, qkan);
    return min(a, b);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (int i = 1; i <= n; i++) arr[i + n] = arr[i];
  for (int i = 0; i <= 20; i++) {
    for (int j = 1; j + (1 << i) - 1 <= 2 * n; j++) {
      if (i == 0)
        T[j][i] = arr[j];
      else
        T[j][i] = min(T[j][i - 1], T[j + (1 << (i - 1))][i - 1]);
    }
  }
  for (int i = 0; i <= 20; i++) root = new Node;
  *root = Node(INT_MAX, 0, NULL, NULL);
  for (int i = 1; i <= n; i++) root->val = min(arr[i], root->val);
  int q;
  scanf("%d", &q);
  while (q--) {
    int ask, a, b, val;
    scanf("%d", &ask);
    if (ask == 1) {
      scanf("%d %d %d", &a, &b, &val);
      update(root, 1, n * k, a, b, val);
    } else {
      scanf("%d %d", &a, &b);
      printf("%d\n", query(root, 1, n * k, 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;
int arr[200003];
int n, k;
int T[200003][21];
struct Node {
  int val, lazy;
  Node *r, *l;
  Node() {}
  Node(int a, int b, Node *x, Node *z) {
    val = a;
    lazy = b;
    r = x;
    l = z;
  }
};
Node *root;
void preorder(Node *curr) {
  if (curr == NULL) return;
  printf("%d|%d ", curr->val, curr->lazy);
  preorder(curr->l);
  preorder(curr->r);
}
int value(Node *nod) {
  if (nod == NULL)
    return INT_MAX;
  else
    return nod->val;
}
int got(int kir, int kan) {
  int res = INT_MAX;
  int temp = kir % n;
  if (temp == 0) temp = n;
  kan = kan - (kir - temp);
  kan = min(kan, n + temp - 1);
  kir = temp;
  for (int i = 20; i >= 0; i--) {
    if (kir + (1 << i) - 1 <= kan) {
      res = min(res, T[kir][i]), kir += 1 << i;
    }
  }
  return res;
}
void update(Node *curr, int kir, int kan, int qkir, int qkan, int v) {
  if (curr->lazy != 0) {
    int x = curr->lazy;
    curr->lazy = 0;
    if (kir != kan) {
      if (curr->l == NULL)
        curr->l = new Node(x, x, NULL, NULL);
      else
        curr->l->val = x, curr->l->lazy = x;
      if (curr->r == NULL)
        curr->r = new Node(x, x, NULL, NULL);
      else
        curr->r->val = x, curr->r->lazy = x;
    }
  }
  if (qkir > kan || qkan < kir)
    return;
  else if (qkir <= kir && qkan >= kan) {
    curr->val = v;
    if (kir != kan) {
      if (curr->l == NULL)
        curr->l = new Node(v, v, NULL, NULL);
      else
        curr->l->val = v, curr->l->lazy = v;
      if (curr->r == NULL)
        curr->r = new Node(v, v, NULL, NULL);
      else
        curr->r->val = v, curr->r->lazy = v;
    }
  } else {
    int mid = (kir + kan) / 2;
    if (curr->l == NULL) curr->l = new Node(got(kir, mid), 0, NULL, NULL);
    if (curr->r == NULL) curr->r = new Node(got(mid + 1, kan), 0, NULL, NULL);
    update(curr->l, kir, mid, qkir, qkan, v);
    update(curr->r, mid + 1, kan, qkir, qkan, v);
    curr->val = min(value(curr->l), value(curr->r));
  }
}
int query(Node *curr, int kir, int kan, int qkir, int qkan) {
  if (curr->lazy != 0) {
    int x = curr->lazy;
    curr->lazy = 0;
    if (kir != kan) {
      if (curr->l == NULL)
        curr->l = new Node(x, x, NULL, NULL);
      else
        curr->l->val = x, curr->l->lazy = x;
      if (curr->r == NULL)
        curr->r = new Node(x, x, NULL, NULL);
      else
        curr->r->val = x, curr->r->lazy = x;
    }
  }
  if (kan < qkir || qkan < kir)
    return INT_MAX;
  else if (kir >= qkir && qkan >= kan)
    return curr->val;
  else {
    int mid = (kir + kan) / 2;
    if (curr->l == NULL) curr->l = new Node(got(kir, mid), 0, NULL, NULL);
    if (curr->r == NULL) curr->r = new Node(got(mid + 1, kan), 0, NULL, NULL);
    int a = query(curr->l, kir, mid, qkir, qkan);
    int b = query(curr->r, mid + 1, kan, qkir, qkan);
    return min(a, b);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (int i = 1; i <= n; i++) arr[i + n] = arr[i];
  for (int i = 0; i <= 20; i++) {
    for (int j = 1; j + (1 << i) - 1 <= 2 * n; j++) {
      if (i == 0)
        T[j][i] = arr[j];
      else
        T[j][i] = min(T[j][i - 1], T[j + (1 << (i - 1))][i - 1]);
    }
  }
  for (int i = 0; i <= 20; i++) root = new Node;
  *root = Node(INT_MAX, 0, NULL, NULL);
  for (int i = 1; i <= n; i++) root->val = min(arr[i], root->val);
  int q;
  scanf("%d", &q);
  while (q--) {
    int ask, a, b, val;
    scanf("%d", &ask);
    if (ask == 1) {
      scanf("%d %d %d", &a, &b, &val);
      update(root, 1, n * k, a, b, val);
    } else {
      scanf("%d %d", &a, &b);
      printf("%d\n", query(root, 1, n * k, a, b));
    }
  }
}

```