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):
def main():

    strTxt = input()
    n = int(input())
    for _ in range(n):
        strCmd = input().split()
        
        if strCmd[0] == 'print':
            funcPrint(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'reverse':
            strTxt = funcReverse(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'replace':
            strTxt = funcReplace(strTxt, int(strCmd[1]), int(strCmd[2]), strCmd[3])

def funcPrint(strInput: str,a: int,b: int):
    print(strInput[a:b+1])

def funcReverse(strInput: str,a: int,b: int):
    if a == 0:
        return strInput[b::-1]+strInput[b+1:]
    else:
        return strInput[:a]+strInput[b:a-1:-1]+strInput[b+1:]

def funcReplace(strInput: str,a: int,b: int, strAfter: str):
    return strInput[:a]+strAfter+strInput[b+1:]


if __name__ == '__main__':
    main()

Solution (Python):
def main():

    strTxt = input()
    n = int(input())
    for _ in range(n):
        strCmd = input().split()
        
        if strCmd[0] == 'print':
            funcPrint(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'reverse':
            strTxt = funcReverse(strTxt, int(strCmd[1]), int(strCmd[2]))
        elif strCmd[0] == 'replace':
            strTxt = funcReplace(strTxt, int(strCmd[1]), int(strCmd[2]), strCmd[3])

def funcPrint(strInput: str,a: int,b: int):
    print(strInput[a:b+1])

def funcReverse(strInput: str,a: int,b: int):
    return strInput[:a]+strInput[a:b+1][::-1]+strInput[b+1:]

def funcReplace(strInput: str,a: int,b: int, strAfter: str):
    return strInput[:a]+strAfter+strInput[b+1:]


if __name__ == '__main__':
    main()

Solution (Python):
def print_text(text, a, b):
    s = int(a)
    e = int(b)+1

    print(text[s:e])

def reverse_text(text, a, b):
    s = int(a)
    e = int(b)+1

    return text[:s] + text[s:e][::-1] + text[e:]

def replace_text(text, a, b, p):
    s = int(a)
    e = int(b)+1

    return text[0:s] + p + text[e:]

def main():
    text = input()
    q = int(input())

    for _ in range(q):
        op, *args = input().split()

        if   op == 'print':
            print_text(text, *args)
        elif op == 'reverse':
            text = reverse_text(text, *args)
        elif op == 'replace':
            text = replace_text(text, *args)

if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    string = input()
    q = int(input())
    for _ in range(q):
        command = input().split()
        a = int(command[1])
        b = int(command[2])
        if command[0] == 'print':
            print(string[a:b+1])
        elif command[0] == 'reverse':
            if a == b:
                reversed_string = string[a]
            else:
                c = a-1 if a is not 0 else None
                reversed_string = string[b:c:-1]
            string = string[:a] + reversed_string + string[b+1:]
        elif command[0] == 'replace':
            string = string[:a] + command[3] + string[b+1:]


if __name__ == '__main__':
    main()

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

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

Solution (Python):
s = input()
for _ in [0]*int(input()):
    command = []
    command.append(list(map(str,input().split())))
   
    if command[0][0] == 'replace':
        s = s[:int(command[0][1])] + command[0][3] + s[int(command[0][2])+1:]
    elif command[0][0] == 'reverse':
        temp =  s[int(command[0][1]):int(command[0][2])+1:]
        s = s[:int(command[0][1])] +temp[::-1] + s[int(command[0][2])+1:]
    elif command[0][0] == 'print':
        print(s[int(command[0][1]):int(command[0][2])+1])

Solution (Python):
S = str(input())
for i in range(int(input())):
    L = input().split()
    o = L[0]
    a = int(L[1])
    b = int(L[2]) + 1
    if len(L) == 4:
        p = L[3]
    else:
        p = 0

    if o == "print":
        print(S[a:b])
    elif o == "reverse":
        S = S[:a]+S[a:b][::-1]+S[b:]
    elif o == "replace":
        S = S[:a]+p+S[b:]

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):
string = str(input())

num = int(input())

for a in range(num):
    order = input()
    if "replace" in order: 
        order,header,footer,p = order.split()
        header = int(header)
        footer = int(footer)
        
        string = string[:header] + p + string[footer+1:]
        
        
    elif "reverse" in order:
        order,header,footer = order.split()
        
        header = int(header)
        footer = int(footer)
        
        reverse = string[header:footer+1]  
        reverse = reverse[::-1]
        string = string[:header] + reverse + string[footer+1:]
        

    elif "print" in order:
        order,header,footer = order.split()
        header = int(header)
        footer = int(footer)
        print(string[header:footer+1])

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

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
for i in range(q):
    query = stdin.readline().rstrip().split()
    query[1] = int(query[1])
    query[2] = int(query[2])

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

Solution (Python):
S = str(input())
N = int(input())
for _i in range(N):
    line = input().split()
    start = int(line[1])
    end = int(line[2])

    if line[0] == 'print':
        print(S[start:end + 1])
    if line[0] == 'reverse':
        reversed_word = list(S[start:end + 1])
        reversed_word.reverse()
        S = S[:start] + ''.join(reversed_word) + S[end + 1:]
    if line[0] == 'replace':
        S = S[:start] + line[3] + S[end + 1:]

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

Solution (Python):



def replace_(x,y,target,replace):
    return target[:x]+replace+target[y+1:]

def reverse_(x,y,target):
    temp_rev = target[x:y+1]
    rev = temp_rev[::-1]
    return target[:x]+rev+target[y+1:]

def print_(x,y,target):
    print(target[x:y+1])


target = input()
num = int(input())
for _ in range(num):
    i = input().split()
    if i[0] == 'replace':
        target = replace_(int(i[1]),int(i[2]),target,i[3])
    elif i[0] == 'reverse':
        target = reverse_(int(i[1]),int(i[2]),target)
    elif i[0] == 'print':
        print_(int(i[1]),int(i[2]),target)

Solution (Python):
target = input()
for _ in range(int(input())):
    order = input().split()
    if order[0] == 'print':
        print(target[int(order[1]):int(order[2])+1])
    elif order[0] == 'reverse':
        new_sent = ''
        begin_num=int(order[1])
        end_num=int(order[2])+1
        for i in range(len(target)):
            if begin_num <= i < end_num:
                new_sent += target[begin_num + end_num-1 -i]
            else:
                new_sent += target[i]
        target = new_sent
    else:
        target = target[:int(order[1])] + order[3] + target[int(order[2])+1:]

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

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

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

Solution (Python):
s = input()
n = int(input())
for i in range(n):
    order, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if order == 'replace':
        s = s[:a] + c[0] + s[b+1:]
    elif order[0] == 'r':
        s = s[:a] + s[::-1][len(s)-b-1:len(s)-a]+ s[b+1:]
    else:
        print(s[a:b+1])

Solution (Python):
string = input()
for i in range(int(input())):
    lst = list(map(str, input().split()))
    if lst[0] == "replace":
        string = string[:int(lst[1])] + lst[3] + string[int(lst[2])+1:]
    if lst[0] == "reverse":
        rev_str = str(string[int(lst[1]):int(lst[2])+1])
        string = string[:int(lst[1])] + rev_str[::-1] + string[int(lst[2])+1:]
    if lst[0] == "print":
        print(string[int(lst[1]):int(lst[2])+1])

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

for _ in range(n):
	command = input().split(" ")
	st = int(command[1])
	en = int(command[2]) + 1

	if command[0] == "replace":
		A[st:en] = list(command[3])
	elif command[0] == "reverse":
		B = A[st:en]
		B.reverse()
		A[st:en] = B
	else:
		moji = ""
		for i in A[st:en]:
			moji += str(i)
		print(moji)

Solution (Python):

A = list(input())
n = int(input())

for _ in range(n):
	command = input().split(" ")
	st = int(command[1])
	en = int(command[2]) + 1

	if command[0] == "replace":
		A[st:en] = list(command[3])
	elif command[0] == "reverse":
		A[st:en] = reversed(A[st:en])
	else:
		print(*A[st:en],sep="")

Solution (Python):
letters = input()
num = int(input())
for i in range(num):
    order = input().split()
    a = int(order[1])
    b = int(order[2])
    if order[0] == 'print':
        print(letters[a:b+1])
    if order[0] == 'reverse':
        p = letters[a:b+1]
        p = p[::-1]
        letters = letters[:a] + p + letters[b+1:]
    if order[0] == 'replace':
        letters = letters[:a] + order[3] + letters[b+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):
st=input()
n=int(input())
for i in range(n):
  moji=list(map(str,input().split()))

  a=int(moji[1])
  b=int(moji[2])
  if moji[0]=="print":
    print(st[a:b+1])
  if moji[0]=="reverse":
    st=st[:a] + st[a:b+1][::-1] + st[b+1:]
  if moji[0]=="replace":
    st=st[:a]+moji[3]+st[b+1:]

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

Solution (Python):
s = input()

for i in range(int(input())):
    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):
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):
s = raw_input()
q = int(raw_input())
for i in range(q):
	m = raw_input().split(' ')
	if m[0]=="print":
		print s[int(m[1]):int(m[2])+1]
	elif m[0] == "replace":
		s = s[:int(m[1])]+m[3]+s[int(m[2])+1:]
	else:
		t = s[int(m[1]):int(m[2])+1]
		s = s[:int(m[1])]+t[::-1]+s[int(m[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):
s = raw_input()
for _ in [0]*int(raw_input()):
  I = raw_input().split()
  a = I[0][2]
  b = int(I[1])
  c = int(I[2])+1
  if a=='p': s=s[:b]+I[3]+s[c:]
  elif a=='v': s=s[:b]+s[b:c][::-1]+s[c:]
  else: print s[b:c]

Solution (Python):
def sub_print(text, a, b):
    print(text[a:b])
    return text

def sub_reverse(text, a, b):
    return text[:a] + text[a:b][::-1] + text[b:]
def sub_replace(text, a, b, p):
    return text[:a] +p + text[b:]

func = {'print':sub_print, 'reverse':sub_reverse, 'replace':sub_replace}

text = input()
q = int(input())
for i in range(q):
    line = input().split()
    text = func[line[0]](text, int(line[1]), int(line[2]) + 1, *line[3:])

Solution (Python):
tgtstr = list(raw_input())
n = int(raw_input())

for i in range(n):
    cmd_list = raw_input().split(" ")
    if cmd_list[0] == "replace":
        for idx in range(int(cmd_list[1]), int(cmd_list[2])+1):
            tgtstr[idx] = cmd_list[3][idx - int(cmd_list[1])]
    elif cmd_list[0] == "reverse":
        start = int(cmd_list[1])
        end = int(cmd_list[2])
        while True:
            
            tmp = str(tgtstr[start])
            tgtstr[start] = str(tgtstr[end])
            tgtstr[end] = tmp
            start += 1
            end -= 1
            if start >= end:
                break

    elif cmd_list[0] == "print":
        print "".join(tgtstr[int(cmd_list[1]):int(cmd_list[2])+1])

Solution (Python):
import sys

string = raw_input()
string_list = list(string)

q = input()

for i in range(q):
    x = map(str, raw_input().split())
    if(x[0] == 'replace'):
        k = 0
        for j in range(int(x[1]), int(x[2])+1):
            string_list[j] = x[3][k]
            k += 1
        
    if(x[0] == 'reverse'):
        temp = []
        for j in range(int(x[1]), int(x[2])+1):
            temp.append(str(string_list[j]))
        temp.reverse()
        
        temp_list = list(temp)
        k = 0
        for j in range(int(x[1]), int(x[2])+1):
           string_list[j] = temp[k]
           k += 1
        
    if(x[0] == 'print'):
        for i in range(int(x[1]), int(x[2])+1):
          sys.stdout.write(string_list[i])
        print

Solution (Python):
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] + args[3] + text[b + 1:]

Solution (Python):
str1 = input()
count = int(input())

for i in range(count):
    args = input().split()
    (a,b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(str1[a:b + 1])
    elif args[0] == 'reverse':
        str1 = str1[0:a] + str1[a:b + 1][::-1] + str1[b + 1:]
    elif args[0] == 'replace':
        str1 = str1[0:a] + args[3] + str1[b + 1:]

Solution (Python):
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]

    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] + args[3] + text[b + 1:]

Solution (Python):
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] +  args[3] + text[b + 1:]

Solution (Python):
import sys
line = sys.stdin.readline().strip()
n = int(sys.stdin.readline())
for i in range(n):
    v = sys.stdin.readline().split()
    op = v[0]
    a = int(v[1])
    b = int(v[2])
    if op == "print":
        print(line[a: b + 1])
    elif op == "reverse":
        line = line[:a] + line[a: b + 1][::-1] + line[b + 1:]
    elif op == "replace":
        p = v[3]
        line = line[:a] + p + line[b + 1:]

Solution (Python):
s = list(raw_input())
q = int(raw_input())

for k in range(q): 
    ls = raw_input().split()
    a = int(ls[1])
    b = int(ls[2])
    if ls[0] == 'print':
        print ''.join(s[a:b+1])
    elif ls[0] == 'reverse':
        if a != 0:
            s[a:b+1] = s[b:a-1:-1]
        else:
            s[a:b+1] = s[b::-1]
    elif ls[0] == 'replace':
        s[a:b+1] = list(ls[3])

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

def my_reverse(s, a, b):
    return s[:a] + s[a:b+1][::-1] + s[b+1:]

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

if __name__ == '__main__':
    s = input()
    q = int(input())
    for i in range(q):
        code = input().split()
        op, a, b = code[0], int(code[1]), int(code[2])
        if op == 'print':
            my_print(s, a, b)
        elif op == 'reverse':
            s = my_reverse(s, a, b)
        elif op == 'replace':
            s = my_replace(s, a, b, code[3])

Solution (Python):
if __name__ == '__main__':
    s = input()
    q = int(input())
    for i in range(q):
        code = input().split()
        op, a, b = code[0], int(code[1]), int(code[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':
            s = s[:a] + code[3] + s[b+1:]

Solution (Python):


s = list(input())
n = int(input())
for i in range(n):
    c = input().split()
    if c[0] == 'print':
        print(''.join(s[int(c[1]) : int(c[2])+1]))
    elif c[0] == 'reverse' and c[1] != '0':
        s[int(c[1]) : int(c[2])+1] = s[int(c[2]) : int(c[1])-1 :-1]
    elif c[0] == 'reverse' and c[1] == '0':
        s[:int(c[2])+1] = s[int(c[2])::-1]
    else: 
        s[int(c[1]) : int(c[2])+1] = list(c[3])

Solution (Python):


s = input()

for i in range(int(input())):
    cmd = input().split()
    a,b = [int(x) for x in cmd[1:3]]

    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):
word=str(input())
count=int(input())
for i in range(count):
	com=list(map(str,input().split()))
	if com[0]=='print':
		print(word[int(com[1]):int(com[2])+1])
	elif com[0]=='replace':
		word=word[:int(com[1])]+com[3]+word[int(com[2])+1:]
	elif com[0]=='reverse':
		word=word[:int(com[1])]+word[int(com[1]):int(com[2])+1][::-1]+word[int(com[2])+1:]

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

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

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

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

Solution (Python):
s = list(raw_input())
for loop in xrange(input()):
    c = raw_input().split()
    if c[0] == "replace":
        s[int(c[1]): int(c[2]) + 1] = list(c[3])
    if c[0] == "reverse":
        s[int(c[1]): int(c[2]) + 1] = s[int(c[1]): int(c[2]) + 1][::-1]
    if c[0] == "print":
        print "".join(s[int(c[1]): int(c[2]) + 1])

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

Solution (Python):
string = raw_input()
for _ in xrange(input()):
    order = raw_input().split()
    a, b = map(int, order[1:3])
    if order[0] == 'print':
        print string[a:b+1]
    elif order[0] == 'reverse':
        
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif order[0] == 'replace':
        string = string[:a] + order[3] + string[b+1:]

Solution (Python):
string = input()
n = int(input())
for _ in range(n):
    query = input().split()
    if query[0] == 'replace':
        op, a, b, p = query
        a, b = int(a), int(b)
        string = string[:a] + p + string[b + 1:]
    elif query[0] == 'reverse':
        op, a, b = query
        a, b = int(a), int(b)
        string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
    elif query[0] == 'print':
        op, a, b = query
        a, b = int(a), int(b)
        print(string[a: b + 1])

Solution (Python):
str0 = raw_input()
q = int(raw_input())

for i in xrange(q):
  
  
  line = raw_input().split(" ")
  temp = str0[int(line[1]):int(line[2])+1]
  if line[0] == "print":
    print temp
  elif line[0] == "reverse":
    temp2 = [] 
    
    for j in xrange(len(temp)):
      temp2.append(temp[len(temp) - j - 1])
    str0 = str0[:int(line[1])] + "".join(temp2) + str0[int(line[2]) + 1:]
    
  elif line[0] == "replace":
    str0 = str0[:int(line[1])] + line[3] + str0[int(line[2]) + 1:]

Solution (Python):
s = input()
 
for i in range(int(input())):
    cmd = input().split()
    a,b = [int(x) for x in cmd[1:3]]
 
    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 = raw_input()
Q = input()
for q in range(Q):
    str_order = raw_input().split()
    if str_order[0] == 'print':
        print s[int(str_order[1]):int(str_order[2])+1]
    elif str_order[0] == 'reverse':
        start = s[:int(str_order[1])]
        mid = s[int(str_order[1]):int(str_order[2])+1]
        mid = mid[::-1]
        end = s[int(str_order[2])+1:]
        s = start+mid+end
    elif str_order[0] == 'replace':
        start = s[:int(str_order[1])]
        mid = str_order[3]
        end = s[int(str_order[2])+1:]
        s = start+mid+end

Solution (Python):
s = list(raw_input())
Q = input()
for q in range(Q):
    str_order = raw_input().split()
    a = int(str_order[1])
    b = int(str_order[2])
    if str_order[0] == 'print':
        print ''.join(s[a:b+1])
    elif str_order[0] == 'reverse':
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp
    elif str_order[0] == 'replace':
        s[a:b+1] = list(str_order[3])

Solution (Python):

string = list(raw_input())
q = input()
List = [0]*q
for i in range(q):
	List[i] = raw_input().split()
	List[i][1:3] = map(int,List[i][1:3])
	if List[i][0] == 'print' :
		print '%s' %"".join(string[List[i][1]:List[i][2]+1])
	elif List[i][0] == 'reverse':
		s = [0] * (List[i][2]-List[i][1])
		s = reversed(string[List[i][1]:List[i][2]+1])
		string[List[i][1]:List[i][2]+1] = s
	else :
		string[List[i][1]:List[i][2]+1] = list(List[i][3])

Solution (Python):
string = input()

n = int(input())

for i in range(n):
    command = input().split()
    c_n = command[0]
    c_i1 = int(command[1])
    c_i2 = int(command[2]) + 1
    if c_n == "print":
        print(string[c_i1:c_i2])
    elif c_n == "reverse":
        string = string[:c_i1] + string[c_i1:c_i2][::-1] + string[c_i2:]
    else:
        string = string[:c_i1] + command[3] + string[c_i2:]

Solution (Python):
str = input()
num = int(input())
for i in range(num):
    command = input().split()
    c1, c2, c3 = command[0], int(command[1]), int(command[2])
    if c1 == 'print':
        print(str[c2:c3 + 1])
    elif c1 == 'reverse':
        str = str[:c2] + str[c2:c3 + 1][::-1] + str[c3 + 1:]
    elif c1 == 'replace':
        str = str[:c2] + command[3] + str[c3 + 1:]

Solution (Python):
in_str = raw_input()
q = int(raw_input())
for i in range(q):
    oper = raw_input().split()
    if oper[0] == 'print':
        print in_str[(int(oper[1])):(int(oper[2]))+1]
    elif oper[0] == 'reverse':
        buf = ''
        for i in range(int(oper[1])):
            buf += in_str[i]
        for i in reversed(range(int(oper[1]),int(oper[2])+1)):
            buf += in_str[i]
        buf += in_str[(int(oper[2]))+1:]
        in_str = buf
    elif oper[0] == 'replace':
        buf = in_str[:(int(oper[1]))]
        buf += oper[3]
        buf += in_str[(int(oper[2]))+1:]
        in_str = buf

Solution (Python):
s = input()
n = int(input())
for _ in range(n):
    line = input().split()
    command, args = line[0], line[1:]
    start = int(args[0])
    end = int(args[1]) + 1
    if command == 'replace':
        s = s[:start] + args[2] + s[end:]
    elif command == 'reverse':
        s = s[:start] + str(''.join(list(reversed(s[start:end])))) + s[end:]
    elif command == 'print':
        print(s[start:end])

Solution (Python):
instr = raw_input().strip()
commandnum = input()
for c in xrange(commandnum):
    command = raw_input().split()
    if command[0]=="replace":
        instr = instr[:int(command[1])]+command[3]+instr[int(command[2])+1:]
    elif command[0]=="reverse":
        instr = instr[:int(command[1])]+instr[int(command[1]):int(command[2])+1][::-1]+instr[int(command[2])+1:]
    elif command[0]=="print":
        print instr[int(command[1]):int(command[2])+1]
    else:
        print "invalid command."
        break

Solution (Python):
s = list(raw_input())
Q = input()
for q in range(Q):
  str_order = raw_input().split()
  a = int(str_order[1])
  b = int(str_order[2])
  if str_order[0] == 'print':
    print ''.join(s[a:b+1])
  elif str_order[0] == 'reverse':
    tmp = s[a:b+1]
    tmp.reverse()
    s[a:b+1] = tmp
  elif str_order[0] == 'replace':
    s[a:b+1] = list(str_order[3])

Solution (Python):
string = raw_input()
n = input()

for i in range(n):
    tmp = map(str, raw_input().split())
    if tmp[0] == "print":
        print string[int(tmp[1]): int(tmp[2]) + 1]
    elif tmp[0] == "reverse":
        s = ""
        for i in range(int(tmp[1])):
            s += string[i]
        for i in range(int(tmp[2]) - int(tmp[1]) + 1):
            s += string[int(tmp[2]) - i]
        for i in range (len(string) - int(tmp[2]) - 1):
            s += string[i + int(tmp[2]) + 1]
        string = s
    elif tmp[0] == "replace":
        s = string[:int(tmp[1])] + tmp[3] + string[int(tmp[2]) + 1:]
        string = s

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

def reverse_ab(s, a, b):
    s_f = s[:a]
    s_m = s[a:b+1]
    s_b = s[b+1:]

    return s_f + s_m[::-1] + s_b

def replace_ab(s, a, b, p):
    s_f = s[:a]
    s_b = s[b+1:]

    return s_f + p + s_b

if __name__ == "__main__":
    s = input()
    q = int(input())

    for i in range(q):
        ops = input().split()
        if ops[0] == "print":
            print_ab(s, int(ops[1]), int(ops[2]))
        elif ops[0] == "reverse":
            s = reverse_ab(s, int(ops[1]), int(ops[2]))
        elif ops[0] == "replace":
            s = replace_ab(s, int(ops[1]), int(ops[2]), ops[3])

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

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

Solution (Python):
def s_print(s, line):
    a, b = map(int, line.split()[1:])
    print(s[a:b + 1])
    return s


def s_reverse(s, line):
    a, b = map(int, line.split()[1:])
    return s[:a] + s[a:b + 1][::-1] + s[b + 1:]


def s_replace(s, line):
    ls = line.split()
    a, b = map(int, ls[1:3])
    rep = ls[-1]
    return s[:a] + rep + s[b + 1:]


func_dict = {'pri': s_print, 'rev': s_reverse, 'rep': s_replace}

s, q = input(), int(input())
while q:
    line = input()
    s = func_dict[line[:3]](s, line)
    q -= 1