You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li… ri] ki times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.
Input
The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.
Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.
The i-th of the next m lines contains three integers li, ri and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.
Output
Print the resulting string s after processing all m queries.
Examples
inputCopy
abacaba
2
3 6 1
1 4 2
outputCopy
baabcaa
Note
The sample is described in problem statement.
对区间进行操作,把首字母移到后面,
STL substr 即可,
注: string 的 substr( start, length ).
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define maxn 200005
const int mod=1e9+7;
#define eps 1e-5
#define pi acos(-1.0)
ll quickpow(ll a,ll b)
{
ll ans=1;
while(b){
if(b&1){
ans=ans*a;
}
a=a*a;
b>>=1;
}
return ans;
}
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
ios::sync_with_stdio(false);
string s;
cin>>s;
int m;
cin>>m;
string ss;
string Tmp;
int len=s.length();
while(m--){
int l,r,k;
cin>>l>>r>>k;
int tmp=r-l+1;
k=k%tmp;
r--;l--;
string ll=s.substr(l,r-l+1-k);
string rr=s.substr(r-k+1,k);
s=s.substr(0,l)+rr+ll+s.substr(r+1);
}
cout<<s<<endl;
}