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):
s = input()
q = int(input())

for i in range(q):
    opt, *args = input().split()
    a = int(args[0])
    b = int(args[1])
    if opt == "print":
        print(s[a:b+1])
    elif opt == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif opt == "replace":
        p = args[2]
        s = s[:a] + p + s[b+1:]

Solution (Python):
str = str(input())
q = int(input())
for i in range(q):
    command, a, b, *p =input().split()
    a = int(a)
    b = int(b)
    p = ''.join(p)
    if command == 'print':
        print(str[a:b+1])

    elif command == 'reverse':
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    else:
        str = str[:a] + p +str[b+1:]

Solution (Python):
s = input()
for i in range (int(input())):
    order = input().split()
    a, b = int(order[1]), int(order[2])
    if "print" in order:
        print(s[a:b+1])
    elif "replace" in order:
        s = s[:a] + order[3] + s[b+1:]
    else:
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]

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

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

for _ in range(n):
    cmd = list(input().split())
    command, a, b = cmd[0], int(cmd[1]), int(cmd[2])
    if command == 'replace':
        str = str[:a] + cmd[3] + str[b+1:]
    elif command == 'reverse':
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    elif command == 'print':
        print(str[a:b+1])
    else:
        pass

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

Solution (Python):

text=input()
num_of_command=int(input())

for command_ID in range(num_of_command):
    command=input().split()
    start=int(command[1]);
    ed=int(command[2])+1;

    if command[0]=="replace":
        pre=text[:start]
        replace_text=command[3];
        after=text[ed:]
        text=pre+replace_text+after      
    elif command[0]=="reverse":
        text=text[:start]+text[start:ed][::-1]+text[ed:]
    elif command[0]=="print":
        print(text[start:ed])

Solution (Python):
S = input()
q = int(input())
L = []
for _ in range(q):
    Op = input().split()
    l, r = int(Op[1]), int(Op[2])
    if Op[0] == 'replace':
        S = S[:l] + Op[3] + S[r+1:]
    elif Op[0] == 'reverse':
        S = S[:l] + S[l:r+1][::-1] + S[r+1:]
    elif Op[0] == 'print':
        print(S[l:r+1])

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

for i in range(n):
    direction = input().split()
    
    if direction[0]=="replace":
        word = word[:int(direction[1])] + direction[3] + word[int(direction[2])+1:]
        
    elif direction[0]=="print":
        print(word[int(direction[1]):int(direction[2])+1])
        
    elif direction[0]=="reverse":
        word = word[:int(direction[1])] + word[int(direction[1]):int(direction[2])+1][::-1] + word[int(direction[2])+1:]

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

for i in range(n):
    s = input().split()

    if s[0] == 'print':
        a,b = int(s[1]),int(s[2])
        print(w[a:b+1])
    elif s[0] == 'reverse':
        a,b = int(s[1]),int(s[2])
        p = w[a:b+1][::-1]
        w = w[:a] + p + w[b+1:]
    elif s[0] == 'replace':
        a,b = int(s[1]),int(s[2])
        w = w[:a] + s[3] + w[b+1:]

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    
    s = input()
    n = int(input())
    for _ in range(n):
        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])
            s = s[:a] + t[3] + s[b + 1:]

main()

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

q = int(input())

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

  if order[0] == "print":
    output = [0 for j in range(b-a+1)]
    for j in range(b-a+1):
      output[j] = sent[a+j]
    print("".join(output))

  elif order[0] == "reverse":
    rev = [0 for j in range(b-a+1)]
    for k in range(b-a+1):
      rev[k] = sent[b-k]

    for l in range(b-a+1):
      sent[a+l] = rev[l]

  else:
    p = order[3]
    for j in range(b-a+1):
      sent[a+j] = p[j]

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

for _ in range(q):
    lst = list(input().split())
    command = lst[0]
    a = int(lst[1])
    b = int(lst[2])
    
    if command == "print":
        print(str[a:b+1])
    elif command == "reverse":
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    else:
        str = str[:a] + lst[3] + str[b+1:]

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

for _ in range(q):
    i = input().split()
    op, a, b = i[0], int(i[1]), int(i[2])
    
    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 = i[3]
        s = s[:a] + p + s[b+1:]

Solution (Python):
s=input()
q=int(input())
for i in range(q):
    order=input().split()
    a=int(order[1])
    b=int(order[2])
    if len(order[0])==5:
        print(s[a:b+1])
    elif len(order)==3:
        s=s[:a]+''.join(reversed(list(s[a:b+1])))+s[b+1:]
    else:
        s=s[:a]+order[3]+s[b+1:]

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

Solution (Python):
s = input()
q = int(input())
for i in range(q):
    o = list(map(str,input().split()))
    a,b = int(o[1]),int(o[2])
    if o[0] == "replace":
        s = s[:a] + o[3] +s[b+1:]
    elif o[0] == "reverse":
        c = s[a:b+1] 
        s = s[:a] + c[::-1] + s[b+1:]
    else:
        print(s[a:b+1])

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

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    t = input().split()
    a, b = map(int, t[1:3])
    if t[0] == 'print':
        print(s[a:b+1])
    elif t[0] == 'reverse':
        r = s[a:b+1]
        s = s[0:a] + r[::-1] + s[b+1:]
    else:
        p = t[3]
        s = s[0:a] + p + s[b+1:]

Solution (Python):
str=[i for i in input()]
n=int(input())
l= [input().split() for i in range(n)]
for i in range(n):
    if l[i][0]=="print":
        str = ''.join(str) 
        print(str[int(l[i][1]):int(l[i][2])+1])
        str = [i for i in str]         
    elif l[i][0]=="reverse":
        part_str=list(reversed(str[int(l[i][1]):int(l[i][2])+1]))
        str[int(l[i][1]):int(l[i][2])+1]=part_str
    else:
        replace_str=[j for j in l[i][3]]
        str[int(l[i][1]):int(l[i][2])+1]=replace_str

Solution (Python):
import sys
txt=input()
n=int(input())
for i in range(n):
    x=input().split()
    if x[0]=='print':
        print(txt[int(x[1]):int(x[2])+1])
    elif x[0]=='replace':
        txt=txt[:int(x[1])]+x[3]+txt[int(x[2])+1:]
    else:
        txt=txt[:int(x[1])]+''.join(reversed(txt[int(x[1]):int(x[2])+1]))+txt[int(x[2])+1:]

Solution (Python):
cord = input()
step = int(input())
for i in range(step):
    thread = input().split()
    if thread[0] == 'print':
        print(cord[int(thread[1]): int(thread[2])+1])
    elif thread[0] == 'replace':
        cord = cord[:int(thread[1])] + thread[3] + cord[int(thread[2])+1:]
    else:
        cord = cord[:int(thread[1])] + cord[int(thread[1]):int(thread[2])+1][::-1] + cord[int(thread[2])+1:]

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

Solution (Python):
a = str(input())
q = int(input())
for i in range(q):
    ope = list(map(str, input().split(" ")))
    if ope[0] == "replace":
        a_list = list(a)
        a = ""
        for i in range(int(ope[2])-int(ope[1])+1):
            del a_list[int(ope[1])]
        a_list.insert(int(ope[1]), ope[3])
        for i in a_list:
            a += i
    elif ope[0] == "reverse":
        new_a = a[int(ope[1]):int(ope[2])+1]
        a = a.replace(a[int(ope[1]):int(ope[2])+1], new_a[::-1])
    elif ope[0] == "print":
        print(a[int(ope[1]):int(ope[2])+1])

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

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

Solution (Python):
S = input()
n = int(input())
for i in range(n):
    line = input()
    line_len = len(line.split())
    
    if(line_len == 3):
        op,a,b = line.split()
    elif(line_len == 4):
        op,a,b,rep = line.split()
    a = int(a)
    b = int(b)
    if(op == "print"):
        print(S[a:b+1])
    elif(op == "replace"):
        tmp = S[0:a] + rep + S[b+1:]
        S = tmp
        
    elif(op == "reverse"):
        tmp = list(S[a:b+1])
        tmp.reverse()
        
        S = S[0:a] + "".join(tmp) + S[b+1:]

Solution (Python):
s = input()
q = int(input())
for _ in range(q):
    input_list = input().split()
    o = input_list[0]
    a = int(input_list[1])
    b = int(input_list[2])
    if len(input_list) == 4:
        p = input_list[3]
        s = s[:a] + p + s[b+1:]
    elif o == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else:
        print(s[a:b+1])

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

for i in range(n):
    command=input().split(" ")

    if command[0]=="replace":
        com1=int(command[1])
        com2=int(command[2])
        com3=list(command[3])
        list_str=list(str)
        for i in range(com1,com2+1):
            list_str[i]=com3[i-com1]
        str="".join(list_str)

    elif command[0]=="reverse":
        com1=int(command[1])
        com2=int(command[2])
        str2=str[com1:com2+1]
        com3=str2[::-1]
        str=str.replace(str[com1:com2+1],com3)

    else:
        com1=int(command[1])
        com2=int(command[2])
        print(str[com1:com2+1])

Solution (Python):
s = input()
q = int(input())
for i in range(q):
    m = list(map(str,input().split()))
    if m[0] == "print":
        print(s[int(m[1]):int(m[2])+1])
    elif m[0] == "reverse":
        sr = s[int(m[1]):int(m[2])+1]
        sr = sr[::-1]
        s1 = s[:int(m[1])]
        s2 = s[int(m[2])+1:]
        s = s1 + sr + s2
        
    elif m[0] == "replace":
        s1 = s[:int(m[1])]
        s2 = s[int(m[2])+1:]
        s = s1 + m[3] + s2

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

Solution (Python):
target = input()
num_operations = int(input())

for _ in range(num_operations):
    operation = input().split()
    operation_name = operation[0]
    frm, to = map(int, operation[1:3])
    if operation_name == 'replace':
        new = operation[3]
    
    if operation_name == 'print':
        print(target[frm:to+1])
    elif operation_name == 'reverse':
        reverse_target = target[frm:to+1]
        target = target[:frm] + reverse_target[::-1] + target[to+1:]
    elif operation_name == 'replace':
        target = target[:frm] + new + target[to+1:]
    else :
        raise Exception

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

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

for i in range(q):
    x, a, b, *p = input().split()
    a = int(a)
    b = int(b)

    if x == 'replace':
        str = str[:a]+p[0] +str[b+1:]

    elif x == 'reverse':
        tmp = str[a:b+1]
        str = str[:a]+tmp[::-1]+str[b+1:]

    elif x == 'print':
        print(str[a:b+1])

Solution (Python):


from collections import Counter,deque


from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
n=int(input().rstrip())
for _ in range(n):
    c,*x=input().split()
    if c=="print":
        print(s[int(x[0]):int(x[1])+1])
    elif c=="reverse":
        s=s[:int(x[0])]+s[int(x[0]):int(x[1])+1][::-1]+s[int(x[1])+1:]
    else:
        s=list(s)
        t=x[2]
        l=0
        for i in range(int(x[0]),int(x[1])+1):
            s[i]=t[l]
            l+=1
        s="".join(s)

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

Solution (Python):

text = input()
num = int(input())
orders = []
for i in range(num):
    orders.append(input().split())


for order in orders:
    r1 = int(order[1])
    r2 = int(order[2])
    if order[0] == 'print':
        print(text[r1:r2+1])
    elif order[0] == 'reverse':
        if r1 == 0:
            text = text[:r1] + text[r2::-1] + text[r2+1:]
        else:
            text = text[:r1] + text[r2:r1-1:-1] + text[r2+1:]
    elif order[0] == 'replace':
        text = text[:r1] + order[3] + text[r2+1:]

Solution (Python):
s = list(input())
for _ in range(int(input())):
    li = input().split()
    li[1] = int(li[1])
    li[2] = int(li[2]) + 1
    if li[0] == "print":
        print("".join(s[li[1]:li[2]]))
    elif li[0] == "reverse":
        s[li[1]:li[2]] = s[li[1]:li[2]][::-1]
    else:
        s[li[1]:li[2]] = li[3]

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    line = input().split()
    a = int(line[1])
    b = int(line[2])

    if line[0] == 'replace':
        to = line[3]
        s = s[0:a] + to + s[b + 1:]
    elif line[0] == 'reverse':
        s = s[0:a] + ''.join(reversed([c for c in s[a:b+1]])) + s[b + 1:]
    else:
        print(s[a:b + 1])

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

Solution (Python):
s=input()
for i in range(int(input())):
    t=input().split()
    opr=t[0];a=int(t[1]);b=int(t[2])
    if t[0]=='print':
        print(s[a:b+1])
    elif t[0]=='reverse':
        s=s[:a]+''.join(list(reversed(s[a:b+1])))+s[b+1:]
    elif t[0]=='replace':
        p=t[3]
        s=s[:a]+p+s[b+1:]

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

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

Solution (Python):
str = input()
num = int(input())
for i in range(num):
    line = input()
    if line.startswith("print"):
        op,a,b = line.split()
        print(str[int(a):int(b)+1])
    elif line.startswith("replace"):
        op,a,b,c = line.split()
        x = str[0:int(a)]
        y = c
        z = str[int(b)+1:]
        str = x + y +z
    elif line.startswith("reverse"):
        op,a,b = line.split()
        x = str[0:int(a)]
        y = str[int(a):int(b)+1]
        y = y[::-1]
        z = str[int(b)+1:]
        str = x + y + z

Solution (Python):
str_normal = input()
str = [i for i in str_normal]
for k in range(int(input())):
	list = [i for i in input().split()]
	
	if list[0]=="print":
		a =int(list[1])
		b =int(list[2])
		str_print=[]
		for i in range(a,b+1):
			str_print +=str[i] 
		print("".join(str_print))
	
	if list[0]=="reverse":
		a =int(list[1])
		b =int(list[2])
		str_a = str[a:b+1]
		str_a.reverse()
		cnt = 0
		for i in range(a,b+1):
			str[i] = str_a[cnt]
			cnt+=1
		
	if list[0]=="replace":
		a =int(list[1])
		b =int(list[2])
		p =list[3]
		p_list=[i for i in p]
		cnt =0
		for i in range(a,b+1):
			str[i]= p_list[cnt]
			cnt+=1

Solution (Python):
str=input()
q = int(input())
for i in range(q):
    s = input().split()

    command = s[0]
    a=int(s[1])
    b=int(s[2])

    if command=="print":
        print(str[a:b+1])
    elif command=="reverse":
        restr=str[a:b+1]
        restr=restr[::-1]
        str = str[:a]+restr+str[b+1:]
        
    elif command=="replace":
        p=s[3]
        str = str[:a]+p+str[b+1:]

Solution (Python):


s = input()
lenS = len(s)
q = int(input())
for i in range(q):
    temp = list(map(str, input().split()))
    idxA = int(temp[1])
    idxB = int(temp[2])
    if temp[0] == 'print':
        print(s[idxA:idxB + 1])
    else:
        head = s[:idxA]
        tail = s[idxB + 1:]
        if temp[0] == 'replace':
            body = temp[3]
        else:
            body = s[idxA:idxB + 1]
            body = body[::-1]
        s = head + body + tail

Solution (Python):
def test():

	str = input()
	n = int(input())

	for i in range(n):

		operation = input().split()

		a = int(operation[1])
		b = int(operation[2])

		if operation[0] == "print":
			print(str[a:b+1])

		elif operation[0] == "reverse":
			if a != 0:
				str = str[0:a] + str[b:a-1:-1] + str[b+1:len(str)]
			else:
				str = str[b::-1] + str[b+1:len(str)]

		elif operation[0] == "replace":
			p = operation[3]
			str = str[0:a] + p + str[b+1:len(str)]


if __name__ == "__main__":
	test()

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

for i in range(n):
    orders = input().split()
    order, a, b, *moji = orders
    a = int(a)
    b = int(b)
    
    if order == "print":
        print(''.join(s[a:b+1]))
    elif order == 'reverse':
        s[a:b+1] = s[a:b+1][::-1]
    else:
        s[a:b+1] = moji[0]

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

for _ in range(n):
    lis = input().split()
    if lis[0] == "replace":
        s = s[:int(lis[1])] + lis[3] + s[int(lis[2])+1:]
    elif lis[0] == "reverse":
        s = s[:int(lis[1])] + s[int(lis[1]):int(lis[2])+1][::-1] + s[int(lis[2])+1:]
    else:
        print(s[int(lis[1]):int(lis[2])+1])

Solution (Python):
s = input()
n = int(input())
for _ in range(n):
    r, a, b, *p = input().split()
    a = int(a)
    b = int(b) + 1 
    if r == "replace":
        s = s[:a] + p[0] + s[b:]
    elif r == "reverse":
        s = s[:a] + s[a:b][::-1] + s[b:]
    elif r == "print":
        print(s[a:b])
    else:
        print("unknown")

Solution (Python):


def pri(s,f,l):
	for i in range(f,l+1):
		print(s[i],end="")
	print()

def rev(s,f,l):
	while f < l:
		tmp=s[f]
		s[f]=s[l]
		s[l]=tmp
		f+=1
		l-=1

def rep(s,f,l,p):
	for i in range(l-f+1):
		s[f+i]=p[i]

s=list(input())

for i in range(int(input())):
	x=input().split()
	x[1]=int(x[1])
	x[2]=int(x[2])
	if "print" == x[0]:
		pri(s, x[1], x[2])
	elif "reverse" == x[0]:
		rev(s, x[1], x[2])
	elif "replace" == x[0]:
		rep(s, x[1], x[2], list(x[3]))

Solution (Python):

import sys
line = sys.stdin.readline() 
word = line.rstrip('\r\n') 
sys.stdin.readline() 
while True:
    if not line: break 
    line = sys.stdin.readline() 
    line = line.rstrip('\r\n') 
    words = line.split()
    if len(line) == 0:
        break   
    else:
        words = line.split()
        if words[0] == "print":
            a = int(words[1])
            b = int(words[2])
            print(word[a:b+1])
        elif words[0] == "reverse":
            a = int(words[1])
            b = int(words[2])
            rep = ""
            for i in range(b,a-1,-1):
                rep += word[i]
            word = word[:a] + rep + word[b+1:] 
        elif words[0] == "replace":
            a = int(words[1])
            b = int(words[2])
            word = word[:a] + words[3] + word[b+1:]

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    a, b = int(cmd[1]), int(cmd[2])
    if cmd[0] == 'print':
        print(s[a:b + 1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b + 1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + 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 = input()
q = int(input())
insts = [input().split() for _ in range(q)]
 
for inst in insts:
    a, b = int(inst[1]), int(inst[2]) + 1
    if inst[0] == "replace":
        p = inst[3]
        s = s[:a] + p + s[b:]
    elif inst[0] == "reverse":
        s = s[:a] + s[a:b][::-1] + s[b:]
    elif inst[0] == "print":
        print(s[a:b])

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

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 = list(input())
for _ in [0]*int(input()):
    cmd, a, b, *p = input().split()
    a = int(a); b = int(b) + 1
    if cmd == 'print':
        print(*s[a:b], sep='')
    if cmd == 'reverse':
        s[a:b] = reversed(s[a:b])
    if cmd == 'replace':
        s[a:b] = p[0]

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())):
    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 = list(str(input()))
q = int(input())
o = ['']*q
for i in range(q):
    o[i] = str(input())
     
for i in range(q):
    order = o[i].split(' ')
    if order[0] == 'print':
        a,b = int(order[1]),int(order[2])
        for i in range(a,b+1):
            print(s[i],end = '')
        print('')
 
    elif order[0] == 'reverse':
        a,b = int(order[1]),int(order[2])
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp        
         
    elif order[0] == 'replace':
        a,b,p = int(order[1]),int(order[2]),list(order[3])
        for i in range(b-a+1):
            s[a+i] = p[i]

Solution (Python):
s = input()
m = int(input())
for i in range(m):
    com, *lw = map(str, input().split())
    if com == "replace":
        s = s[:int(lw[0])] + lw[2] + s[int(lw[1]) + 1:]
    if com == "reverse":
        t = s[int(lw[0]):int(lw[1]) + 1]
        s = s[:int(lw[0])] + t[::-1] + s[int(lw[1]) + 1:]
    if com == "print":
        print(s[int(lw[0]):int(lw[1]) + 1])

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

s = S
for _ in range(0, N):
	C = input().split()
	l, r = int(C[1]), int(C[2]) + 1
	if C[0] == "replace":
		s = s[:l] + C[3] + s[r:]
	elif C[0] == "reverse":
		s = s[:l] + s[l:r][::-1] + s[r:]
	elif C[0] == "print":
		print(s[l:r])

Solution (Python):
def my_print(lst,a,b):
    for i in range(a,b+1):
        print(lst[i],end='')
    print()

def reverse(lst,a,b):
    lst2 = lst[a:b+1]
    lst2.reverse()
    lst[a:b+1] = lst2
    
    
str1 = list(input())
n = int(input())
for i in range(n):
    str2 = input().split()
    if str2[0]=='print':
        a,b = int(str2[1]),int(str2[2])
        my_print(str1,a,b)
    if str2[0]=='replace':
        a,b,p = int(str2[1]),int(str2[2]),str2[3]
        str1[a:b+1]=p
    if str2[0]=='reverse':
        a,b = int(str2[1]),int(str2[2])
        reverse(str1, a, b)

Solution (Python):
def splitString(target, start, end):
    first = target[:start]
    middle = target[start:end + 1]
    last = target[end + 1:]
    return (first, middle, last)

def doReplace(target, args):
    start = int(args[0])
    end = int(args[1])
    replace_str = args[2]

    first, _, last = splitString(target, start, end)

    return first + replace_str + last


def doReverse(target, args):
    start = int(args[0])
    end = int(args[1])

    first, middle, last = splitString(target, start, end)

    return first + middle[::-1] + last


def makeMessage(target, args):
    start = int(args[0])
    end = int(args[1])

    _, middle, _ = splitString(target, start, end)

    return middle


def transform():
    messages = []  
    target = input()
    q = int(input())

    for _ in range(q):
        line = input()
        cmd = line.split(' ')[0]
        args = line.split(' ')[1:]

        
        if cmd == 'print':
            messages.append(makeMessage(target, args))
        elif cmd == 'replace':
            target = doReplace(target, args)
        elif cmd == 'reverse':
            target = doReverse(target, args)
    
    [print(message) for message in messages]


def kantanna_test(expected, actual):
    if expected == actual:
        print('OK')
    else:
        print('NG')


if __name__ == '__main__':

    transform()

Solution (Python):
string = list(input())
q = int(input())
for _ in range(q):
    cmd = input().split()
    op = cmd[0]
    a, b = map(int, cmd[1:3])
    if op == "print":
        print("".join(string[a:b + 1]))
    elif op == "reverse":
        string = string[:a] + list(reversed(string[a:b + 1])) + string[b + 1:]
    elif op == "replace":
        for s in list(cmd[3]):
            string[a] = s
            a += 1

Solution (Python):
q_text = str(input())
q_num = int(input())

for i in range(q_num):
  q = input()
  if q.startswith("print"):
    command,a,b = q.split()
    a=int(a)
    b=int(b)
    print(q_text[a:b+1])
    
  elif q.startswith("reverse"):
    command,a,b = q.split()
    a=int(a)
    b=int(b)
    temp_text=q_text[a:b+1]
    q_text = q_text[:a] + temp_text[::-1] + q_text[b+1:]
    
  
  elif q.startswith("replace"):
    command,a,b,p = q.split()
    a=int(a)
    b=int(b)
    q_text = q_text[:a] + p + q_text[b+1:]

Solution (Python):
s = list(input())
q = int(input())
for i in range(q):
  
  r =list(map(str, input().split()))
  cmd = r[0]
  a = int(r[1])
  b = int(r[2])
  
  if cmd == "print":
    for j in range(a, b+1):
      print(s[j], end="")
    print("")
  elif cmd == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
  elif cmd == "replace":
    rep = list(r[3])
    count = 0
    for j in range(a,b+1):
      s[j] = rep[count]
      count = count + 1

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

for i 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):
def souhei(a,b):
	c=int(a)
	d=int(b)
	return [c, d]
moji=input()
moji=list(moji)
P=int(input())
for pp in range(P):
	some=list(input().split())
	if some[0]=='print':
		some[1],some[2]=souhei(some[1],some[2])
		for a in range(some[1],some[2]+1):
			if a==some[2]:
				print(moji[a])
			else:
				print(moji[a],end='')
	elif some[0]=='reverse':
		some[1],some[2]=souhei(some[1],some[2])
		nn=0
		m=int((some[1]+some[2])/2)
		for bb in range(some[1],m+1):
			X=moji[bb]
			moji[bb]=moji[some[2]-nn]
			moji[some[2]-nn]=X
			nn+=1	
	elif some[0]=='replace':
		some[1],some[2] = souhei(some[1],some[2])
		g=some[3]
		g=list(g)
		n=0
		for oo in range(some[1],some[2]+1):
			moji[oo]=g[n]
			n+=1

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