Problem:
Transformation Write a program which performs a sequence of commands to a given string $str$. The command is one of:  print a b : print from the a -th character to the b -th character of $str$  reverse a b : reverse from the a -th character to the b -th character of $str$  replace a b p : replace from the a -th character to the b -th character of $str$ with p  Note that the indices of $str$ start with 0. Input In the first line, a string $str$ is given. $str$ consists of lowercase letters. In the second line, the number of commands q is given. In the next q lines, each command is given in the above mentioned format. Output For each print command, print a string in a line. Constraints  $1 \leq $ length of $str \leq 1000$  $1 \leq q \leq 100$  $0 \leq a \leq b < $ length of $str$  for replace command, $b - a + 1 = $ length of $p$  Sample Input 1 abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4 Sample Output 1 xaze Sample Input 2 xyz
3
print 0 2
replace 0 2 abc
print 0 2 Sample Output 2 xyz
abc

Solution (Python):
from enum import Enum
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


line = input()
num_query = int(input())

for loop in range(num_query):

    input_str = list(input().split())

    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]

    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]

    else: 
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()

Solution (Python):
s=input()
for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    if c=='p':s=s[:a]+o[3]+s[b:]
    elif c=='i':print(s[a:b])
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]

Solution (Python):
char = input()
num = int(input())

for i in range(num):
    commands = input()
    command = commands.split(" ")
    start = int(command[1])
    stop = int(command[2])
    if command[0] == "replace":
        char = char[0:start] + command[3] + char[stop+1:]
    elif command[0] == "reverse":
        if start == 0:
            char = char[stop:0:-1] + char[0] + char[stop+1:]
        else:
            char = char[:start] + char[stop:start-1:-1] + char[stop+1:]
    elif command[0] == "print":
        print(char[start:stop+1])
    else:
        break

Solution (Python):

S=input()
n=int(input())
for j in range(n):
  M=list(map(str,input().split()))
  a=int(M[1])
  b=int(M[2])
  if(M[0]=="print"):
    print(S[a:b+1])
  elif M[0]=="reverse":
    S=S[:a]+S[a:b+1][::-1]+S[b+1:]
  elif M[0]=="replace":
    S=S[:a]+M[3]+S[b+1:]

Solution (Python):
s = list(input())
for i in range(int(input())):
  cmd, a, b, *c = input().split()
  a = int(a); b = int(b)
  if cmd == "print":
    print(*s[a:b+1], sep='')
  elif cmd == "reverse":
    s[a:b+1] = reversed(s[a:b+1])
  else:
    s[a:b+1] = c[0]

Solution (Python):
str = input()
for i in range(int(input())):
    process = input().split()
    a = int(process[1])
    b = int(process[2])
    
    if process[0] == 'replace':
        str = str[:a] + process[3] + str[b+1:]
    elif process[0] == 'reverse':
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    elif process[0] == 'print':
        print(str[a:b+1])

Solution (Python):
s = list(input())
n = int(input())
order = []
rep = []
l = []
a = 0
b = 0
toprint = ""
for i in range(n):
    order = input().split()
    a = int(order[1])
    b = int(order[2])
    if len(order)==4:
        rep = list(order[3])
        for j in range(len(rep)):
            s[j+a]=rep[j]
    elif order[0]=="reverse":
        l = ["" for k in range(b-a+1)]
        for j in range(len(l)):
            l[j]=s[j+a]
        l.reverse()
        for j in range(len(l)):
            s[j+a]=l[j]
    else:
        toprint=""
        for j in range(b-a+1):
            toprint+=s[j+a]
        print(toprint)

Solution (Python):
w = input()
n = int(input())

for _ in range(n):
    ops = input().split()
    a = int(ops[1])
    b = int(ops[2])+1

    if ops[0] == 'print':
        print(w[a:b])

    if ops[0] == 'reverse':
        w = w[:a] + str(w[a:b])[::-1] + w[b:]

    if ops[0] == 'replace':
        p = ops[3]
        w = w[:a] + p + w[b:]

Solution (Python):
str = input()
q = int(input())  
for i in range(q):
    order = input().split()
    if order[0] == "print":
        a = int(order[1])
        b = int(order[2])
        print(str[a:b+1])
    elif order[0] == "reverse":
        a = int(order[1])
        b = int(order[2])
        rev_str = "".join(list(reversed(str[a:b+1])))
        str = str[:a] + rev_str + str[b+1:]
    elif order[0] == "replace":
        a = int(order[1])
        b = int(order[2])
        str = str[:a] + order[3] + str[b+1:]

Solution (Python):
s = input()
q = int(input())
 
for i in range(q):
    line = input().split()
     
    if len(line) == 4:
        com,a,b,r = line
        a,b = int(a),int(b)
        s = s[:a] + r + s[b+1:]
    else:
        com,a,b = line
        a,b = int(a),int(b)
        if com == "print":
            print(s[a:b+1])
        else:
            sab = s[a:b+1]
            s = s[:a] + sab[::-1] + s[b+1:]

Solution (Python):
s = input()
for _ in range(int(input())):
    code=input().split()
    if code[0]=='print'  :
        print(s[int(code[1]):int(code[2])+1])
    elif code[0]=='reverse':
        s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:]
    elif code[0]=='replace':
        s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]

Solution (Python):
s = str(input())
 
q = int(input())
 
d_list=[]
for i in range(q):
  s2 = ''
   
  d = list(map(str, input().split()))
  if d[0] == 'print':
    print( s[ int(d[1]): int(d[2])+1 ] )
     
  elif d[0] == 'reverse':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = reversed(S[int(d[1]):int(d[2])+1])
    for i in S:
      s2 += i
    s = s2
    
  elif d[0] == 'replace':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = list(d[3])
    for i in S:
      s2 += i
    s = s2

Solution (Python):
s = str(input())

q = int(input())

d_list=[]
for i in range(q):
  s2 = ''
  
  d = list(map(str, input().split()))
  if d[0] == 'print':
    print( s[ int(d[1]): int(d[2])+1 ] )
    
  elif d[0] == 'reverse':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = reversed(S[int(d[1]):int(d[2])+1])
    for i in S:
      s2 += i
    s = s2
   
  elif d[0] == 'replace':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = list(d[3])
    for i in S:
      s2 += i
    s = s2

Solution (Python):
s = input()
for _ in range(int(input())):
    code=input().split()
    if code[0]=='print'  :
        print(s[int(code[1]):int(code[2])+1])
    elif code[0]=='reverse':
        s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:]
    elif code[0]=='replace':
        s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]

Solution (Python):
str = input()
q = int(input())
 
for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1
 
    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Solution (Python):
str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Solution (Python):
s = input()
for _ in range(int(input())):
    code=input().split()
    if code[0]=='print'  :
        print(s[int(code[1]):int(code[2])+1])
    elif code[0]=='reverse':
        s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:]
    elif code[0]=='replace':
        s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]

Solution (Python):
str=list(input())
N=int(input())
for i in range(N):
    order=list(input().split())
    x=int(order[1])
    y=int(order[2])
    z=len(str)
    if order[0]=='replace':
        str[x:y+1]=order[3]
    elif order[0]=='reverse':
        strage=str[::-1]
        str[x:y+1]=strage[z-1-y:z-x]
    else:
        printstr=''.join(str[x:y+1])
        print(printstr)

Solution (Python):
ans = input()
n = int(input())
for _ in range(n):
    o = input().split()
    a, b = map(int, o[1:3])
    b += 1
    c = o[0][2]
    if c == "p":
        ans = ans[:a] + o[3] + ans[b:]
    elif c == 'i':
        print(ans[a:b])
    else:
        ans = ans[:a] + ans[a:b][::-1] + ans[b:]

Solution (Python):
if __name__ == "__main__":
    input_str = list(input())
    op_num = int(input())
    for _ in range(op_num):
        operations = input().split()
        op_name = operations[0]
        beg_idx = int(operations[1])
        end_idx = int(operations[2]) + 1
        if "replace" == op_name:
            replace_str = list(operations[3])
            input_str[beg_idx:end_idx] = replace_str
        elif "reverse" == op_name:
            input_str[beg_idx:end_idx] = reversed(input_str[beg_idx:end_idx])
        else:
            print("".join(input_str[beg_idx:end_idx]))

Solution (Python):
s = input()
st = list(s)
D = []
n = int(input())
for i in range(n) : 
  B = input().split()
  a = int(B[1])
  b = int(B[2])
  if B[0] == 'print' :
   
    st[a : b+1] = ''.join(st[a:b+1])
    if st[a : b+1] not in D :     
      D.append(''.join(st[a : b+1]))
    
    
  elif B[0] == 'reverse' :
    C = st[a : b + 1]
    C.reverse()
    del st[a : b + 1]
    st[a : a] = C

  elif B[0] == 'replace' :
    del st[a : b + 1]
    st[a : a] = B[3]
    
   
    
st  = ''.join(st) 


for i in D :
  print(i)

Solution (Python):
s=input()
q=int(input())
for i in range(q):
    t=input().split(" ")
    if t[0]=="print":
        a,b=int(t[1]),int(t[2])
        print(s[a:b+1:])
    if t[0]=="reverse":
        a,b=int(t[1]),int(t[2])
        s=s[:a:]+s[a:b+1:][::-1]+s[b+1::]
    if t[0]=="replace":
        a,b=int(t[1]),int(t[2])
        x=t[3]
        s=s[:a:]+x+s[b+1::]

Solution (Python):






import sys
import math


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()






















def get_input():
    N = []
    while True:
        try:
            N.append(input())
        except EOFError:
            break
    return N

S = input()
N = int(input())
P = []

for i in range(N):
    P.append([x for x in input().split()])

for M in P:
    if M[0] == 'print':
        a = int(M[1])
        b = int(M[2])+1
        print(S[a:b])
    elif M[0] == 'reverse':
        a = int(M[1])
        b = int(M[2])+1
        T = S[a:b]
        S = S[:a]+T[::-1]+S[b:]
    elif M[0] == 'replace':
        a = int(M[1])
        b = int(M[2])+1
        S = S[:a]+M[3]+S[b:]

Solution (Python):
string = input()
q = int(input())
for i in range(q):
    command = list(input().split())
    a = int(command[1])
    b = int(command[2])
    if command[0] == "print":
        print(string[a:b + 1])
    elif command[0] == "reverse":
        tmp_str = string[a: b + 1]
        string = string[:a] + tmp_str[::-1] + string[b + 1:]
    elif command[0] == "replace":
        string = string[:a] + command[3] + string[b + 1:]

Solution (Python):
order = []
str = input()

q = int(input())
for i in range(q):
    s = input().split()
    order.append(s)


for i in range(q):
    a = int(order[i][1])
    b = int(order[i][2])
    
    if order[i][0] == 'print':
            print(str[a:(b+1)])
    elif order[i][0] == 'replace':
        str = str[:a] + order[i][3] + str[(b+1):]
        
    elif order[i][0] == 'reverse':
        new_str = list(str[a:(b+1)])
        new_str.reverse()
        new_str = ''.join(new_str)
        str = str[:a] + new_str + str[(b+1):]

Solution (Python):


str = input()
q = int(input())

for _ in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])

Solution (Python):
s=input()
n=int(input())
for i in range(n):
    c=input().split()
    st=int(c[1])
    en=int(c[2])
    if c[0]=='replace':
        s=s[:st]+c[3]+s[en+1:]
    elif c[0]=='reverse':
        s=s[:st]+s[st:en+1][::-1]+s[en+1:]
    else:
        print(s[st:en+1])

Solution (Python):

class orders():
    def __init__(self,str):
        self.str=str
        
    def printout(self,a,b):
        result=""
        array=[]
        array=list(self.str)

        for i in range(a,b+1):
            result=result+array[i]
        print(result)
    
    def reverse(self,a,b):
        result_r=""
        re_array=[]
        array_r=[]
        array_r=list(self.str)

        for i in range(0,a):
            result_r=result_r+array_r[i]
       
        for j in range(a,b+1):
           
            re_array.append(array_r[j])
          
        for jj in re_array[::-1]:
            result_r=result_r+jj
            
        for k in range(b+1,len(array_r)):
            result_r=result_r+array_r[k]

        self.str=result_r
     
    def replace_out(self,a,b,p):
        result_p=""
        array_r=[]
        array_r=list(self.str)
        for i in range(0,a):
            result_p=result_p+array_r[i]
        
        result_p=result_p+p

        for k in range(b+1,len(array_r)):
            result_p=result_p+array_r[k]
        
        self.str=result_p

if __name__=="__main__":
    
    input_text=input()

    number=input()
    num=int(number)
    i=1
    object1=orders(input_text)
    while i <=num:
        in_array=[]
        inp=""
        inp=input()
        in_array=inp.split()

        if in_array[0]=="replace":
            object1.replace_out(int(in_array[1]),int(in_array[2]),in_array[3])
           
        
        elif in_array[0]=="reverse":
            object1.reverse(int(in_array[1]),int(in_array[2]))

        elif in_array[0]=="print":
            object1.printout(int(in_array[1]),int(in_array[2]))

        i=i+1

Solution (Python):
s=input()

for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    
    if c=='p':s=s[:a]+o[3]+s[b:]
      
    elif c=='i':print(s[a:b])
      
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]

Solution (Python):
s = input()
for _ in range(int(input())):
    code=input().split()
    if code[0]=='print'  :
        print(s[int(code[1]):int(code[2])+1])
    elif code[0]=='reverse':
        s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:]
    elif code[0]=='replace':
        s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]

Solution (Python):
s = input()
for _ in range(int(input())):
    code=input().split()
    if code[0]=='print'  :
        print(s[int(code[1]):int(code[2])+1])
    elif code[0]=='reverse':
        s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:]
    elif code[0]=='replace':
        s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]

Solution (Python):
s = input()
for i in range(int(input())):
    op, a, b, *p = input().split()
    a, b = int(a), int(b)
    
    if op == 'print':
        print(s[a:b + 1])
        
    elif op == 'reverse':
        s = s[:a] + s[a:b + 1][::-1] + s[b + 1:]

    elif op == 'replace':
        s = s[:a] + p[0] + s[b + 1:]
        
    else:
        print('op error')

Solution (Python):
str=input()
ls=len(str)
Str=[str[i] for i in range(ls)]
q=int(input())
i=0
while i<q:
    Com=input().split()
    command=Com[0]
    a=int(Com[1])
    b=int(Com[2])
    l=len(Com)
    if l>3:
        rep=Com[3]
        Rep=[rep[i] for i in range(b+1-a)]

    if command=="print":
        print("".join(Str[a:b+1]))
    if command=="reverse":
        temp=Str[a:b+1]
        
        


        for j in range(b+1-a):
            Str[a+j]=temp[b-a-j]
        

    if command=="replace":
        
        for j in range(b+1-a):
            Str[a+j]=Rep[j]
        
    i+=1

Solution (Python):
s = list(input())

for i in range(int(input())):
    cmd, a, b, *c = input().split()
    a = int(a); b = int(b)
    if cmd == "print":
        print(*s[a:b+1], sep='')
    elif cmd == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
    else:
        s[a:b+1] = c[0]

Solution (Python):
s = input()
q = int(input())
for i in range(q):
    row = list(input().split())
    a = int(row[1])
    b = int(row[2])
    command = row[0]
    if command == "replace":
        p = row[3]
        s = s[:a] + p + s[b+1:]
    elif command == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif command == "print":
        print(s[a:b+1])

Solution (Python):
w=raw_input()
n=input()
l=['print','replace','reverse']
for i in range(n):
    c=map(str,raw_input().split())
    if c[0]==l[0]:
        print w[int(c[1]):int(c[2])+1]
    elif c[0]==l[1]:
        w=w[:int(c[1])]+c[3]+w[int(c[2])+1:]
    else:
        w=w[0:int(c[1])]+w[int(c[1]):int(c[2])+1][::-1]+w[int(c[2])+1:]

Solution (Python):
from enum import Enum
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
line = input()
num_query = int(input())
 
for loop in range(num_query):
 
    input_str = list(input().split())
 
    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]
 
    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]
 
    else: 
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()

Solution (Python):
st = input()
q = int(input())

for i in range(q):
  order = list(map(str, input().split()))
  a = int(order[1])
  b = int(order[2])
  
  if order[0] =='print':
      print(st[a:b+1])
  elif order[0] =='reverse':
      st = st[:a] + st[a:b+1][::-1] + st[b+1:]
  else:
      st = st[:a] + order[3] + st[b+1:]

Solution (Python):
char=input()
cnt=int(input())
for _ in range(0,cnt):
    ops = input().split()
    a,b=map(int,ops[1:3])
    if ops[0] == 'print':
        print(char[a:b+1])
    if ops[0] == 'reverse':
        char = char[0:a] + char[a:b+1][::-1] + char[b+1:]
    if ops[0] == 'replace':
        char = char[0:a] + ops[3] + char[b+1:]

Solution (Python):
text = input()

q = int(input())

for _ in range(q):

    list_command = list(input().split())
    
    a = int(list_command[1])
    b = int(list_command[2])

    if   list_command[0] == "print":
        print(text[a:b + 1])
    elif list_command[0] == "reverse":
        text = text[:a] + text[a:b+1][::-1] + text[b + 1:]
    elif list_command[0] == "replace":
        text = text[:a] + list_command[3] + text[b + 1:]
    else:
        raise

Solution (Python):
s = input()
q = int(input())
for _ in range(q):
    data = input().split()
    method = data[0]
    a, b = map(int, data[1:3])
    if method == 'print':
        print(s[a:b + 1])
        continue
    if method == 'reverse':
        p = s[a:b + 1]
        p = p[::-1]
    elif method == 'replace':
        p = data[3]
    s = s[:a] + p + s[b + 1:]

Solution (Python):
s = input()
n = int(input())

for _ in range(n):
    line = input().split()
    command = line[0]

    if command == 'replace':
        start, end  = int(line[1]), int(line[2])
        s = s[:start] + line[3] + s[end+1:]
    elif command == 'reverse':
        start, end  = int(line[1]), int(line[2])
        s = s[:start] + s[start:end+1][::-1] + s[end+1:]
    elif command == 'print':
        start, end  = int(line[1]), int(line[2])
        print(f"{s[start:end+1]}")

Solution (Python):
s = input()
q = int(input())

S = []

for i in range(q) :
  x = list(map(str, input().split()))
  a = int(x[1])
  b = int(x[2]) + 1

  if(x[0] == "print") :
    S.append(s[a:b])
  elif(x[0] == "reverse") :
    rv = s[a:b]
    srv = rv[::-1]  
    s = s[:a] + srv + s[b:]
  else :
    rp = x[3]
    s = s[:a] + rp + s[b:]

for j in S :
  print(j)

Solution (Python):
t = input()
for _ in range(int(input())):
    order = input().split()
    cmd = order[0]
    a, b = map(int,  order[1:3])
    if cmd == 'print':
        print(t[a:b+1])
    elif cmd == 'reverse':
        t = t[:a] + t[a:b+1][b::-1] + t[b+1:]
    else:
        c = order[3]
        t = t[:a] + c + t[b+1:]

Solution (Python):
def fun_replace(str1,str2,a,b):
    str1_list = list(str1)
    str2_list = list(str2)
    for i in range(b-a+1):
        str1_list[a+i]=str2_list[i]
    str1_changed = "".join(str1_list)
    return str1_changed

def fun_reverse(str1,a,b):
    tmp_str_list=list(str1[a:b+1])
    tmp_str_list.reverse()
    str1_list = list(str1)
    for i in range(b-a+1):
        str1_list[a+i] = tmp_str_list[i]
    str1_changed = "".join(str1_list)
    return str1_changed

def fun_print(str1,a,b):
    for i in range(a,b+1):
        print("%s"%(str1[i]),end="")
    print()


T = str(input())
change_num=int(input())
for order_num in range(change_num):
    order=input().split()

    if str(order[0]) == 'replace':
        T=fun_replace(T,str(order[3]),int(order[1]),int(order[2]))
    elif str(order[0]) == 'reverse':
        T=fun_reverse(T,int(order[1]),int(order[2]))
    else:
        fun_print(T,int(order[1]),int(order[2]))

Solution (Python):
S = input()
M = int(input())
for _ in range(M):
    op, *args = input().split()
    a = int(args.pop(0))
    b = int(args.pop(0))
    if op == "print":
        print(S[a:b + 1])
    elif op == "reverse":
        S = S[:a] + S[a:b + 1][::-1] + S[b + 1:]
    elif op == "replace":
        p = args.pop(0)
        S = S[:a] + p + S[b + 1:]

Solution (Python):
s = input()
cnt = int(input())

for _ in range(cnt):
    cmd = input().split()
    a=int(cmd[1])
    b=int(cmd[2]) +1

    if cmd[0] == "print":
        print(s[a:b])

    if cmd[0] == "reverse" :
        s= s[:a] +s[a:b][::-1]+s[b:]

    if cmd[0] == "replace":
        c = cmd[3]
        s = s[:a] + c +s[b:]

Solution (Python):
str_ori = input()
num = int(input())

result = []

for _ in range(num):

    table = list(map(str, input().split()))
    start = int(table[1])
    end = int(table[2]) + 1

    if table[0] == "print":
        result.append(str_ori[start:end])
    elif table[0] == "reverse":
        rev = str_ori[start:end]
        srev = rev[::-1]
        str_ori = str_ori[:start] + srev + str_ori[end:]
    elif table[0] == "replace":
        rep = table[3]
        str_ori = str_ori[:start] + rep + str_ori[end:]

for p in result:
    print(p)

Solution (Python):
if __name__ == '__main__':
	s = str(input())
	n = int(input())
	for i in range(n):
		data = input().split()
		if data[0] == "print":
			print(s[int(data[1]):int(data[2])+1])
		elif data[0] == "reverse":
			tmp = s[int(data[1]):int(data[2])+1]
			tmp = [s for s in tmp]
			tmp.reverse()
			rev = "".join(tmp)
			s = s[:int(data[1])]+rev+s[int(data[2])+1:]
		elif data[0] == "replace":
			s = s[:int(data[1])]+data[3]+s[int(data[2])+1:]

Solution (Python):
def Print(st,a,b):
    print(st[a:b])
    
def Reverse(st,a,b):
    rev = st[a:b]
    st = st[:a] + rev[::-1] + st[b:]
    
    return st

def Replace(st,a,b,p):
    rep = str(p)
    st = st[:a] + rep + st[b:]
    
    return st

st = input()
num = int(input())
while num > 0:
    com = input().split()
    a = int(com[1])
    b = int(com[2])
    
    if(com[0] == "print"):
        Print(st,a,b+1)
    elif(com[0] == 'reverse'):
        st = Reverse(st,a,b+1)

    elif(com[0] == 'replace'):
        p = str(com[3])
        st = Replace(st,a,b+1,p)
    num -= 1

Solution (Python):
str = input()
q = int(input())
for i in range(q):
  lst = list(input().split())
  a = int(lst[1])
  b = int(lst[2])
  if lst[0] == "print":
    print(str[a:b+1])
  elif lst[0] == "reverse":
    s = str[a:b+1]
    ss = "".join(list(reversed(s))) 
    t1 = str[0:a]
    t2 = str[a:b+1]
    t3 = str[b+1:len(str)]
    str = t1 + ss + t3
  elif lst[0] == "replace":
    t1 = str[0:a]
    t2 = str[a:b+1]
    t3 = str[b+1:len(str)]
    str = t1 + lst[3] + t3
  else:
    pass

Solution (Python):
x = list(input())
num = int(input())

for _ in range(num):
    v = input().split()
    order = v[0]
    if order == 'replace':
        a, b, c =v[1:]
        a, b = int(a), int(b)
        del x[a:b+1]
        for n, v in enumerate(list(c)):
            x.insert(a + n, v)
    elif order == 'print':
        a, b = map(int, v[1:])
        print(''.join(x[a:b+1]))
    elif order == 'reverse':
        a, b = map(int, v[1:])
        c = x[a:b+1]
        del x[a:b+1]
        for n, v in enumerate(reversed(list(c))):
            x.insert(a + n, v)

Solution (Python):
s = [*input()]
for _ in range(int(input())):
	l = input().split()
	a = int(l[1])
	b = int(l[2]) + 1
	if l[0] == 'print':
		print(*s[a:b], sep='')
	elif l[0] == 'reverse':
		s[a:b] = reversed(s[a:b])
	elif l[0] == 'replace':
		s[a:b] = l[3]

Solution (Python):
x = input()
kaisu =int(input())

for i in range(0, kaisu):
    y = input()
    y = y.split()

    a = int(y[1])
    b = int(y[2]) + 1

    if y[0] == "print":
        print(x[a:b])

    elif y[0] == "replace":
        x = x[0:a] + y[3] + x[b:]

    elif y[0] == "reverse":
        c = x[a:b]
        c = c[::-1]
        x = x[0:a] + c + x[b:]

Solution (Python):

def originalPrint(text,start,end):
    print(text[start: end])
    
def originalReverse(text,start,end):
    head = (text[:start])
    target = (text[start:end])
    sliced = target
    reversed_text = sliced[::-1]
    tail = text[end:]
    
    text = head+reversed_text+tail
    return text
    
def orignalReplace(text,start,end, replace_text):
    head = (text[:start])
    tail = text[end:]
    
    text = head+replace_text+tail
    return text

text = input()
num = int(input())

for i in range(num):
    order_info = input().split()
    order = order_info[0]
    start = int(order_info[1])
    end = int(order_info[2]) + 1
    if order == 'print':
        originalPrint(text, start, end)
    elif order == 'reverse':
        text = originalReverse(text, start, end)
    elif order == 'replace':
        replace_text = order_info[3]
        text = orignalReplace(text, start, end,replace_text)

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    command = input().split()
    c1, c2 = int(command[1]), int(command[2])+1
    if command[0] == 'print':
        print(s[c1:c2])
    elif command[0] == 'reverse':
        s0 = list(s[c1:c2])
        s0.reverse()
        s1 = ''.join(s0)
        s = s[:c1]+s1+s[c2:]
    elif command[0] == 'replace':
        s = s[:c1]+command[3]+s[c2:]

Solution (Python):




s =input()
n = int(input())

for i in range(n):
    data = list(input().split())
    
    if data[0] == "print":
        print(s[int(data[1]):int(data[2]) + 1] )
    elif data[0] == "reverse":
        rs = s[int(data[1]):int(data[2]) + 1]
        rs = rs[::-1]
        s = s[:int(data[1])] + rs + s[int(data[2]) + 1:]
    else:
        s = s[:int(data[1])] + data[3] + s[int(data[2]) + 1:]

Solution (Python):
s=input()
for i in [0]*int(input()):
    x=input().split()
    a=int(x[1])
    b=int(x[2])+1
    if x[0]=='print':
        print(s[a:b])
    elif x[0]=='replace':
        s=s[:a]+x[3]+s[b:]
    else:
        s=s[:a]+s[a:b][::-1]+s[b:]

Solution (Python):
string = input()

loop = int(input())

data = []

for i in string:
	data.append(i)

for i in range(loop):
	operate = input().split()

	if operate[0] == "replace":
		a = int(operate[1])
		b = int(operate[2])
		trans = []
		for i in operate[3]:
			trans.append(i)
		ope = 0
		for i in range(a, b+1):
			data[i] = trans[ope]
			ope += 1
	elif operate[0] == "reverse":
		a = int(operate[1])
		b = int(operate[2])
		trans = []
		for i in range(a,b+1):
			trans.append(data[b-i+a])

		ope = 0

		for i in range(a, b+1):
			data[i] = trans[ope]
			ope += 1

	else:	
		a = int(operate[1])
		b = int(operate[2])
		for i in range(a, b+1):
			print(data[i], end = "")
		print()

Solution (Python):
str = input()
q = int(input())

for i in range(q):
    s = input().strip().split()
    
    start = int(s[1])
    end = int(s[2])+1    

    if s[0] == 'print':
        print(str[start:end])
        
    if s[0] == 'reverse':
        str = list(str)
        str[start:end] = reversed(str[start:end])
        str = ''.join(str)
        
    if s[0] == 'replace':
        str = list(str)
        str[start:end] = list(s[3])
        str = ''.join(str)

Solution (Python):
line = input()
N = int(input())
 
for loop in range(N):
 
    input_str = list(input().split())
 
    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]
 
    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]
 
    else: 
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()

Solution (Python):
str = input()
q = int(input())

for i in range(q):
        buff = input()
        index = -1
        lst = []
        while True:
                jndex = buff.find(" ", index + 1)
                if jndex == -1:
                        lst.append(buff[index + 1 :])
                        break
                lst.append(buff[index + 1 : jndex])
                index = jndex
        
        lst[1] = int(lst[1])
        lst[2] = int(lst[2])

        if lst[0] == "print":
                print(str[lst[1]:lst[2]+1])
        elif lst[0] == "reverse":
                str = str[:lst[1]] + str[lst[1]:lst[2]+1][::-1] + str[lst[2]+1:]
        elif lst[0] == "replace":
                str = str[:lst[1]] + lst[3] + str[lst[2]+1:]

Solution (Python):
inp = list(input()) 
count = int(input())

for i in range(count):
    command = list(input().split())
    
    if command[0] == "print":
        a = int(command[1])
        b = int(command[2])
        print("".join(inp[a:b+1]))
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2])
        inp[a:b+1] = reversed(inp[a:b+1])
        
    elif command[0] == "replace":
        a = int(command[1])
        b = int(command[2])
        inp[a:b+1] = command[3]

Solution (Python):
w = input()
N = int(input())

for i in range(N):
    ilist = input().split()
    a = int(ilist[1])
    b = int(ilist[2])

    if ilist[0] == 'print':
        print(w[a:b+1])
    elif ilist[0] == 'reverse':
        w = w[:a] + w[a:b+1][::-1] + w[b+1:]
    else:
        w = w[:a] + ilist[3] + w[b+1:]