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

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

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

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

for i in range(q):
	do_list = raw_input().split()
	a = int(do_list[1])
	b = int(do_list[2])
	if do_list[0] == "print":
		print(str[a:(b+1)])
	elif do_list[0] == "reverse":
		part = str[a:(b+1)]
		rev = ""
		for j in range(len(part)):
			rev += part[-j-1]
		if a == 0:
			str = rev + str[(b+1):]
		elif b == len(str)-1:
			str = str[:a] + rev
		else:
			str = str[:a] + rev + str[(b+1):]
	else:
		p = do_list[3]
		if a == 0:
			str = p + str[(b+1):]
		elif b == len(str)-1:
			str = str[:a] + p
		else:
			str = str[:a] + p + str[(b+1):]

Solution (Python):
def main():
    m = list(input())
    q = int(input())
    A = []
    for _ in range(q):
        A.append(input().split())

    for x in range(q):
        if A[x][0] == "print":
            A[x][1] = int(A[x][1])
            A[x][2] = int(A[x][2])
            for y in range(A[x][1], A[x][2] + 1):
                if y != A[x][2]:
                    print(m[y], end = "")
                else:
                    print(m[y])
        elif A[x][0] == "reverse":
            A[x][1] = int(A[x][1])
            A[x][2] = int(A[x][2])
            hoge = []
            for y in range(A[x][1], A[x][2] + 1):
                hoge.append(m[y])
            hoge = hoge[::-1]
            i = 0
            for y in range(A[x][1], A[x][2] + 1): 
                m[y] = hoge[i]
                i += 1
        elif A[x][0] == "replace":
            A[x][1] = int(A[x][1])
            A[x][2] = int(A[x][2])
            fuga = list(A[x][3])
            j = 0
            for y in range(A[x][1], A[x][2] + 1):
                m[y] = fuga[j]
                j += 1


if __name__ == "__main__":
    main()

Solution (Python):
string = raw_input()
num_order = int(raw_input())
for i in range(num_order):
    command = raw_input().split()
  
    a, b = map(int, command[1:3])
    if command[0] == "print":
        print string[a:b+1]
    elif command[0] == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif command[0] == "replace":
        p = command[-1]
        string = string[:a] + p + string[b+1:]

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

Solution (Python):
def main():

    string = input()
    commands_count = int(input())
    commands = [input().split() for i in range(commands_count)]

    for command in commands:
        a, b = int(command[1]), int(command[2])
        if len(command) == 4:
            string = string[0:a] + command[3] + string[b+1:]
        else:
            if command[0] == 'print':
                print(string[a:b+1])
            else:
                string = string[0:a] + ''.join(list(reversed(string[a:b+1]))) + string[b+1:]

main()

Solution (Python):
def str_reverse(s, a, b):
    s_new = s[0:a]
    s_rev = s[a:b+1]
    s_rev_len = len(s_rev)
    for i in range(s_rev_len):
        j = s_rev_len - i - 1
        s_new += s_rev[j]
    s_new += s[b+1:]
    return s_new

def str_replace(s, a, b, new):
    s_new = s[0:a]
    s_new += new
    s_new += s[b+1:]
    return s_new


s = input()
n = int(input())
for q in range(n):
    line = input()
    if line.find('print') == 0:
        cmd, a, b  = line.split()
        a = int(a)
        b = int(b)
        print(s[a:b+1])

    elif line.find('reverse') == 0:
        cmd, a, b  = line.split()
        a = int(a)
        b = int(b)
        s = str_reverse(s, a, b)

    elif line.find('replace') == 0:
        cmd, a, b, p  = line.split()
        a = int(a)
        b = int(b)
        s = str_replace(s, a, b, p)

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

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

Solution (Python):


def main():

    inputLine = list(input())

    orderLine = int(input())

    for i in range(orderLine):
        tokens = list(input().split())

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

        if(tokens[0] == 'print'):
            print( ''.join(inputLine[a:b+1]) )
        elif(tokens[0] == 'reverse'):
            reverseList = inputLine[a:b+1]
            inputLine[a:b+1] = reverseList[::-1]
        elif(tokens[0] == 'replace'):
            replaceList = list(tokens[3])
            inputLine[a:b+1] = replaceList

if __name__ == '__main__':
    main()

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

    for _ in range(q):
        query = input().split()
        op, a, b = query[0:3]
        a, b = int(a), int(b)

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


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
s=input()
for _ in range(int(input())):
 a=input().split()
 if a[0][0]=='p':print(s[int(a[1]):int(a[2])+1])
 else:
  t=a[3]if'p'==a[0][2]else s[int(a[1]):int(a[2])+1][::-1]
  s=s[0:int(a[1])]+t+s[int(a[2])+1:]

Solution (Python):
s=input()
for _ in range(int(input())):
 a=input().split()
 i=int(a[1]);j=int(a[2])
 if a[0][0]=='p':print(s[i:j+1])
 else:
  t=a[3]if'p'==a[0][2]else s[i:j+1][::-1]
  s=s[0:i]+t+s[j+1:]

Solution (Python):
s=input()
for _ in range(int(input())):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=a[3]if'p'==o[2]else s[i:j][::-1]
  s=s[0:i]+t+s[j:]

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

l = []
for i in range(n):
    l.append(list(map(str,input().split())))

for i in range(len(l)):
    command = l[i][0]
    a = int(l[i][1])
    b = int(l[i][2])
    c = s[a:b+1]
    if command == "replace":
        s = s[:a] + l[i][3] + s[b+1:]
    elif command == "reverse":
        s = s[:a] + c[::-1] + s[b+1:]
    elif command == "print":
        print(c)

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

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

Solution (Python):
str = input()
str_list = list(str)
q = int(input())
for i in range(q):
    order = input().split()
    if order[0] == 'print':
        for i in range(int(order[1]),int(order[2])+1):
            print("{}".format(str_list[i]),end=(''))
        print('')
    elif order[0] == 'replace':
        word=list(order[3])
        j = 0
        for i in range(int(order[1]),int(order[2])+1):
            str_list[i]=word[j]
            j = j + 1
    elif order[0] == 'reverse':
        word = list(str_list[int(order[1]):int(order[2])+1])
        j = len(word)
        for i in range(int(order[1]),int(order[2])+1):
            str_list[i] = word[j-1]
            j = j - 1

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

Solution (Python):
w = input()
q = int(input())
for _ in range(q):
    S = input().split()
    s = S[0]
    a, b = map(int, S[1: 3])
    if s == "print":
        print(w[a: b + 1])
    elif s == "reverse":
        w = w[:a] + w[a: b + 1][::-1] + w[b + 1:]
    else:
        w = w[:a] + S[3] + w[b + 1:]

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

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

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

Solution (Python):

def show(a,b):
    global str
    print str[a:b+1]
def reverse(a,b):
    global str
    t = str[:a]
    t += str[-(len(str)-b):-(len(str)-a+1):-1]
    t += str[b+1:]
    str = t
def replace(a,b,p):
    global str
    t = str[:a]
    t += p
    t += str[b+1:]
    str = t

str = raw_input()
n = input()

for i in range(n):
    command = raw_input().split()
    if command[0] == "replace":
        replace(int(command[1]),int(command[2]),command[3])
    elif command[0] == "reverse":
        reverse(int(command[1]),int(command[2]))
    elif command[0] == "print":
        show(int(command[1]),int(command[2]))

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

Solution (Python):
str_in, n = input(), int(input())
for i in range(n):
    com = input().split()
    com_idx = [int(i) for i in com if i.isdigit()]
    if com[0]=="print":
        print(str_in[com_idx[0]:com_idx[1]+1])
    elif com[0]=="reverse":
        str_rev = str_in[com_idx[0]:com_idx[1]+1]
        str_in = str_in[:com_idx[0]] + str_rev[::-1] + str_in[com_idx[1]+1:]
    elif com[0]=="replace":
        str_in = str_in[:com_idx[0]] + com[3] + str_in[com_idx[1]+1:]

Solution (Python):
text = list(input())
num = int(input())
for i in range(num):
    cmd = input().split()
    start, end = map(int, cmd[1:3])
    if cmd[0] == 'replace':
        text[start:end+1] = list(cmd[-1])
    elif cmd[0] == 'reverse':
        text[start:end+1] = (text[start:end+1])[::-1]
    elif cmd[0] == 'print':
        print(''.join(text[start:end+1]))

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

Solution (Python):
string = input()
for _ in range(int(input())):
    com = [x for x in input().split()]
    c = com[0]
    a,b = [int(com[i]) for i in range(1,3)]
    if c == 'reverse':
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    if c == 'print':
        print(string[a:b+1])
    if c == 'replace':
        string = string[:a] + com[3] + string[b+1:]

Solution (Python):



import sys

in_str = sys.stdin.readline().strip()
q = int(sys.stdin.readline())

for i in range(q):
    command = sys.stdin.readline().split()
    pos_a = int(command[1])
    pos_b = int(command[2])

    if command[0] == 'print':
        print(in_str[pos_a:pos_b+1])
    elif command[0] == 'reverse':
        if pos_a == 0: to_pos = None
        else: to_pos = pos_a - 1
        in_str = in_str[:pos_a] + in_str[pos_b:to_pos:-1] + in_str[pos_b+1:]
    elif command[0] == 'replace':
        in_str = in_str[:pos_a] + command[3] + in_str[pos_b+1:]
    else:
        raise ValueError

Solution (Python):
def transformate(s, command):
    command, *op = command.split()

    op[0] = int(op[0])
    op[1] = int(op[1])

    if command == 'replace':
        return s[0:op[0]] + op[2] + s[op[1]+1:]
    elif command == 'reverse':
        return s[0:op[0]] + s[op[0]:op[1]+1][::-1] + s[op[1]+1:]
    elif command == 'print':
        print(s[op[0]:op[1]+1])
        return s

if __name__ == '__main__':
    s = input()
    for _ in range(int(input())):
        s = transformate(s, input())

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

Solution (Python):

t = input()
for i in range(int(input())):
    cmd = list(input().split())
    cmd[1] = int(cmd[1])
    cmd[2] = int(cmd[2])
    if cmd[0] == "print":
        print(t[cmd[1] : cmd[2]] + t[cmd[2]])
    elif cmd[0] == "reverse":
        tmp = t[cmd[1] : cmd[2]] + t[cmd[2]]
        tmp = tmp[::-1]
        t = t[:cmd[1]] + tmp + t[cmd[2]+1:]
    elif cmd[0] == "replace":
        t = t[:cmd[1]] + cmd[3] + t[cmd[2]+1:]

Solution (Python):
s = input()
n = int(input())
ans = ''
i = 0
while i < n:
    order = list(map(str, input().split(' ')))
    if order[0] == 'print':
        ans += s[int(order[1]):int(order[2])+1] + '\n'
    elif order[0] == 'reverse':
        i1 = int(order[1])
        i2 = int(order[2])
        s0 = s[:i1]
        j = 0
        while j < (i2 - i1 + 1):
            s0 += s[i2 - j]
            j += 1
        s0 += s[i2+1:]
        s = s0
    else:
        i1 = int(order[1])
        i2 = int(order[2])
        s = s[:i1] + order[3] + s[i2+1:]
    i += 1
print(ans[:-1])

Solution (Python):
class StringEditor:
    def __init__(self, s):
        self.s = s

    def __str__(self):
        return self.s

    def print(self, start, end):
        """print command

        >>> e = StringEditor('abcde')
        >>> e.print(1, 3)
        bcd
        """
        print(self.s[start:end+1])

    def replace(self, start, end, word):
        """replace command

        >>> e = StringEditor('abcde')
        >>> e.replace(1, 3, 'xyz')
        >>> e.print(0, 4)
        axyze
        """
        self.s = self.s[:start] + word + self.s[end+1:]

    def reverse(self, start, end):
        """reverse command

        >>> e = StringEditor('abcde')
        >>> e.reverse(0, 2)
        >>> e.print(0, 4)
        cbade
        >>> e.reverse(2, 3)
        >>> e.print(0, 4)
        cbdae
        """
        if start > 0:
            rev = self.s[end:start-1:-1]
        else:
            rev = self.s[end::-1]

        self.s = self.s[:start] + rev + self.s[end+1:]


def run():
    s = input()
    num = int(input())
    editor = StringEditor(s)

    for _ in range(num):
        com, *args = input().split()

        if com == 'print':
            start, end = [int(i) for i in args]
            editor.print(start, end)
        elif com == 'reverse':
            start, end = [int(i) for i in args]
            editor.reverse(start, end)
        elif com == 'replace':
            start, end = [int(i) for i in args[0:2]]
            word = args[-1]
            editor.replace(start, end, word)
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()

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

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

Solution (Python):


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

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

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

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):
w = input()
N = int(input())
for n in range(N):
    o = input().split()
    if o[0] == "print":
        print(w[int(o[1]):int(o[2])+1])
    if o[0] == "reverse":
        a = w[int(o[1]):int(o[2])+1]
        w = w[:int(o[1])] + a[::-1] + w[int(o[2])+1:]
    if o[0] == "replace":
        b = [x for x in w]
        i = [y for y in o[3]]
        for j in range(len(i)):
            b[int(o[1])+j] = i[j]
        w = "".join(map(str,b))

Solution (Python):
S=input()
N=int(input())
for i in range(N):
    command=input().split()
    if command[0]=="replace":
        a=int(command[1])
        b=int(command[2])
        x=command[3]
        A=S[:a]
        B=S[b+1:]
        S=A+x+B
    elif command[0]=="reverse":
        a=int(command[1])
        b=int(command[2])
        A=S[:a]
        B=S[a:b+1]
        C=S[b+1:]
        T=""
        for p in range(len(B)):
            T+=B[len(B)-1-p]
        S=A+T+C
    else:
        
        a=int(command[1])
        b=int(command[2])
        print(S[a:b+1])

Solution (Python):
def Reverse(str, A, B):
    a = int(A)
    b = int(B)
    if a == 0:
        str = str[0:a] + str[b::-1] + str[b + 1:]
    else:
        str = str[0:a] + str[b:a - 1:-1] + str[b + 1:]
    return str

def Replace(str, a, b, c):
    str2 = ''
    Str = list(str)
    for i in range(int(b) - int(a) + 1):
        Str[i + int(a)] = c[i]
    for i in range(len(Str)):
        str2 += Str[i]
    return str2

str = input()
n = int(input())
for i in range(n):
    a = input()
    A = a.split()
    if A[0] == 'print':
        print(str[int(A[1]):int(A[2]) + 1])
    elif A[0] == 'reverse':
        str = Reverse(str, A[1], A[2])
    elif A[0] == 'replace':
        str = Replace(str, A[1], A[2], A[3])

Solution (Python):


import math

s = list(input())
q = int(input())

for i in range(q):
    n = list(input().split())
    if 'print' in n:
        for j in range(int(n[1]), int(n[2]) + 1):
            print(str(s[j]), end='')
        print()

    elif 'reverse' in n:
        for k in range(math.floor((int(n[2]) - int(n[1]) + 1) / 2)):
            s[int(n[1]) + k], s[int(n[2]) - k] = s[int(n[2]) - k], s[int(n[1]) + k]

    elif 'replace' in n:
        for l in range(int(n[1]), int(n[2]) + 1):
            s.pop(int(n[1]))

        count  = int(n[1])

        for m in list(n[3]):
            s.insert(count, m)
            count += 1

Solution (Python):



sent = input()

def print_(arr):
    global sent
    print(sent[int(arr[0]):int(arr[1])+1])

def reverse_(arr):
    global sent
    sent = sent[:int(arr[0])] + sent[int(arr[0]):int(arr[1])+1][::-1] + sent[int(arr[1])+1:]

def replace_(arr):
    global sent
    sent = sent[:int(arr[0])] + arr[2] + sent[int(arr[1])+1:]

ops = {'print': print_, 'reverse': reverse_, 'replace': replace_}

q = int(input())
for i in range(q):
    arr = input().split()
    ops[arr[0]](arr[1:])

Solution (Python):
s=input()
for _ in[0]*int(input()):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=a[3]if'p'==o[2]else s[i:j][::-1]
  s=s[0:i]+t+s[j:]

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

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

Solution (Python):
def convert():
    str = input().rstrip()
    n = int(input().rstrip())
    
    for _ in range(n):
        columns = input().rstrip().split()
        order = columns[0]
        a = int(columns[1])
        b = int(columns[2])
        
        if order == 'print':
            print(str[a:b+1])
            
        if order == 'reverse':
            str = str[:a] + str[a:b+1][::-1] + str[b+1:]
        
        if order == 'replace':        
            p = columns[3]
            str = str[:a] + p + str[b+1:] 
if __name__ == '__main__':
    convert()

Solution (Python):
s = str(raw_input())
q = int(raw_input())
for i in range(q):
    line = map(str, raw_input().split())
    com = line[0]
    a = int(line[1])
    b = int(line[2])
    if com == "print":
        print s[a:b+1]
    elif com == "reverse":
        tmp = s[::-1]
        s = s[:a] + tmp[len(tmp)-b-1:len(tmp)-a] + s[b+1:]
    elif com == "replace":
        p = line[3]
        s = s[:a] + p + s[b+1:]
    else:
        print "Error"

Solution (Python):
sentence = input()
jobs = int(input())

def my_print(s, x, y):
    print(s[x:y+1])

def my_replace(s, x, y, t):
    s = list(s)
    s[x:y+1] = t
    return "".join(s)

def my_reverse(s, x, y):
    s = list(s)
    ss = s[x:y+1]
    ss.reverse()
    s[x:y+1] = ss
    return "".join(s)

for _ in range(jobs):
    task = input().split()
    task[1], task[2] = int(task[1]), int(task[2])
    if task[0] == "print":
        my_print(sentence, task[1], task[2])
    elif task[0] == "replace":
        sentence = my_replace(sentence, task[1], task[2], task[3])
    elif task[0] == "reverse":
        sentence = my_reverse(sentence, task[1], task[2])

Solution (Python):
str=list(input())
n=int(input())
for i in range(n):
    a=input().split()
    s=int(a[1]);f=int(a[2])+1
    str1=str[s:f]
    if a[0]=='replace':
        ar=list(a[3])
        str[s:f]=ar
    elif a[0]=='print':
        ans=''.join(str1)
        print(ans)
    else:
        str2=str1[::-1]
        str[s:f]=str2

Solution (Python):


def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    string = input()
    n = int(input())
    for i in range(n):
        command = input().split()
        a = int(command[1])
        b = int(command[2])
        if command[0][0] == 'r':
            front = string[0 : a]
            back = string[b + 1 : len(string)]
        if command[0][2] == 'p':
            string = front + command[3] + back
        elif command[0][2] == 'v':
            string = front + string[a : b + 1][::-1] + back
        else:
            print(string[a : b + 1])

if __name__ == "__main__":
    main()

Solution (Python):
def replace(str):
    for i, c in enumerate(command[3], command[1]):
        str[i] = c
    return str

def reverse(str):
    for i, c in enumerate(reversed(str[command[1]: command[2]+1]), command[1]):
        str[i] = c
    return str

def str_print(str):
    str = ''.join(str)
    print(str[command[1]: command[2]+1])
    str = list(str)
    return str

str = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    command[1], command[2] = int(command[1]), int(command[2])
    if command[0] == 'replace':
        str = replace(str)
    elif command[0] == 'reverse':
        str = reverse(str)
    else:
        str = str_print(str)

Solution (Python):
p = input()
num = int(input())
for i in range(num):
    order = list(map(str,input().split()))
    a = int(order[1])
    b = int(order[2])
    if order[0] == 'print':
        print(p[a:b+1])
    elif order[0] == 'replace':
        rep = order[3]
        p = p[:a] + rep + p[b+1:]
    else:
        p = p[:a] + p[a:b+1][::-1] + p[b+1:]

Solution (Python):
def my_print():
    print("{}".format("".join(str[command[1]: command[2]])))

def replace():
    command[3] = list(command[3])
    str[command[1]: command[2]] = command[3]

def reverse():
    str[command[1]: command[2]] = reversed(str[command[1]: command[2]])

str = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    command[1], command[2] = int(command[1]), int(command[2]) + 1
    if command[0] == "print":
        my_print()
    elif command[0] == "replace":
        replace()
    else:
        reverse()

Solution (Python):

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

for i in range(q):
	arr = list(map(str, input().split()))
	c = arr[0]
	n1 = int(arr[1])
	n2 = int(arr[2])

	if c == 'print':
		print(s[n1:n2 + 1])
	if c == 'replace':
		s = s[0:n1] + arr[3] + s[n2 + 1:len(s)]
	if c == 'reverse':
		l = n2 - n1 + 1
		reverse = ''
		for i in range(l):
			reverse += s[n2 - i]
		s = s[0:n1] + reverse + s[n2 + 1:len(s)]

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

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

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

Solution (Python):
input_str = input()
n_orders = int(input())
for _ in range(n_orders):
    order_str = input()
    if order_str.startswith('print'):
        _, start, end = [s.strip() for s in order_str.split()]
        start = int(start)
        end = int(end) + 1
        print(input_str[start:end])
    elif order_str.startswith('reverse'):
        _, start, end = [s.strip() for s in order_str.split()]
        start = int(start)
        end = int(end) + 1
        rev_str = input_str[start:end]
        rev_str = list(reversed(rev_str))
        input_str = list(input_str)
        input_str[start:end] = rev_str
        input_str = ''.join(input_str)
    elif order_str.startswith('replace'):
        _, start, end, rep_str = [s.strip() for s in order_str.split()]
        start = int(start)
        end = int(end) + 1
        input_str = list(input_str)
        input_str[start:end] = rep_str
        input_str = ''.join(input_str)

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

Solution (Python):


string = input()
commandAmount = int(input())

for i in range(commandAmount):
    command = input().rstrip().split()
    start = int(command[1])
    end = int(command[2])
    if command[0] == 'print':
        print(string[start : end + 1]) 
    elif command[0] == 'reverse':
        replacedString = list(string)
        
        for i in range(start, end + 1):
            replacedString[i] = list(string)[start + end - i]
        
        string = ''.join(replacedString)
    elif command[0] == 'replace':
        string = list(string)
        replace = list(command[3])
        for i in range(start, end + 1):
            string[i] = replace[i - start]
        string = ''.join(string)