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):
import sys
input = sys.stdin.readline

def main():
    s = input().strip()
    N = int(input())
    for i in range(N):
        t = input().strip().split()
        a = int(t[1])
        b = int(t[2])
        if t[0][0] == "p":
            print(s[int(t[1]):int(t[2])+1])
        elif t[0][2] == "p":
            s = s[:a] + t[3] + s[b+1:]
        else:
            s = s[:a] + s[a:b+1][::-1] + s[b+1:]

if __name__ == "__main__":
    main()

Solution (Python):
s = input()
q = int(input())
order_list = list()
for i in range(q):
    order = list(map(str,input().split()))
    order_list.append(order)

for order in order_list:
    a = int(order[1])
    b = int(order[2])
    if order[0] == "print":
        print(s[a:b+1])
    elif order[0] == "reverse":
        s_rv = s[a:b+1]
        s_rv = s_rv[::-1]
        s = s.replace(s[a:b+1], s_rv)
    elif order[0] == "replace":
        s_part = s[a:b+1]
        s_part = s_part.replace(s[a:b+1], order[3])
        s = s[:a] + s_part + s[b+1:]

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

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

for i in range(N):
    o = [x for x in input().split()]

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

    if o[0] == "print":
        print(s[a:b])
    if o[0] == "replace":
        s = s[:a] + o[3] + s[b:]
    if o[0] == "reverse":
        tmp = s[a:b]
        s = s[:a] + tmp[::-1] + s[b:]

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

Solution (Python):

lst = input()
count = int(input())
for i in range(count):
    t = input().split()
    a = int(t[1])
    b = int(t[2])
    if t[0] == 'print':
        print(lst[a:b+1])

    elif t[0] == 'replace':
        lst = lst[0 : a] + t[3] + lst[b + 1 :]

    elif t[0] == "reverse":
        lst = lst[0:a] + lst[a:b+1][::-1] + lst[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):
s=str(input())
n=int(input())
c1=0
c2=0
for i in range(n):
    c=list(input().split())

    if c[0]=="replace":
        l=s[:int(c[1])]
        r=s[int(c[2])+1:]
        s=str(l)+c[3]+str(r)


    elif c[0]=="reverse":
        l=s[:int(c[1])]
        r=s[int(c[2])+1:]
        s=str(l)+s[int(c[1]):int(c[2])+1][::-1]+str(r)            
    else:
        for i in range(int(c[1]),int(c[2])+1):
            print(s[i],end="")
        print("")

Solution (Python):
S = list(input())
N = int(input())
for _ in range(N):
    Q = input().split()
    if Q[0] == "print":
        si = int(Q[1])
        ei = int(Q[2])
        print(*S[si: ei + 1], sep="")
    elif Q[0] == "reverse":
        si = int(Q[1])
        ei = int(Q[2])
        S[si:ei+1] = S[si:ei+1][::-1]
        
    elif Q[0] == "replace":
        si = int(Q[1])
        ei = int(Q[2])
        S[si: ei + 1] = list(Q[3])

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

n = int(input())
orders = [list(input().split()) for i in range(n)]
for order in orders:
  if order[0] == "print":
    print("".join(word[int(order[1]):int(order[2])+1]))
  elif order[0] == "replace":
    replace_word = list(order[3])
    for i in range(len(replace_word)):
      word[int(order[1]) + i] = replace_word[i]
  elif order[0] == "reverse":
    reverse_word = list(reversed(word[int(order[1]):int(order[2])+1]))
    count = 0
    for j in range(int(order[1]),int(order[2])+1):
      word[j] = reverse_word[count] 
      count += 1

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

for _ in range(n):
    O = input().split()
    o = O[0]
    a = int(O[1])
    b = int(O[2])
    if o == 'print':
        print(''.join(S[a:b+1]))
    elif o == 'replace':
        S[a:b+1] = list(O[3])
    elif o == 'reverse':
        S[a:b+1] = reversed(S[a:b+1])

Solution (Python):
s = 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(s[a:b + 1])
    elif command[0] == "reverse":
        t = s[a:b + 1]
        t = t[::-1]
        s = s[:a] + t + (s[b + 1:])
    elif command[0] == "replace":
        s = s[:a] + command[3] + s[b + 1:]

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

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

Solution (Python):
string = input()
n = int(input())
for i in range(n):
    command = list(input().split())
    if command[0] == "print":
        print(string[int(command[1]):int(command[2])+1])
    elif command[0] == "reverse":
        tmp1 = string[:int(command[1])]
        tmp2 = string[int(command[1]):int(command[2])+1]
        tmp2 = tmp2[::-1]
        tmp1 += tmp2
        tmp1 += string[int(command[2])+1:]
        string = tmp1
    elif command[0] == "replace":
        tmp = string[:int(command[1])]
        tmp += command[3]
        tmp += string[int(command[2])+1:]
        string = tmp

Solution (Python):
str = input()
q = int(input())
for i in range(q):
    method, a, b, *p = input().split()

    if method == "print":
        print(str[int(a) : int(b) + 1])
    elif method == "reverse":
        pre = str[: int(a)]
        reverse = str[int(a) : int(b) + 1][::-1]
        after = str[int(b) + 1 :]
        str = pre + reverse + after
    elif method == "replace":
        pre = str[: int(a)]
        after = str[int(b) + 1 :]
        str = pre + "".join(p) + after

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

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

for _ in range(n):
    quary = list(map(str,input().split()))
    if quary[0] == "print":
        print(s[int(quary[1]):int(quary[2])+1])
    if quary[0] == "replace":
        s = s[0:int(quary[1])] + quary[3] + s[int(quary[2])+1:]
    if quary[0] == "reverse":
        s = s[0:int(quary[1])] + ''.join(list(reversed(s[int(quary[1]):int(quary[2])+1]))) + s[int(quary[2])+1:]

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

Solution (Python):
s = input()
s_lst = []
for i in s:
    s_lst.append(i)
q = int(input())
order = [0] * q
for i in range(q):
    order[i] = input().split()
    order[i][1] = int(order[i][1])
    order[i][2] = int(order[i][2])
for i in range(q):
    if order[i][0] == "print":
        s = "".join(s_lst)
        
        print(s[order[i][1]:order[i][2]+1])
    elif order[i][0] == "reverse":
        for j in range((order[i][2]-order[i][1]+1)//2):
            s_lst[order[i][1]+j], s_lst[order[i][2]-j] = s_lst[order[i][2]-j], s_lst[order[i][1]+j]
        
    elif order[i][0] == "replace":
        for j in range(len(order[i][3])):
            s_lst[order[i][1] + j] = order[i][3][j]

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

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

    if lis[0] == "print":
        print(s[a : b + 1])
    elif lis[0] == "replace":
        p = lis[3]
        s = s[:a] + p + s[b + 1 :]
    else:  
        slice = (s[a : b + 1])[::-1]
        s = s[:a] + slice + s[b + 1 :]

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

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

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

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

Solution (Python):
s = input()

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

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    command = input().split()
    (a, b) = map(lambda x: int(x), command[1:3])
    s1, s2, s3 = s[:a], s[a:b + 1], s[b + 1:]
    if command[0] == "print":
        print(s2)
    elif command[0] == "reverse":
        s = s1 + s2[::-1] + s3
    elif command[0] == "replace":
        s = s1 + command[3] + s3

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

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

Solution (Python):
s = input()
for i in range(int(input())):
  code = input().split()
  if 'print'==code[0]:
    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:]
  else:
    s = s[:int(code[1])] + str(code[3]) + s[int(code[2])+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 order[0] == "print" :
        print(s[a : b + 1])
    if order[0] == "replace" :
        s = s[:a] + order[3] + s[b + 1:]
    if order[0] == "reverse" :
        s_reverse = s[a : b + 1]
        s = s[:a] + s_reverse[::-1] + s[b + 1:]

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

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

Solution (Python):
s = input()
q = int(input())
l = [input().split() for _ in range(q)]

for i in range(q):
    a = int(l[i][1])
    b = int(l[i][2])
    if l[i][0] == "replace":
        s = s[:a] + l[i][3] + s[b+1:]
    elif l[i][0] == "reverse":
        if a == 0:
            s = s[b::-1] + s[b+1:]
        else:
            s = s[:a] + s[b:a-1:-1] + s[b+1:]
    else:
        print(s[a:b+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):
s = input()
n = int(input())

for _ in range(n):
    t = input().split()
    t1 = int(t[1])
    t2 = int(t[2])
    tmp = s[t1:t2+1]
    if t[0] == 'replace':
        s = s[:t1] + t[3] + s[t2+1:]
    elif t[0] == 'reverse':
        s = s[:t1] + tmp[::-1] + s[t2+1:]
    elif t[0] == 'print':
        print(tmp)

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()
for _ in range(int(input())):
    *t, = map(str, input().split())
    t.append("")
    c = t.pop(0)
    a = int(t.pop(0))
    b = int(t.pop(0))
    *p, = t.pop(0)

    if c == "print":
        print("".join(s[a:b+1]))
    elif c == "reverse":
        s = s[:a]+list(reversed(s[a:b+1]))+s[b+1:]
    elif c == "replace":
        s = s[:a]+p+s[b+1:]

Solution (Python):
s = list(input())
n = int(input())
op_l = list(input().split() for _ in range(n))

for op in op_l:
    a = int(op[1])
    b = int(op[2])
    if op[0] == 'print':
        print(*s[a:b+1], sep='')
    elif op[0] == 'reverse':
        tmp = list(s[a:b+1])
        cnt = 0
        for i in range(a, b+1):
            cnt += 1
            s[i] = tmp[-cnt]
    elif op[0] == 'replace':
        xx = list(op[3])
        cnt = 0
        for i in range(a, b+1):
            s[i] = xx[cnt]
            cnt += 1

Solution (Python):
inp = input()
n = int(input())
for i in range(n):
    od = input().split()
    
    inp = list(inp)

    if (od[0] == "replace"):
        inp[int(od[1]):int(od[2])+1] = od[3]
        
    if (od[0] == "reverse"):
        ss = inp[int(od[1]):int(od[2])+1].copy()
        ss.reverse()
        
        inp[int(od[1]):int(od[2])+1] = ss
        

    if (od[0] == "print"):
        print("".join(inp[int(od[1]):int(od[2])+1]))

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

    if a[0]=="replace":
        tmp=str()
        for j in range(0,int(a[1])):
            tmp+=s[j]
        tmp+=a[3]
        for j in range(int(a[2])+1,len(s)):
            tmp+=s[j]
        s=tmp

    elif a[0]=="reverse":
        tmp=str()
        for j in range(0,max(0,int(a[1]))):
            tmp+=s[j]
        for j in reversed(range(int(a[1]),int(a[2])+1)):
            tmp+=s[j]
        for j in range(int(a[2])+1,len(s)):
            tmp+=s[j]
        s=tmp

    else:
        ans=str()
        for j in range(int(a[1]),int(a[2])+1):
            ans+=s[j]
        print(ans)

Solution (Python):
str = input()

q = int(input())

for i in range(q):
    
    command = input().split()
    
    if command[0] == 'replace':
        a, b, p = command[1:]
        str = str[:int(a)] + p + str[int(b) + 1:]
        
    elif command[0] == 'reverse':
        a, b = [int(x) for x in command[1:]]
        str = str[:a] + ''.join(list(reversed(str[a:b + 1]))) + str[b + 1:]
        
    elif command[0] == 'print':
        a, b = [int(x) for x in command[1:]]
        print(str[a:b + 1])

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

for i in range(n):
    inputs = input().split()
    if inputs[0] == 'print':
        s = int(inputs[1])
        e = int(inputs[2])
        print(txt[s:e+1])
    elif inputs[0] == 'reverse':
        s = int(inputs[1])
        e = int(inputs[2])
        t_r = txt[s:e+1]
        t_r = t_r[::-1]
        txt = txt[:s] + t_r + txt[e+1:]
    elif inputs[0] == 'replace':
        s = int(inputs[1])
        e = int(inputs[2])
        rep = inputs[3]
        txt = txt[:s] + rep + txt[e+1:]

Solution (Python):
string=input()
n=int(input())
for i in range(n):
    order=list(input().split())
    start=int(order[1])
    end=int(order[2])
    if order[0]=="print":
        print(string[start:end+1])
    elif order[0]=="replace":
        string=string[:start]+order[3]+string[end+1:]
    elif order[0]=="reverse":
        if start!=0:
            string=string[:start]+string[end:start-1:-1]+string[end+1:]
        else:
            string=string[:end+1][::-1]+string[end+1:]

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

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

answer = []

for i in range(q):
    line = input().split()

    if line[0] == "print":
        a = int(line[1])
        b = int(line[2])
        answer.append(inp[a:(b + 1)])
    elif line[0] == "reverse":
        a = int(line[1])
        b = int(line[2])
        reverseStr = inp[a:(b + 1)]
        inp = inp[:a] + reverseStr[::-1] + inp[(b + 1):]
    elif line[0] == "replace":
        a = int(line[1])
        b = int(line[2])
        p = line[3]
        inp = inp[:a] + p + inp[(b + 1):]

[print(answer[i]) for i in range(len(answer))]

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

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

Solution (Python):
str = input()
q = int(input())
for i in range(q):
 c = input().split()
 if c[0] == 'print':
  a,b = list(map(int,c[1:3]))
  print(str[a:b+1])
 elif c[0] == 'reverse':
  a,b = list(map(int,c[1:3]))
  str = str[:a]+''.join(reversed(str[a:b+1]))+str[b+1:]
 elif c[0] == 'replace':
  a,b = list(map(int,c[1:3]))
  p = c[3]
  str = str[:a]+p+str[b+1:]

Solution (Python):

input_data = list(input())
processing = int(input())


for i in range(processing):
    order = input().split()
    if order[0] == "print":
        print("".join(input_data[int(order[1]):int(order[2])+1]))
    elif order[0] == "reverse":
        reverse_data = (input_data[int(order[1]):int(order[2])+1])
        reverse_data.reverse()
        input_data = input_data[0:int(order[1])] + reverse_data + input_data[int(order[2])+1:]
    elif order[0] == "replace":
        input_data = input_data[0:int(order[1])] + list(order[3]) + input_data[int(order[2])+1:]

Solution (Python):
S = input()
N = int(input())
for n in range(N):
    *w, = input().split()
    a, b = int(w[1]), int(w[2])
    if w[0] == 'replace':
        r = w[3]
        S = S[:a]+r+S[b+1:]
    if w[0] == 'reverse':
        S = S[:a]+S[a:b+1][::-1]+S[b+1:]
    if w[0] == 'print':
        print(S[a:b+1])

Solution (Python):
instr = list(str(input()))
num = int(input())
for i in range(num):
    comm = list(input().split())
    if str(comm[0]) =='replace':
        instr[int(comm[1]):int(comm[2])+1]=str(comm[3])
    elif str(comm[0]) =='reverse':
        instr[int(comm[1]):int(comm[2])+1]=list(reversed(instr[int(comm[1]):int(comm[2])+1]))
    elif str(comm[0]) =='print':
        print("".join(instr[int(comm[1]):int(comm[2])+1]))

Solution (Python):
string = input()
rep = int(input())
for i in range(rep):
    l = input().split()
    query = l[0]
    a = int(l[1])
    b = int(l[2])

    if   query == "print":
        print(string[a:b+1])
    elif query == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string [b+1:]
        
    elif query == "replace":
        p = l[3]
        string = string[:a] + p + string [b+1:]

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

Solution (Python):
def my_print(str, a, b):
  print(str[a:b + 1])
  return str

def my_replace(str, a, b, p):
  return str[:a] + p + str[b + 1:]

def my_reverse(str, a, b):
  r_str = str[a:b + 1][::-1]
  return str[:a] + r_str + str[b + 1:]

str = input()

for i in range(int(input())):
  cmd, *args = input().split(' ')
  args = [int(i) for i in args[0:2]] + args[2:]
  str = globals()['my_' + cmd](str, *args)

Solution (Python):
def print2(s, a, b):
    print(s[a:b+1])
    return s

def reverse2(s, a, b):
    if a == 0:
        return s[b::-1] + s[b+1:]
    else:
        return s[:a] + s[b:a-1:-1] + s[b+1:]
   
def replace2(s, a, b, p):
    return s[:a] + p + s[b+1:]

s = input()
q = int(input())
for i in range(q):
    lst = input().split()
    a = int(lst[1])
    b = int(lst[2])
    if len(lst) == 4:
        p = lst[3]
        s = eval(lst[0] + "2(s, a, b , p)")
    else:
        s = eval(lst[0] + "2(s, a, b)")

Solution (Python):


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


for i in range(n):
    let = list(map(str,input().split()))
    if let[0] == "replace":
        s = s[:int(let[1])] + let[3] + s[int(let[2])+1:]
        
    elif let[0] == "reverse":
        ss = s[int(let[1]):int(let[2])+1]
        s = s[:int(let[1])] + ss[::-1] + s[int(let[2])+1:] 
        
    elif let[0] == "print":
        print(s[int(let[1]):int(let[2])+1])

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

Solution (Python):
s = input()
c = int(input())
for i in range(c):
    nums = [str(e) for e in input().split()]
    nums[1] = int(nums[1])
    nums[2] = int(nums[2]) + 1
    if nums[0] == "print":
        print(s[nums[1]:nums[2]])
    if nums[0] == "reverse":
        s = s.replace(s[nums[1]:nums[2]],s[nums[1]:nums[2]][::-1])
    if nums[0] == "replace":
        s = list(s)
        s[nums[1]:nums[2]] = nums[3]
        s = "".join(s)

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

for x in range(xLoop):
    xCmd= input()
    if xCmd[0:7] == 'replace':
        xCmd,a,b,p = xCmd.split()
        a = int(a)
        b = int(b)
        if a == 0:
            str = p + str[b+1:len(str)]
        else:
            str = str[0:a] + p + str[b+1:len(str)]
        
    elif xCmd[0:7] == 'reverse':
        xCmd,a,b = xCmd.split()
        a = int(a)
        b = int(b)
        p = str[a:b+1]
        p = p[::-1]
        if a == 0:
            str = p + str[b+1:len(str)]
        else:
            str = str[0:a] + p + str[b+1:len(str)]

    else:
        xCmd,a,b = xCmd.split()
        a = int(a)
        b = int(b)+1
        print(str[a:b])

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

for _ in range(q):
    
    order = input().split()
    
    command = order[0]
    n = int(order[1])
    m = int(order[2])
    
    if command == "print":
        print(s[n:m+1])
    elif command == "reverse":
        r = ''.join(list(reversed(s[n:m+1])))
        s = s[:n] + r + s[m+1:]

    elif command == "replace":
        s = s[:n] + order[-1] + s[m+1:]

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

Solution (Python):

inpstr = input()


q = int(input())


for i in range(q):
    order = input()
    order_list = [j for j in order.split(" ")]
    order_txt = order_list[0]
    if order_txt == "replace":
        rplc1 = int(order_list[1])
        rplc2 = int(order_list[2])
        rplcstr = order_list[3]
        inpstr = inpstr[:rplc1] + rplcstr + inpstr[rplc2 + 1:]
    elif order_txt == "reverse":
        rvrs1 = int(order_list[1])
        rvrs2 = int(order_list[2])
        tmp_str = inpstr[rvrs1:rvrs2 + 1]
        rvrs_str = "".join(reversed(tmp_str))
        inpstr = inpstr[:rvrs1] + rvrs_str + inpstr[rvrs2 + 1:]
    else:
        prt1 = int(order_list[1])
        prt2 = int(order_list[2])
        print(inpstr[prt1:prt2 + 1])

Solution (Python):



if __name__ == "__main__":

    param = input()
    char = [c for c in param]

    n = int(input())

    for _ in range(n):

        command = input().split(" ")

        if   command[0] == "print":
            str = "".join(char[int(command[1]) : (int(command[2]) + 1)])
            print(str)
        elif command[0] == "reverse":
            part = char[int(command[1]):(int(command[2]) + 1)]
            part.reverse()
            char[int(command[1]):(int(command[2]) + 1)] = part[0:]
        elif command[0] == "replace":
            char[int(command[1]):int(command[2]) + 1] = command[3]
        else:
            pass

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):
class Transformation(object):

    def __init__(self, text):
        self.text = text

    def print(self, a, b):
        print(self.text[a:b+1])

    def reverse(self, a, b):
        target = self.text[a:b+1]
        target = target[::-1]
        self.text = self.text[:a] + target + self.text[b+1:]

    def replace(self, a, b, p):
        self.text = self.text[:a] + p + self.text[b+1:]


text = input()
t = Transformation(text)
q = int(input())
for i in range(q):
    commands = input().split()
    command = commands[0]
    a = int(commands[1])
    b = int(commands[2])
    if command == "print":
        t.print(a, b)
    elif command == "reverse":
        t.reverse(a, b)
    elif command == "replace":
        p = commands[3]
        t.replace(a, b, p)

Solution (Python):
str_in = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    start_num = int(command[1])
    end_num   = int(command[2])+1
    if command[0] == 'replace':
        rep = list(command[3])
        cnt = 0
        for j in range(start_num, end_num):
            str_in[j] = rep[cnt]
            cnt += 1
    elif command[0] == 'reverse':
        end_num -= 1
        while end_num > start_num:
            str_tmp = str_in[end_num]
            str_in[end_num] = str_in[start_num]
            str_in[start_num] = str_tmp
            end_num -= 1
            start_num += 1
    elif command[0] == 'print':
        for l in range(start_num, end_num):
            print(str_in[l], end="")
        print()
    else:
        pass

Solution (Python):
src = input()

request_n = int(input())

for _ in range(request_n):
    request_lst = input().split()
    
    command = request_lst[0]
    start = int(request_lst[1])
    end = int(request_lst[2])
    
    if command == "print":
        print(src[start:end + 1])
    
    elif command == "reverse":
        rev = src[start:end + 1]
        src = src[:start] + rev[::-1] + src[end + 1:]
    
    elif command == "replace":
        target = request_lst[3]
        src = src[:start] + target + src[end + 1:]

Solution (Python):
target_strings = input()
num_of_order = int(input())

for i in range(num_of_order):
    order = input().split(" ")
    if order[0] == "replace":
        target_strings = target_strings[:int(order[1])] + \
        order[3] + target_strings[int(order[2])+1:]
    
    elif order[0] == "reverse":
        string2 = target_strings[int(order[1]):int(order[2])+1]
        target_strings = target_strings[:int(order[1])] + \
        string2[::-1] +\
        target_strings[int(order[2])+1:]
       
    else:
        print(target_strings[int(order[1]):int(order[2]) + 1])

Solution (Python):
s=list(input())
n=int(input())
for i in range(n):
    inst=list(input().split())
    start=int(inst[1])
    end=int(inst[2])
    if(inst[0]=="print"):
        print(''.join(s[start:end+1]))
    elif(inst[0]=="replace"):
        for j in range(len(inst[3])):
            s[start+j]=inst[3][j]
    elif(inst[0]=="reverse"):
        rev=list(reversed(s[start:end+1]))
        for j in range(len(rev)):
            s[start+j]=rev[j]

Solution (Python):
letters = input()
times = int(input())

for t in range(times):
    s = input().split()
    l = s[0]
    a = int(s[1])
    b = int(s[2]) + 1

    if l == 'print':
        print(letters[a:b])
    
    elif l == 'replace':
        rl = s[3]
        first_part = letters[:a]
        last_part = letters[b:]
        letters = first_part + rl + last_part
        
    elif l == 'reverse':
        temp_letter = ''.join(reversed(letters[a:b]))
        letters = letters.replace(letters[a:b], temp_letter)