#SGM0000004. RMQ với phép dịch vòng (RMQ with Shifts)

RMQ với phép dịch vòng (RMQ with Shifts)

RMQ with Shifts

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Given a 1-indexed array AA, process two operation types. query(L,R) asks for the minimum on [L,R][L,R]. shift(i_1,i_2,\ldots,i_k) with i1<i2<⋯<iki_1<i_2<\cdots<i_k left-cyclically shifts the values at those positions.

Input

  • The first line contains nn and qq.
  • The second line contains nn positive integers, each at most 100000100000.
  • Each of the next qq lines is a valid query(...) or shift(...) string, contains no spaces, and has length at most 3030.

Output

For every query operation, print the minimum value in the requested range.

Subtasks

  • Subtask 1 — 20%: 1≤n,q≤10001 \le n,q \le 1000.
  • Subtask 2 — 30%: 1≤n,q≤500001 \le n,q \le 50000.
  • Subtask 3 — 50%: 1≤n≤1000001 \le n \le 100000, 1≤q≤2500001 \le q \le 250000.

Examples

Input

7 5
6 2 4 8 5 1 4
query(3,7)
shift(2,4,5,7)
query(1,4)
shift(1,2)
query(2,2)

Output

1
4
6

Explanation

The first query examines 4,8,5,1,44,8,5,1,4, so the answer is 11. After shift(2,4,5,7), the array becomes 6,8,4,5,4,1,26,8,4,5,4,1,2, hence query(1,4) returns 44. After shift(1,2), the first two values become 8,68,6, so query(2,2) returns 66.