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: Accepted

Solution code:
w = str(input())
n = int(input())
while ( n > 0 ):
    n = n -1
    l  =  list(map(str,input().split()))
    if (l[0] == "print" ):
        print (w[int(l[1]):int(l[2])+1])
    elif(l[0] == "replace"):
        p1 = int(l[1])
        p2 = int(l[2])
        w = w[:p1] + l[3] + w[p2+1:]
    elif(l[0] == "reverse"):
        p1 = int(l[1])
        p2 = int(l[2])
        t1 = w[:p1]
        t2 = w[p1:p2+1]
        t3 = w[p2+1:]
        w = t1 + t2[::-1] + t3

Submission status: Accepted

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

Submission status: Accepted

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

printlist = []

for _ in range(q):
    c = list(map(str, input().split()))
    start = int(c[1])
    end = int(c[2]) + 1

    if c[0] == "print":
        printlist.append(s[start:end])
    elif c[0] == "reverse":
        r = s[start:end]
        sr = r[::-1]
        s = s[:start] + sr + s[end:]
    elif c[0] == "replace":
        r = c[3]
        s = s[:start] + r + s[end:]

for p in printlist:
    print(p)

Submission status: Accepted

Solution code:
str_chr = input()
n = int(input())
order = []

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

Submission status: Accepted

Solution code:
def merge(A,i,B):#リストAのi番目にリストBを挿入したリストを返す
    A_1=A[0:i]
    A_2=A[i:len(A)]
    return A_1 +B + A_2


str = input()
str =list(str)
n=int(input())
for i in range(0,n):
    order=input().split()
    order[1]=int(order[1])
    order[2]=int(order[2])
    if(order[0]=="print"):
        print("".join(str[order[1]:order[2]+1]))
    elif(order[0]=="replace"):
        del str[order[1]:order[2]+1]
        str=merge(str,order[1],list(order[3]))
    elif(order[0]=="reverse"):
        key=str[order[1]:order[2]+1]
        key.reverse()
        del str[order[1]:order[2]+1]
        str=merge(str,order[1],key)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
	line = input().split()
	com = line[0]
	x = int(line[1])
	y = int(line[2])
	
	if com == 'replace':
		str = str[:x]+line[3]+str[y+1:]
	elif com == 'reverse':
		str = str[:x]+str[x:y+1][::-1]+str[y+1:]
	elif com == 'print':
		print(str[x:y+1])

Submission status: Accepted

Solution code:
s = input()
command_n = int(input())
for i in range(command_n):
    command, a, *b = [int(i) if i.isdigit() else i for i in input().split() ]
    
    if command == "print":
        b = b[0]
        print(s[a:b+1])
    if command == "reverse":
        b = b[0]
        s_ab = s[a:b+1]
        s = s.replace(s_ab, s_ab[::-1])
    if command == "replace":
        b, p = b[0], b[1]
        L_s = list(s)
        L_s[a:b+1] = p
        s = "".join(L_s)

Submission status: Accepted

Solution code:
s = str(input())
n = int(input())
m = []

for i in range(n):
    m = list(input().split())
    i1 = int(m[1])
    i2 = int(m[2])+1
    if m[0] == "replace":
        s = s[0:i1] + m[3] + s[i2::]
        # print(s)
    elif m[0] == "reverse":
        sr = s[i1:i2]
        sr = sr[::-1]
        s = s[0:i1] + sr + s[i2::]
        # print(s)
    elif m[0] == "print":
        print(s[i1:i2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str_in = input()
str_len = len(str_in)
n = int(input())

for i in range(0, n):
    c = input().split()
    if (c[0] == 'print'):
        print(str_in[int(c[1]) : int(c[2]) + 1])
    elif (c[0] == 'reverse'):
        temp = ''
        for l in str_in[int(c[1]) : int(c[2]) + 1]:
            temp = l + temp
        str_in = str_in[0 : int(c[1])] + temp + str_in[int(c[2]) +1 : str_len]
    elif (c[0] == 'replace'):
        str_in = str_in[0 : int(c[1])] + c[3] + str_in[int(c[2]) +1 : str_len]

Submission status: Accepted

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

for _ in range(n):
    x = list(map(str, input().split()))
    a, b = int(x[1]), int(x[2])
    if x[0] == "print":
        print(line[a:b+1])
    elif x[0] == "reverse":
        line = line[:a] + line[a:b+1][::-1] + line[b+1:]
    else:
        line = line[:a] + x[3] + line[b+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from enum import Enum
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


line = input()
num_query = int(input())

for loop in range(num_query):

    input_str = list(input().split())

    if input_str[0] == 'replace':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + input_str[3] + line[right:]

    elif input_str[0] == 'reverse':
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        line = line[:left] + line[left:right][::-1] + line[right:]

    else: #print
        left = int(input_str[1])
        right = int(input_str[2])
        right += 1
        for i in range(left,right):
            print(line[i],end = "")
        print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=input()
n=int(input())
for i in range(n):
    s=input()
    s=s.rstrip().split(" ")
    if s[0]=="replace":
        N=N[:int(s[1])]+s[3]+N[int(s[2])+1:]
    elif s[0]=="reverse":
        a=""
        for j in range(int(s[2])-int(s[1])+1):
            a=a+N[int(s[2])-j]
        N=N[:int(s[1])]+a+N[int(s[2])+1:]
    elif s[0]=="print":
        print(N[int(s[1]):int(s[2])+1])

Submission status: Accepted

Solution code:

st = input()
q = int(input())

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

Submission status: Accepted

Solution code:
# coding: utf-8
origin = input()
loops = int(input())

for _ in range(loops):
    command = input().split()
    start = int(command[1])
    end = int(command[2]) + 1

    # print('before : {}'.format(origin))
    if 'replace' in command:
        rep_str = command[3]
        origin = list(origin)
        for i, index in enumerate(range(start, end)):
            origin[index] = rep_str[i]
        origin = ''.join(origin)

    elif 'reverse' in command:
        rev_str = origin[start:end][::-1]
        origin = origin.replace(origin[start:end], rev_str)

    else:
        print(origin[start:end])
    
    # print('after  : {}'.format(origin))

Submission status: Accepted

Solution code:
def doIt(t, c):
	c = c.split()
	t = list(t)
	if c[0] == 'replace':
		j = 0
		temp = [x for x in c[3]]
		for i in range(int(c[1]), int(c[2]) + 1):
			t[i] = temp[j]
			j += 1
	elif c[0] == 'reverse':
		temp = t[int(c[1]):int(c[2]) + 1]
		j = len(temp) - 1
		for i in range(int(c[1]), int(c[2]) + 1):
			t[i] = temp[j]
			j -= 1
	else:
		print(''.join(t[int(c[1]):int(c[2])+1]))
	return ''.join(t)

text = input()
n = int(input())
while n > 0:
	text = doIt(text, input())
	n -= 1

Submission status: Accepted

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

if __name__ == '__main__':
    s = raw_input()
    q = int(raw_input())

    for _ in range(q):
        op = raw_input().split()
        a, b = map(int, op[1:3])
        p = ''.join(op[3:])
        op = op[0]

        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] + p + s[b+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = [s for s in input()]
p = int(input())
for _ in range(p):
	sy = input().split(' ')
	op = sy[0]
	a = int(sy[1])
	b = int(sy[2])
	if op == 'print':
		sh = ''
		for i in range(a,b+1): sh += S[i]
		print(sh)
	elif op == 'reverse':
		pick = []
		for i in range(a,b+1): pick.append(S.pop(a))
		for i,r in enumerate(reversed(pick)): S.insert(a+i, r)
	elif op == 'replace':
		q = [s for s in sy[3]]
		for i,s in enumerate(q):
			S.pop(a+i)
			S.insert(a+i, s)

Submission status: Runtime Error

Solution code:
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].reverse() + s[b:]
    else:
        s = s[:a] + t[3] + s[b:]

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
n = nt(input())
for i in range(n):
    order, a, b, c = input().split()
    if order == 'replace':
        s = s[:a] + c + s[b+1:]
    elif order[o] == 'r':
        s = s[:a] + a[a:b+1:-1] + a[b+1:]
    else:
        print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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 + s[b+1:]
    elif order[0] == 'r':
        s = s[:a] + s[::-1][a:b+1] + s[b+1:]
    else:
        print(s[a:b+1])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b+1):
        print(data[i])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] = "print"):
        op_print(data,int(num[0]),int(num[1]))
    elif(op[0] = "reverse"):
        data = op_reverse(data,int(num[0]),int(num[1]))
    elif(op[0] = "replace"):
        data = op_replace(data,int(num[0]),int(num[1]),num[2])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b+1):
        print(data[i])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(num[0]),int(num[1]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(num[0]),int(num[1]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(num[0]),int(num[1]),num[2])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b+1):
        print(data[i])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[0]),int(op[1]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[0]),int(op[1]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[0]),int(op[1]),op[2])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b+1):
        print(data[i])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b):
        print(data[i])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b):
        print(data[i],end="")
    print()
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]-1))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b):
        print(data[i],end="")
    print()
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2])-1)
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b):
        print(data[i],end="")
    print()
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b-1):
        print(data[i],end="")
    print()
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    for i in range(a,b):
        print(data[i-1],end="")
    print()
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    print(data[a:b])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    op[2] += 1
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    print(data[a:b])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()));num[2]+=1
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    print(data[a:b])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()));op[2]+=1
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

Solution code:
def op_print(data,a,b):
    print(data[a:b])
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    op[2]+=1
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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[int(c[1]):int(c[2])+1][::-1]+w[int(c[2])+1:]

Submission status: Runtime Error

Solution code:
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]

Submission status: Runtime Error

Solution code:
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] + p + s[b+1:]

Submission status: Runtime Error

Solution code:
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]

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
 snt=input()

 num=int(input())

 for i in range(num):
  ops=input().split()
  
  
  if ops[0]=="replace":
      snt[int(ops[1]):int(ops[2])]=ops[3]


  elif ops[0]=="print":
      snt=snt[int(ops[1]):int(ops[2])]


  elif ops[0]=="reverse":
      snt[int(ops[1]):int(ops[2])]=snt[int(ops[1]):int(ops[2])].reverse



 print(snt)

Submission status: Runtime Error

Solution code:
 snt=input()

 num=int(input())

 for i in range(num):
  ops=input().split()
  
  
  if ops[0]=="replace":
      snt[int(ops[1]):int(ops[2])+1]=ops[3]


  elif ops[0]=="print":
      snt=snt[int(ops[1]):int(ops[2])+1]


  elif ops[0]=="reverse":
      snt[int(ops[1]):int(ops[2])+1]=snt[int(ops[1]):int(ops[2])+1].reverse



 print(snt)

Submission status: Runtime Error

Solution code:
 snt=input()

 num=int(input())

 for i in range(num):
  ops=input().split()
  
  
  if ops[0]=="replace":
      snt[int(ops[1]):int(ops[2])+1]=ops[3]


  elif ops[0]=="print":
      snt=snt[int(ops[1]):int(ops[2])+1]
      print(snt)


  elif ops[0]=="reverse":
      snt[int(ops[1]):int(ops[2])+1]=snt[int(ops[1]):int(ops[2])+1].reverse



 print(snt)

Submission status: Runtime Error

Solution code:
 snt=input()

 num=int(input())

 for i in range(num):
  ops=input().split()
  
  
  if ops[0]=="replace":
      snt[int(ops[1]):int(ops[2])+1]=ops[3]


  elif ops[0]=="print":
      snt=snt[int(ops[1]):int(ops[2])+1]
      print(snt)


  elif ops[0]=="reverse":
      snt[int(ops[1]):int(ops[2])+1].reverse()



 print(snt)

Submission status: Runtime Error

Solution code:
 snt=input()

 num=int(input())

 for i in range(num):
  ops=input().split()
  
  
  if ops[0]=="replace":
      snt[int(ops[1]):int(ops[2])+1]=ops[3]


  elif ops[0]=="print":
      snt=snt[int(ops[1]):int(ops[2])+1]
      print(snt)


  elif ops[0]=="reverse":
      snt[int(ops[1]):int(ops[2])+1].reverse()

Submission status: Runtime Error

Solution code:
 snt=input()

 num=int(input())

 for i in range(num):
  ops=input().split()


  if ops[0]=="replace":
      snt=snt.replace(snt[int(ops[1]):int(ops[2])+1],ops[3])

  elif ops[0]=="print":
      snt=snt[int(ops[1]):int(ops[2])+1]
      print(snt)

  elif ops[0]=="reverse":
      snt=snt[:int(ops[1])]+ snt[int(ops[1]):int(ops[2])+1].reverse() + snt[int(ops[2]:])

Submission status: Runtime Error

Solution code:
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])]+ans1[3]+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]

Submission status: Runtime Error

Solution code:
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])]+ans1[3]+ 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]

Submission status: Runtime Error

Solution code:
string = input()
n = int(input())

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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":
        len = len(s)
        s = s[0:a] + s[-len+b:-len+a-1:-1] + s[b+1:]
    elif com == "replace":
        p = line[3]
        s = s.replace(s[a:b+1], p)
    else:
        print "Error"

Submission status: Runtime Error

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

#??\???
while 1:
	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 ] )
		elif op[0]=="print":
			print(str[a:b+1])

Submission status: Runtime Error

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

#??\???
while 1:
	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 ] )
		# elif op[0]=="print":
		# 	print(str[a:b+1])