Problem: Given n numbers a0, a1, ..., an-1 and q.
I want you to perform appropriate processing for q queries.
The query has the following three types of operations.


* Shift the value
Given a pair of l and r. (l <r) Circular shift the value from al to ar.

0 1 2 3 4 5 6 7 8 9

Is given the query l = 2, r = 5.

The shifted number sequence is

0 1 5 2 3 4 6 7 8 9

Will be.


* Find the minimum value
Given a pair of l and r. (l ≤ r)
Find the smallest value from al to ar.


* Update value
Given a pair of pos and val. Update the value of apos to val.



Input

The input is given in the following format.


n q
a0
a1
..
..
..
an-1
x1 y1 z1
x2 y2 z2
..
..
..
xq yq zq


If xi = 0, it represents a shift query. At this time, let l = yi and r = zi.
If xi = 1, it represents a query for the minimum value. At this time, let l = yi and r = zi.
If xi = 2, it represents a query that updates the value. At this time, pos = yi, val = zi.


Input meets the following constraints
1 ≤ n, q ≤ 200,000
0 ≤ ai ≤ 10,000,000 For queries that update values, 0 ≤ val ≤ 10,000,000

Output

When xi = 1 is given as a query, output the value of the answer on one line.

Examples

Input

10 3
0
1
2
3
4
5
6
7
8
9
1 5 7
0 2 5
1 5 7


Output

5
4


Input

10 10
289383
930886
692777
636915
747793
238335
885386
760492
516649
641421
2 7 368690
1 3 6
0 2 6
1 1 8
0 2 9
2 2 665123
1 5 9
0 2 8
2 7 961393
1 1 2


Output

238335
238335
238335
368690

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
int xor128(){
  static int x = 123456789;
  static int y = 362436069;
  static int z = 521288629;
  static int w = 88675123; 
  int t;
   
  t = x ^ (x << 11);
  x = y; y = z; z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

template<typename T,typename E>
struct RBST{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,size_t)> P;

  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  
  struct Node{
    Node *l,*r;
    size_t cnt;
    T val,dat;
    E laz;
    Node():cnt(0){l=r=nullptr;}
    Node(T val,E laz):
      cnt(1),val(val),dat(val),laz(laz){l=r=nullptr;}
  };

  const size_t LIM = 1e6;
  vector<Node> pool;
  size_t ptr;

  RBST(F f,G g,H h,P p,T d1,E d0):
    f(f),g(g),h(h),p(p),d1(d1),d0(d0),pool(LIM),ptr(0){}

  Node* build(size_t l,size_t r,vector<T> &v){
    if(l+1==r) return create(v[l]);
    size_t m=(l+r)>>1;
    return merge(build(l,m,v),build(m,r,v));
  }
  
  Node* build(vector<T> &v){
    return build(0,v.size(),v);
  }
  
  Node* create(){
    return &pool[ptr++];
  }
  
  Node* create(T v){
    return &(pool[ptr++]=Node(v,d0));
  }
  
  size_t count(const Node* a){
    if(a==nullptr) return 0;
    return a->cnt;
  }

  Node* insert(Node* a,size_t pos,T v){
    Node* b=create(v);
    auto s=split(a,pos);
    return a=merge(merge(s.first,b),s.second);
  }

  Node* erase(Node* a,size_t pos){
    auto s=split(a,pos);
    auto t=split(s.second,1);
    return merge(s.first,t.second);
  }

  T query(const Node *a){
    if(a==nullptr) return d1;
    //cout<<a<<":"<<(a->val)<<" "<<(a->dat)<<" "<<(a->laz)<<endl;
    return a->dat;
  }

  Node* update(Node* a){
    if(a==nullptr) return a;
    Node *l=a->l,*r=a->r;
    if(a->laz!=d0){ 
      a->val=g(a->val,p(a->laz,1));
      if(l!=nullptr){
	l->laz=h(l->laz,a->laz);
	l->val=g(l->val,p(l->laz,1));
	l->dat=g(l->dat,p(l->laz,count(l)-1));
	l->dat=f(l->val,l->dat);
      }
      if(r!=nullptr){
	r->laz=h(r->laz,a->laz);
	r->val=g(r->val,p(r->laz,1));
	r->dat=g(r->dat,p(r->laz,count(r)-1));
	r->dat=f(r->val,r->dat);
      }
      a->laz=d0;
    }
    a->cnt=count(l)+count(r)+1;
    a->dat=f(a->val,f(query(l),query(r)));
    return a;
  }

  T query(Node *&a,size_t l,size_t r){
    auto s=split(a,l);
    auto t=split(s.second,r-l);
    auto u=t.first;
    T res=query(u);
    a=merge(s.first,merge(t.first,t.second));
    return res;
  }
  
  void update(Node *&a,size_t l,size_t r,E v){
    auto s=split(a,l);
    auto t=split(s.second,r-l);
    auto u=t.first;
    u->laz=h(u->laz,v);
    update(u);
    a=merge(merge(s.first,u),t.second);
  }

  void dump(Node* a,typename vector<T>::iterator it){
    if(!count(a)) return;
    update(a);
    dump(a->l,it);
    *(it+count(a->l))=a->val;
    dump(a->r,it+count(a->l)+1);
  }
  
  void dump(Node* a,vector<T> &v){
    v.resize(count(a));
    dump(a,v.begin());
  }

  Node* merge(Node* a,Node* b){
    if(a==nullptr) return b;
    if(b==nullptr) return a;
    if(xor128()%(count(a)+count(b))<count(a)){
      a=update(a);
      a->r=merge(a->r,b);
      return update(a);
    }
    b=update(b);
    b->l=merge(a,b->l);
    return update(b);
  }

  pair<Node*, Node*> split(Node* a,size_t k){
    if(a==nullptr) return make_pair(a,a);
    update(a);
    if(k<=count(a->l)){
      auto s=split(a->l,k);
      a->l=s.second;
      return make_pair(s.first,update(a));
    }
    auto s=split(a->r,k-(count(a->l)+1));
    a->r=s.first;
    return make_pair(update(a),s.second);
  } 
  
};

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n,q;
  cin>>n>>q;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  
  RBST<int, int>::F f=[](int a,int b){return min(a,b);};
  RBST<int, int>::G g=[](int a,int b){return b<0?a:b;};
  RBST<int, int>::H h=[](int a,int b){return b<0?a:b;};
  RBST<int, int>::P p=[](int a,size_t b){++b;return a;};
  const int INF = 1e9;
  RBST<int, int> rbst(f,g,h,p,INF,-1);

  auto root=rbst.build(v);
  
  for(int i=0;i<q;i++){
    int x,y,z;
    cin>>x>>y>>z;
    if(x==0){
      int v=rbst.query(root,z,z+1);
      root=rbst.erase(root,z);
      root=rbst.insert(root,y,v);
    }
    if(x==1){
      cout<<rbst.query(root,y,z+1)<<endl;
    }
    if(x==2){
      rbst.update(root,y,y+1,z);
    }
  }
  
  return 0;
}