Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



Sample input:
abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4


Sample output:
xaze

Submission status: Wrong Answer

Solution code:
# 21-String-Transformation.py

# ???????????????
# ????????? str ?????????????????????????????????????????????????????????????????°????????????????????????????????????
# ???????????\?????????????????????????????§??????

# print a b: str ??? a ??????????????? b ??????????????§??????????????????
# reverse a b: str ??? a ??????????????? b ??????????????§?????????????????????
# replace a b p: str ??? a ??????????????? b ??????????????§??? p ?????????????????????
# ????????§??????????????? str ????????????????????? 0 ???????????¨????????????

# Input
# 1 ?????????????????? str ????????????????????????str ?????±?°????????????????????????????
# 2 ????????????????????° q ?????????????????????????¶???? q ??????????????????????¨??????¢?????§?????????????????????

# Output
# ??? print ???????????¨???????????????????????????????????????????????????

# Constraints
# 1???str????????????1000
# 1???q???100
# 0???a???b<str?????????
# replace ????????§??? b???a+1=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

#??\???

str = input()
op_num = int( input() )
for i in range(op_num):
	op = input().split()
	a = int(op[1])
	b = int(op[2])
	if op[0]=="replace":
		str = str.replace(str[ a:b+1 ], op[3])
	elif op[0]=="reverse":
		# str = str.replace(str[a:b+1], str[ b-len(str) : a-len(str)-1 : -1 ] )
		str = str[:a] + str[a:b+1][::-1] + str[b+1:]
	# elif op[0]=="print":
	else:
		print(str[a:b+1])

Submission status: Wrong Answer

Solution code:
string = list(input())
times = int(input())
for i in range(times):
    order = input().split()
    if order[0] == "replace":
        replace_string = order[3]
        count = 0
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = replace_string[count]
            count += 1
            #print(count)
    elif order[0] == "reverse":
        reverse_string = string[int(order[1]):int(order[2]) + 1]
        reverse_string.reverse()
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = reverse_string[j]
        #string[int(order[1]):int(order[2]) + 1].reverse()
        print(string)
        #string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse()
    elif order[0] == "print":
        print("".join(string[int(order[1]):int(order[2]) + 1]))

Submission status: Wrong Answer

Solution code:
string = list(input())
times = int(input())
for i in range(times):
    order = input().split()
    #print(order)
    if order[0] == "replace":
        replace_string = order[3]
        print(string)
        count = 0
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = replace_string[count]
            count += 1
            #print(count)
        print(string)
    elif order[0] == "reverse":
        print(string)
        reverse_string = string[int(order[1]):int(order[2]) + 1]
        reverse_string.reverse()
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = reverse_string[j]
        print(string)
        #string[int(order[1]):int(order[2]) + 1].reverse()
        #print(string)
        #string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse()
    elif order[0] == "print":
        print(string)
        print("".join(string[int(order[1]):int(order[2]) + 1]))
        print(string)

Submission status: Wrong Answer

Solution code:
str = input().casefold()
q = int(input())

for i in range(q):
    command = 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+a:]
    elif command[0] == "replace":
        str = str[:a] +command[3] + str[b+1:]

Submission status: Wrong Answer

Solution code:
string = list(input())
times = int(input())
#a = [int(i) for i in range(0,5)]
#print(a)
for i in range(times):
    order = input().split()
    #print(order)
    if order[0] == "replace":
        replace_string = order[3]
        #print(string)
        count = 0
        for j in range(int(order[1]), int(order[2]) + 1):
            string[j] = replace_string[count]
            count += 1
            #print(count)
        #print(string)
    elif order[0] == "reverse":
        #print(string)
        reverse_string = string[int(order[1]):int(order[2]) + 1]
        reverse_string.reverse()
        #for j in range(int(order[1]), int(order[2]) + 1):
        #    string[j] = reverse_string[j]
        string = string[:int(order[1])] + reverse_string + string[int(order[2]):]
        #print(j)
        #print(string)
        #string[int(order[1]):int(order[2]) + 1].reverse()
        #print(string)
        #string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse()
    elif order[0] == "print":
        #print(string)
        print("".join(string[int(order[1]):int(order[2]) + 1]))
        #print(string)

Submission status: Wrong Answer

Solution code:
string = [str(i) for i in input()]
for _ in range(int(input())):
	n = input().split()
	order = n.pop(0)
	if order == 'replace':
		string = string[:int(n[0])] + \
		[i for i in n[2]] + string[int(n[1])+1:]
	elif order == 'reverse':
		string = string[:int(n[1])] + \
		string[int(n[0]):int(n[1])+1][::-1] + \
		string[int(n[1])+1:]
	else :
		out = string[ int(n[0]) : int(n[1])+1 ]
		print(''.join(out))

Submission status: Wrong Answer

Solution code:
#def area###############################
def pr(s,a,b):
	print s[int(a):int(b)+1]

def rv(s,a,b):
	tmp=s[::-1]
	news=s[:int(a)]+tmp[len(tmp)-int(b)-1:len(tmp)-int(a)]+s[int(b)+1:]
	return news
def rp(s,a,b,p):
	news=s[:int(a)]+p+s[int(b)+1:]
	return news
########################################


I=raw_input()
n=int(input())
for i in range(n):
	k=raw_input().split(" ")
	if k[0]=="replace":
		I=rp(I,k[1],k[2],k[3])
	elif k[0]=="reverse":
		I=rv(I,k[1],k[2])
	elif k[0]=="print":
		pr(I,k[1],k[2])
	print I

Submission status: Wrong Answer

Solution code:
def _print(c):
    a,b = c
    print(s[int(a):int(b)+1])
def _reverse(c):
    global s
    a,b = c
    r = s[int(b)-len(s):int(a)-len(s)-1:-1]
    s = s.replace(s[int(a):int(b)+1],r)
def _replace(c):
    global s
    a,b,p = c
    s = s.replace(s[int(a):int(b)+1],p)
s = input()
n = int(input())
command = {"print":_print,"reverse":_reverse,"replace":_replace}
for i in range(n):
        c = input().split()
        command[c[0]](c[1:])

Submission status: Wrong Answer

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

for qi in range(q):
    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:
        p = command[3]
        s = s[a:] + p + s[:b]

Submission status: Wrong Answer

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

for qi in range(q):
    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:
        p = command[3]
        s = s[a:] + p + s[b + 1:]

Submission status: Wrong Answer

Solution code:
str = input()
num = int(input())

for i in range(num):
	seq = input().split()
	start = int(seq[1])
	end = int(seq[2])
	temp = str[start:end+1]
	
	if seq[0] == 'replace':
		str = str.replace(temp, seq[3])
	elif seq[0] == 'reverse':
		str = str.replace(temp, temp[::-1])
	else:
		print(temp)

Submission status: Wrong Answer

Solution code:
str = input()
num = int(input())

for i in range(num):
	seq = input().split()
	start = int(seq[1])
	end = int(seq[2])
	temp = str[start:end+1]
	
	if seq[0] == 'replace':
		str = str.replace(temp, seq[3],1)
	elif seq[0] == 'reverse':
		str = str.replace(temp, temp[::-1])
	else:
		print(temp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
str = raw_input()
for _ in xrange(input()):
 ops = raw_input().split()
 na = int(ops[1])
 nb = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print str[na:nb+1]
 elif op[2]=="v": str = str[:na] + "".join(reversed(str[na:nb])) + str[nb:]
 else: str = str[:na] + ops[3] + str[nb:]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
 a = list(input().split())
 if a[0] == 'replace':
  temp = s[int(a[1]):int(a[2])+1]
  s.replace(temp, a[3])
 elif a[0] == 'reverse':
  temp = s[int(a[1]):int(a[2])+1]
  s.replace(temp, temp[::-1])
 elif a[0] == 'print':
  print(s[int(a[1]):int(a[2])+1])

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
 a = list(input().split())
 temp = s[int(a[1]):int(a[2])+1]
 if a[0] == 'replace':
  s.replace(temp, a[3])
 elif a[0] == 'reverse':
  temp2 = temp[::-1]
  s.replace(temp, temp2)
 elif a[0] == 'print':
  print(temp)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
 a = list(input().split())
 temp = s[int(a[1]):int(a[2])+1]
 if a[0] == 'replace':
  s = s.replace(temp, a[3])
 elif a[0] == 'reverse':
  temp2 = temp[::-1]
  s = s.replace(temp, temp2)
 elif a[0] == 'print':
  print(temp)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
 a = list(input().split())
 temp = s[int(a[1]):int(a[2])+1]
 if a[0] == 'replace':
  s = s.replace(temp, a[3], 1)
 elif a[0] == 'reverse':
  temp2 = temp[::-1]
  s = s.replace(temp, temp2, 1)
 elif a[0] == 'print':
  print(temp)

Submission status: Wrong Answer

Solution code:
string = input()
q = int(input())
for c in range(0,q):
    instruction = input().split(' ')
    if instruction[0] == 'print':
        print(string[int(instruction[1]):int(instruction[2]) + 1])
    elif instruction[0] == 'reverse':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], string[int(instruction[1]):int(instruction[2])+1][::-1])
    elif instruction[0] == 'replace':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], instruction[3])

Submission status: Wrong Answer

Solution code:
string = input()
q = int(input())
for c in range(0,q):
    instruction = input().split(' ')
    if instruction[0] == 'print':
        print(string[int(instruction[1]):int(instruction[2]) + 1])
    elif instruction[0] == 'reverse':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], string[int(instruction[1]):int(instruction[2])+1][::-1], 1)
    elif instruction[0] == 'replace':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], instruction[3], 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
string = input()
q = int(input())
for c in range(0,q):
    instruction = input().split(' ')
    if instruction[0] == 'print':
        print(string[int(instruction[1]):int(instruction[2]) + 1])
    elif instruction[0] == 'reverse':
        string = string.replace(string[int(instruction[1]):int(instruction[2])+1], string[int(instruction[1]):int(instruction[2])+1][::-1], 1)
    elif instruction[0] == 'replace':
        string = string[:int(instruction[1])] + instruction[3] + string[int(instruction[1])+1:]

Submission status: Wrong Answer

Solution code:
st, q = input(), int(input())
for _ in range(q):
    order = list(map(str, input().split()))
    a, b = int(order[1]), int(order[2])
    if order[0] == "print":
        print(st[a:b+1])
    elif order[0] == "reverse":
        if a == 0:
            st = st[b::-1].join(st.rsplit(st[a:b+1]))
        else:
            st = st[b:a-1:-1].join(st.rsplit(st[a:b+1]))
    else:
        st = st.replace(st[a:b+1], order[3])

Submission status: Wrong Answer

Solution code:
st, q = input(), int(input())
for _ in range(q):
    order = list(map(str, input().split()))
    a, b = int(order[1]), int(order[2])
    if order[0] == "print":
        print(st[a:b+1])
    elif order[0] == "reverse":
        if a == 0:
            st = st[b::-1].join(st.rsplit(st[a:b+1]))
        else:
            st = st[b:a-1:-1].join(st.rsplit(st[a:b+1]))
    else:
        if a == b:
            st = st[0:a] + order[3] + st[a+1:]
        else:
            st = st.replace(st[a:b+1], order[3])

Submission status: Wrong Answer

Solution code:
st, q = input(), int(input())
for _ in range(q):
    order = list(map(str, input().split()))
    a, b = int(order[1]), int(order[2])
    if order[0] == "print":
        print(st[a:b+1])
    elif order[0] == "reverse":
        if a == 0:
            st = st[b::-1].join(st.rsplit(st[a:b+1]))
        else:
            st = st[b:a-1:-1].join(st.rsplit(st[a:b+1]))
    else:
        if a == b:
            if a == len(st):
                st = st[0:a] + order[3]
            else:
                st = st[0:a] + order[3] + st[a+1:]
        else:
            st = st.replace(st[a:b+1], order[3])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
methods = {'print': lambda s, b, e: (s, print(s[b:e+1])),
           'reverse': lambda s, b, e: (s[:b] + s[e:b-len(s)-1:-1] + s[e+1:],),
           'replace': lambda s, b, e, r: (s.replace(s[b:e+1], r),)}
for _ in range(n):
    args = input().split(' ')
    method = args[0]
    args[1] = int(args[1])
    args[2] = int(args[2])
    s = methods[method](s, *args[1:])[0]

Submission status: Wrong Answer

Solution code:
s = input()
for _ in range(int(input())):
  q = input()
  if q.startswith('replace'):
    q, a, b, p = q.split()
    a = int(a)
    b = int(b)
    s = s.replace(s[a:b+1], p)
  elif q.startswith('reverse'):
    q, a, b = q.split()
    a = int(a)
    b = int(b)
    s = s[a:b+1][::-1]+s[b+1:]
  elif q.startswith('print'):
    q, a, b = q.split()
    a = int(a)
    b = int(b)
    print(s[a:b+1])

Submission status: Wrong Answer

Solution code:
s = input()
for _ in range(int(input())):
  q = input()
  if q.startswith('replace'):
    q, a, b, p = q.split()
    a = int(a)
    b = int(b)
    s = s.replace(s[a:b+1], p)
  elif q.startswith('reverse'):
    q, a, b = q.split()
    a = int(a)
    b = int(b)
    s = s[:a]+s[a:b+1][::-1]+s[b+1:]
  elif q.startswith('print'):
    q, a, b = q.split()
    a = int(a)
    b = int(b)
    print(s[a:b+1])

Submission status: Wrong Answer

Solution code:
str=input()
q=eval(input())
command=[]
replace=[]
numdata=[]
for i in range(q):
    x=input()
    if 'replace' in x:
        a,b,c,d=x.split()
        replace.append(d)
        numdata.append((int(b),int(c)))
    else:
        a,b,c=x.split()
        numdata.append((int(b),int(c)))
    command.append(a)
Re=iter(replace)
for i in range(q):
    if command[i]=='print':
        print(str[numdata[i][0]:numdata[i][1]+1])
    elif command[i]=='reverse':
        str=str[:numdata[i][0]]+str[numdata[i][1]:numdata[i][0]-1:-1]+str[numdata[i][1]+1:]
    else:
        str=str[:numdata[i][0]]+next(Re)+str[numdata[i][1]+1:]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input()
n = int(input())
for i in range(n):
    order = input().split()
    if order[0] == "print":
        print(line[int(order[1])-1:int(order[2])-1])
    elif order[0] == "reverse":
        tmp = line[int(order[1]) - 1:int(order[2]) - 1]
        line = line[:int(order[1]) - 1] + tmp[::-1] + line[int(order[2]) - 1:]
    elif order[0] == "replace":
        line = line[:int(order[1]) - 1] + order[3] + line[int(order[2]) - 1:]

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    s = sys.stdin.readline().strip('\n')
    q = int(sys.stdin.readline().strip('\n'))

    for instruction in range(q):
        words = [word for word in sys.stdin.readline().strip('\n').split()]

        if words[0] == 'replace':
            s = s.replace(s[int(words[1]):int(words[2])+1], words[3])
        elif words[0] == 'reverse':
            s = s.replace(s[int(words[1]):int(words[2])+1],
                          ''.join(reversed(s[int(words[1]):int(words[2])+1])))
        elif words[0] == 'print':
            print(s[int(words[1]):int(words[2])+1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    s = sys.stdin.readline().strip('\n')
    q = int(sys.stdin.readline().strip('\n'))

    for instruction in range(q):
        words = [word for word in sys.stdin.readline().strip('\n').split()]
        print(words)
        if words[0] == 'replace':
            s = s[:int(words[1])] + words[3] + s[int(words[2])+1:]
        elif words[0] == 'reverse':
            s = s[:int(words[1])] \
                    + ''.join(reversed(s[int(words[1]):int(words[2])+1])) \
                    + s[int(words[2])+1:]
        elif words[0] == 'print':
            print(s[int(words[1]):int(words[2])+1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
word=''
com = ""
a = 0
b = 0
word=str(raw_input())
num=int(raw_input())
for i in range(num):
    add= raw_input().split()
    com = add[0]
    a = int(add[1])
    b = int(add[2])
    if com == 'replace':
        word = word.replace(word[a:b+1],add[3])
    elif com == 'reverse':
        tmp = word[a:b+1]
        word = word[0:a] + tmp[::-1] + word[b+1:]
    elif com == 'print':
        print word[a:b+1]
    else :
        break

Submission status: Wrong Answer

Solution code:
s = input()
line = int(input())

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

    if len(param) == 4: ope, a, b, p = param
    else: ope, a, b = param

    a,b = int(a), int(b)

    if ope == "print":
        print(s[a:b+1])
    elif ope == "reverse":
        rev = s[a:b+1][::-1]
        print(rev)
        s = (s[:a] + rev + s[b+1:])
    elif ope == "replace":
        s = (s[:a] + p + s[b+1:])

Submission status: Wrong Answer

Solution code:
str1 = list(input())
q = int(input())

for i in range(q):
	order = [str(x) for x in input().split()]
	if order[0] == 'replace':
		str1[int(order[1]):int(order[2])+1] = list(order[3]) 
		print(str1)
	elif order[0] == 'reverse':
		str2 = str1[int(order[1]):int(order[2])+1]
		str1[int(order[1]):int(order[2])+1] = reversed(str2)
			
	else: #print
		print(str1[int(order[1]):int(order[2])+1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
str, q = input(), int(input())
for i in range(q):
    com = input().strip().split()
    if com[0] == 'print':
        print(str[int(com[1]):int(com[2])+1])
    elif com[0] == 'reverse':
        str = list(str)
        str[int(com[1]):int(com[2])+1] = str[int(com[2]):int(com[1])-6:-1]
        str = ''.join(str)
        print(str)
    elif com[0] == 'replace':
        str = str.replace(str[int(com[1]):int(com[2])+1], com[3])
        print(str)

Submission status: Wrong Answer

Solution code:
str, q = input(), int(input())
for i in range(q):
    com = input().strip().split()
    if com[0] == 'print':
        print(str[int(com[1]):int(com[2])+1])
    elif com[0] == 'reverse':
        str = list(str)
        str[int(com[1]):int(com[2])+1] = str[int(com[2]):int(com[1])-6:-1]
        str = ''.join(str)
    elif com[0] == 'replace':
        str = str.replace(str[int(com[1]):int(com[2])+1], com[3])

Submission status: Wrong Answer

Solution code:
str, q = input(), int(input())
for i in range(q):
    com = input().strip().split()
    if com[0] == 'print':
        print(str[int(com[1]):int(com[2])+1])
    elif com[0] == 'reverse':
        str = list(str)
        str[int(com[1]):int(com[2])+1] = str[int(com[2]):int(com[1])-len(str)-1:-1]
        str = ''.join(str)
    elif com[0] == 'replace':
        str = str.replace(str[int(com[1]):int(com[2])+1], com[3])

Submission status: Wrong Answer

Solution code:
tes = input()
for mak in range(int(input())) :
    ins = input().split()
    ins[1], ins[2] = int(ins[1]), int(ins[2])
    if ins[0] == 'replace' :
        tes = tes.replace(tes[ins[1] : ins[2] + 1], ins[3])
    elif ins[0] == 'reverse' :
        tem = tes[ins[1] : ins[2] + 1]
        tem = tem[::-1]
        tes = tes.replace(tes[ins[1] : ins[2] + 1], tem)
    elif ins[0] == 'print' :
        print(tes[ins[1] : ins[2] + 1])

Submission status: Wrong Answer

Solution code:
text = input()
times = int(input())

for i in range(times):
    function = input().split()
    word = text[int(function[1]):int(function[2])+1]

    if function[0] == "print":
        print(word)

    elif function[0] == "reverse":
        word_reverse = word[::-1]
        text = text.replace(word,word_reverse)

    elif function[0] == "replace":
        text = text.replace(word,function[3])

Submission status: Wrong Answer

Solution code:
def print_func(s, order):
    print(s[order[1]:order[2]+1])


def reverse_func(s, order):
    ans = list(s[order[1]:order[2]+1])
    ans.reverse()
    s = s[:order[1]]+''.join(ans)+s[order[2]+1:]
    return s


def replace_func(s, order):
    s = s.replace(s[order[1]:order[2]+1], order[3])
    return s


if __name__ == '__main__':
    s = input()
    for i in range(int(input())):
        order = input().split()
        order[1] = int(order[1])
        order[2] = int(order[2])
        if order[0] == 'print':
            print_func(s, order)
        elif order[0] == 'reverse':
            s = reverse_func(s, order)
        else:
            s = replace_func(s, order)

Submission status: Wrong Answer

Solution code:
word = input()
q = int(input())

for _ in range(q):
    s = input().split(" ")
    command = s[0]
    a = int(s[1])
    b = int(s[2])

    if command == "print":
        print(word[a:b+1])
    elif command == "reverse":
        word = word[:a] + word[a:b+1][::-1] + word[b+1:]
    elif command == "replace":
        word = word.replace( word[a:b+1], s[3] )

Submission status: Wrong Answer

Solution code:
word = input()
q = int(input())

for _ in range(q):
    s = input().split(" ")
    command = s[0]
    a = int(s[1])
    b = int(s[2])

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

string = input()

n = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings.replace(self.strings[int1:int2+1], str1)
            print(self.strings)

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]
            print(self.strings)

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings.replace(self.strings[int1:int2+1], str1)

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings[:int1] + str1 + self.strings[int2+1:]
            #self.strings = self.strings.replace(self.strings[int1:int2+1], str1)
            print(self.strings)

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]
            print(self.strings)

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
for i in range(n):
    order = input().split()
    order[1] = int(order[1])
    order[2] = int(order[2])
    if order[0] == "print":
        print(s[order[1]: order[2] + 1])
    if order[0] == "replace":
        s = s.replace(s[order[1]: order[2] + 1], order[3])
    if order[0] == "reverse":
        i = order[1]
        j = order[2]
        half = int((j - i) / 2)
        s = list(s)
        while i <= half\
        or    i <= j:
            t = s[i]
            s[i] = s[j]
            s[j] = t
            i += 1
            j -= i
        s = "".join(s)

Submission status: Wrong Answer

Solution code:
s = list(input())
q = int(input())
for i in range(q):
    cmd = list(input().split())
    m = int(cmd[1])
    n = int(cmd[2])
    if cmd[0] == "print":
        for i in range(m, n + 1):
            print(s[i], end="")
        print()

    if cmd[0] == "reverse":
        half = int((n + 1 - m) / 2)
        while m <= half\
        or    m < n:
            t = s[m]
            s[m] = s[n]
            s[n] = t
            m += 1 
            n -= 1

    if cmd[0] == "replace":
        r = cmd[3]
        j = 0
        for i in range(m, n + 1):
            s[i] = r[j]
            j += 1

Submission status: Wrong Answer

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