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

Submission status: Accepted

Solution code:
# inputs
text = input()
num = int(input())
orders = []
for i in range(num):
    orders.append(input().split())

# output
for order in orders:
    r1 = int(order[1])
    r2 = int(order[2])
    if order[0] == 'print':
        print(text[r1:r2+1])
    elif order[0] == 'reverse':
        if r1 == 0:
            text = text[:r1] + text[r2::-1] + text[r2+1:]
        else:
            text = text[:r1] + text[r2:r1-1:-1] + text[r2+1:]
    elif order[0] == 'replace':
        text = text[:r1] + order[3] + text[r2+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for i in range(n):
    line = input().split()
    a = int(line[1])
    b = int(line[2])

    if line[0] == 'replace':
        to = line[3]
        s = s[0:a] + to + s[b + 1:]
    elif line[0] == 'reverse':
        s = s[0:a] + ''.join(reversed([c for c in s[a:b+1]])) + s[b + 1:]
    else:
        print(s[a:b + 1])

Submission status: Accepted

Solution code:
str = input()
l = len(str)
for _ in range(int(input())):
    r = input().split()
    a = int(r[1])
    b = int(r[2])
    if r[0] == 'print':
        print(str[a:b+1])
    elif r[0] == 'reverse':
        str = str[:a] + str[b-l:a-l-1:-1] + str[b+1:]
    else:
        str = str[:a] + r[3] + str[b+1:]

Submission status: Accepted

Solution code:
s=input()
for i in range(int(input())):
    t=input().split()
    opr=t[0];a=int(t[1]);b=int(t[2])
    if t[0]=='print':
        print(s[a:b+1])
    elif t[0]=='reverse':
        s=s[:a]+''.join(list(reversed(s[a:b+1])))+s[b+1:]
    elif t[0]=='replace':
        p=t[3]
        s=s[:a]+p+s[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str = input()
num = int(input())
for i in range(num):
    line = input()
    if line.startswith("print"):
        op,a,b = line.split()
        print(str[int(a):int(b)+1])
    elif line.startswith("replace"):
        op,a,b,c = line.split()
        x = str[0:int(a)]
        y = c
        z = str[int(b)+1:]
        str = x + y +z
    elif line.startswith("reverse"):
        op,a,b = line.split()
        x = str[0:int(a)]
        y = str[int(a):int(b)+1]
        y = y[::-1]
        z = str[int(b)+1:]
        str = x + y + z

Submission status: Accepted

Solution code:
str_normal = input()
str = [i for i in str_normal]
for k in range(int(input())):
	list = [i for i in input().split()]
	
	if list[0]=="print":
		a =int(list[1])
		b =int(list[2])
		str_print=[]
		for i in range(a,b+1):
			str_print +=str[i] 
		print("".join(str_print))
	
	if list[0]=="reverse":
		a =int(list[1])
		b =int(list[2])
		str_a = str[a:b+1]
		str_a.reverse()
		cnt = 0
		for i in range(a,b+1):
			str[i] = str_a[cnt]
			cnt+=1
		
	if list[0]=="replace":
		a =int(list[1])
		b =int(list[2])
		p =list[3]
		p_list=[i for i in p]
		cnt =0
		for i in range(a,b+1):
			str[i]= p_list[cnt]
			cnt+=1

Submission status: Accepted

Solution code:
str=input()
q = int(input())
for i in range(q):
    s = input().split()

    command = s[0]
    a=int(s[1])
    b=int(s[2])

    if command=="print":
        print(str[a:b+1])
    elif command=="reverse":
        restr=str[a:b+1]
        restr=restr[::-1]
        str = str[:a]+restr+str[b+1:]
        #print(str)
    elif command=="replace":
        p=s[3]
        str = str[:a]+p+str[b+1:]
        #print(str)

Submission status: Accepted

Solution code:
#coding: utf-8

s = input()
lenS = len(s)
q = int(input())
for i in range(q):
    temp = list(map(str, input().split()))
    idxA = int(temp[1])
    idxB = int(temp[2])
    if temp[0] == 'print':
        print(s[idxA:idxB + 1])
    else:
        head = s[:idxA]
        tail = s[idxB + 1:]
        if temp[0] == 'replace':
            body = temp[3]
        else:
            body = s[idxA:idxB + 1]
            body = body[::-1]
        s = head + body + tail

Submission status: Accepted

Solution code:
def test():

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

	for i in range(n):

		operation = input().split()

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

		if operation[0] == "print":
			print(str[a:b+1])

		elif operation[0] == "reverse":
			if a != 0:
				str = str[0:a] + str[b:a-1:-1] + str[b+1:len(str)]
			else:
				str = str[b::-1] + str[b+1:len(str)]

		elif operation[0] == "replace":
			p = operation[3]
			str = str[0:a] + p + str[b+1:len(str)]


if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
s = list(input())
n = int(input())

for i in range(n):
    orders = input().split()
    order, a, b, *moji = orders
    a = int(a)
    b = int(b)
    
    if order == "print":
        print(''.join(s[a:b+1]))
    elif order == 'reverse':
        s[a:b+1] = s[a:b+1][::-1]
    else:
        s[a:b+1] = moji[0]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()
n = int(input())
for _ in range(n):
    r, a, b, *p = input().split()
    a = int(a)
    b = int(b) + 1 
    if r == "replace":
        s = s[:a] + p[0] + s[b:]
    elif r == "reverse":
        s = s[:a] + s[a:b][::-1] + s[b:]
    elif r == "print":
        print(s[a:b])
    else:
        print("unknown")

Submission status: Accepted

Solution code:
#ITP1_9_D

def pri(s,f,l):
	for i in range(f,l+1):
		print(s[i],end="")
	print()

def rev(s,f,l):
	while f < l:
		tmp=s[f]
		s[f]=s[l]
		s[l]=tmp
		f+=1
		l-=1

def rep(s,f,l,p):
	for i in range(l-f+1):
		s[f+i]=p[i]

s=list(input())

for i in range(int(input())):
	x=input().split()
	x[1]=int(x[1])
	x[2]=int(x[2])
	if "print" == x[0]:
		pri(s, x[1], x[2])
	elif "reverse" == x[0]:
		rev(s, x[1], x[2])
	elif "replace" == x[0]:
		rep(s, x[1], x[2], list(x[3]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
line = sys.stdin.readline() 
word = line.rstrip('\r\n') 
sys.stdin.readline() 
while True:
    if not line: break 
    line = sys.stdin.readline() 
    line = line.rstrip('\r\n') 
    words = line.split()
    if len(line) == 0:
        break   
    else:
        words = line.split()
        if words[0] == "print":
            a = int(words[1])
            b = int(words[2])
            print(word[a:b+1])
        elif words[0] == "reverse":
            a = int(words[1])
            b = int(words[2])
            rep = ""
            for i in range(b,a-1,-1):
                rep += word[i]
            word = word[:a] + rep + word[b+1:] 
        elif words[0] == "replace":
            a = int(words[1])
            b = int(words[2])
            word = word[:a] + words[3] + word[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str = list(input())
for i in range(int(input())):
    cmd, a, b, *c = input().split()
    a = int(a); b = int(b)
    if cmd == "print":
        print(*str[a:b+1], sep='')
    elif cmd == "reverse":
        str[a:b+1] = reversed(str[a:b+1])
    else:
        str[a:b+1] = c[0]

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 = list(input())
for _ in [0]*int(input()):
    cmd, a, b, *p = input().split()
    a = int(a); b = int(b) + 1
    if cmd == 'print':
        print(*s[a:b], sep='')
    if cmd == 'reverse':
        s[a:b] = reversed(s[a:b])
    if cmd == 'replace':
        s[a:b] = p[0]

Submission status: Accepted

Solution code:
s = list(str(input()))
q = int(input())
o = ['']*q
for i in range(q):
    o[i] = str(input())
     
for i in range(q):
    order = o[i].split(' ')
    if order[0] == 'print':
        a,b = int(order[1]),int(order[2])
        for i in range(a,b+1):
            print(s[i],end = '')
        print('')
 
    elif order[0] == 'reverse':
        a,b = int(order[1]),int(order[2])
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp        
         
    elif order[0] == 'replace':
        a,b,p = int(order[1]),int(order[2]),list(order[3])
        for i in range(b-a+1):
            s[a+i] = p[i]

Submission status: Accepted

Solution code:
s = input()
m = int(input())
for i in range(m):
    com, *lw = map(str, input().split())
    if com == "replace":
        s = s[:int(lw[0])] + lw[2] + s[int(lw[1]) + 1:]
    if com == "reverse":
        t = s[int(lw[0]):int(lw[1]) + 1]
        s = s[:int(lw[0])] + t[::-1] + s[int(lw[1]) + 1:]
    if com == "print":
        print(s[int(lw[0]):int(lw[1]) + 1])

Submission status: Accepted

Solution code:
S = input()
N = int(input())

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

Submission status: Accepted

Solution code:
def my_print(lst,a,b):
    for i in range(a,b+1):
        print(lst[i],end='')
    print()

def reverse(lst,a,b):
    lst2 = lst[a:b+1]
    lst2.reverse()
    lst[a:b+1] = lst2
    
    
str1 = list(input())
n = int(input())
for i in range(n):
    str2 = input().split()
    if str2[0]=='print':
        a,b = int(str2[1]),int(str2[2])
        my_print(str1,a,b)
    if str2[0]=='replace':
        a,b,p = int(str2[1]),int(str2[2]),str2[3]
        str1[a:b+1]=p
    if str2[0]=='reverse':
        a,b = int(str2[1]),int(str2[2])
        reverse(str1, a, b)

Submission status: Accepted

Solution code:
def splitString(target, start, end):
    first = target[:start]
    middle = target[start:end + 1]
    last = target[end + 1:]
    return (first, middle, last)

def doReplace(target, args):
    start = int(args[0])
    end = int(args[1])
    replace_str = args[2]

    first, _, last = splitString(target, start, end)

    return first + replace_str + last


def doReverse(target, args):
    start = int(args[0])
    end = int(args[1])

    first, middle, last = splitString(target, start, end)

    return first + middle[::-1] + last


def makeMessage(target, args):
    start = int(args[0])
    end = int(args[1])

    _, middle, _ = splitString(target, start, end)

    return middle


def transform():
    messages = []  # プリント用文字を格納するリスト
    target = input()
    q = int(input())

    for _ in range(q):
        line = input()
        cmd = line.split(' ')[0]
        args = line.split(' ')[1:]

        # 各命令を実行
        if cmd == 'print':
            messages.append(makeMessage(target, args))
        elif cmd == 'replace':
            target = doReplace(target, args)
        elif cmd == 'reverse':
            target = doReverse(target, args)
    # 各メッセージの表示
    [print(message) for message in messages]


def kantanna_test(expected, actual):
    if expected == actual:
        print('OK')
    else:
        print('NG')


if __name__ == '__main__':

    transform()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
q_text = str(input())
q_num = int(input())

for i in range(q_num):
  q = input()
  if q.startswith("print"):
    command,a,b = q.split()
    a=int(a)
    b=int(b)
    print(q_text[a:b+1])
    
  elif q.startswith("reverse"):
    command,a,b = q.split()
    a=int(a)
    b=int(b)
    temp_text=q_text[a:b+1]
    q_text = q_text[:a] + temp_text[::-1] + q_text[b+1:]
    #print(q_text)
  
  elif q.startswith("replace"):
    command,a,b,p = q.split()
    a=int(a)
    b=int(b)
    q_text = q_text[:a] + p + q_text[b+1:]
    #print(q_text)

Submission status: Accepted

Solution code:
s = list(input())
q = int(input())
for i in range(q):
  
  r =list(map(str, input().split()))
  cmd = r[0]
  a = int(r[1])
  b = int(r[2])
  
  if cmd == "print":
    for j in range(a, b+1):
      print(s[j], end="")
    print("")
  elif cmd == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
  elif cmd == "replace":
    rep = list(r[3])
    count = 0
    for j in range(a,b+1):
      s[j] = rep[count]
      count = count + 1

Submission status: Accepted

Solution code:
str = input("")
q = int(input())

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

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

Submission status: Accepted

Solution code:
def souhei(a,b):
	c=int(a)
	d=int(b)
	return [c, d]
moji=input()
moji=list(moji)
P=int(input())
for pp in range(P):
	some=list(input().split())
	if some[0]=='print':
		some[1],some[2]=souhei(some[1],some[2])
		for a in range(some[1],some[2]+1):
			if a==some[2]:
				print(moji[a])
			else:
				print(moji[a],end='')
	elif some[0]=='reverse':
		some[1],some[2]=souhei(some[1],some[2])
		nn=0
		m=int((some[1]+some[2])/2)
		for bb in range(some[1],m+1):
			X=moji[bb]
			moji[bb]=moji[some[2]-nn]
			moji[some[2]-nn]=X
			nn+=1	
	elif some[0]=='replace':
		some[1],some[2] = souhei(some[1],some[2])
		g=some[3]
		g=list(g)
		n=0
		for oo in range(some[1],some[2]+1):
			moji[oo]=g[n]
			n+=1

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(num):
    commands = input()
    command = commands.split(" ")
    start = int(command[1])
    stop = int(command[2])
    if command[0] == "replace":
        char = char[0:start] + command[3] + char[stop+1:]
    elif command[0] == "reverse":
        if start == 0:
            char = char[stop:0:-1] + char[0] + char[stop+1:]
        else:
            char = char[:start] + char[stop:start-1:-1] + char[stop+1:]
    elif command[0] == "print":
        print(char[start:stop+1])
    else:
        break

Submission status: Accepted

Solution code:
#ITP1_9_D
S=input()
n=int(input())
for j in range(n):
  M=list(map(str,input().split()))
  a=int(M[1])
  b=int(M[2])
  if(M[0]=="print"):
    print(S[a:b+1])
  elif M[0]=="reverse":
    S=S[:a]+S[a:b+1][::-1]+S[b+1:]
  elif M[0]=="replace":
    S=S[:a]+M[3]+S[b+1:]

Submission status: Accepted

Solution code:
s = list(input())
for i in range(int(input())):
  cmd, a, b, *c = input().split()
  a = int(a); b = int(b)
  if cmd == "print":
    print(*s[a:b+1], sep='')
  elif cmd == "reverse":
    s[a:b+1] = reversed(s[a:b+1])
  else:
    s[a:b+1] = c[0]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
n = int(input())
order = []
rep = []
l = []
a = 0
b = 0
toprint = ""
for i in range(n):
    order = input().split()
    a = int(order[1])
    b = int(order[2])
    if len(order)==4:
        rep = list(order[3])
        for j in range(len(rep)):
            s[j+a]=rep[j]
    elif order[0]=="reverse":
        l = ["" for k in range(b-a+1)]
        for j in range(len(l)):
            l[j]=s[j+a]
        l.reverse()
        for j in range(len(l)):
            s[j+a]=l[j]
    else:
        toprint=""
        for j in range(b-a+1):
            toprint+=s[j+a]
        print(toprint)

Submission status: Accepted

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

for _ in range(n):
    ops = input().split()
    a = int(ops[1])
    b = int(ops[2])+1

    if ops[0] == 'print':
        print(w[a:b])

    if ops[0] == 'reverse':
        w = w[:a] + str(w[a:b])[::-1] + w[b:]

    if ops[0] == 'replace':
        p = ops[3]
        w = w[:a] + p + w[b:]

Submission status: Accepted

Solution code:
str = input()
q = int(input())  # 命令の数
for i in range(q):
    order = input().split()
    if order[0] == "print":
        a = int(order[1])
        b = int(order[2])
        print(str[a:b+1])
    elif order[0] == "reverse":
        a = int(order[1])
        b = int(order[2])
        rev_str = "".join(list(reversed(str[a:b+1])))
        str = str[:a] + rev_str + str[b+1:]
    elif order[0] == "replace":
        a = int(order[1])
        b = int(order[2])
        str = str[:a] + order[3] + str[b+1:]

Submission status: Accepted

Solution code:
s = input()
q = int(input())
 
for i in range(q):
    line = input().split()
     
    if len(line) == 4:
        com,a,b,r = line
        a,b = int(a),int(b)
        s = s[:a] + r + s[b+1:]
    else:
        com,a,b = line
        a,b = int(a),int(b)
        if com == "print":
            print(s[a:b+1])
        else:
            sab = s[a:b+1]
            s = s[:a] + sab[::-1] + s[b+1:]

Submission status: Accepted

Solution code:
s = str(input())
 
q = int(input())
 
d_list=[]
for i in range(q):
  s2 = ''
   
  d = list(map(str, input().split()))
  if d[0] == 'print':
    print( s[ int(d[1]): int(d[2])+1 ] )
     
  elif d[0] == 'reverse':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = reversed(S[int(d[1]):int(d[2])+1])
    for i in S:
      s2 += i
    s = s2
    
  elif d[0] == 'replace':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = list(d[3])
    for i in S:
      s2 += i
    s = s2

Submission status: Accepted

Solution code:
s = str(input())

q = int(input())

d_list=[]
for i in range(q):
  s2 = ''
  
  d = list(map(str, input().split()))
  if d[0] == 'print':
    print( s[ int(d[1]): int(d[2])+1 ] )
    
  elif d[0] == 'reverse':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = reversed(S[int(d[1]):int(d[2])+1])
    for i in S:
      s2 += i
    s = s2
   
  elif d[0] == 'replace':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = list(d[3])
    for i in S:
      s2 += i
    s = s2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str=list(input())
N=int(input())
for i in range(N):
    order=list(input().split())
    x=int(order[1])
    y=int(order[2])
    z=len(str)
    if order[0]=='replace':
        str[x:y+1]=order[3]
    elif order[0]=='reverse':
        strage=str[::-1]
        str[x:y+1]=strage[z-1-y:z-x]
    else:
        printstr=''.join(str[x:y+1])
        print(printstr)

Submission status: Accepted

Solution code:
ans = input()
n = int(input())
for _ in range(n):
    o = input().split()
    a, b = map(int, o[1:3])
    b += 1
    c = o[0][2]
    if c == "p":
        ans = ans[:a] + o[3] + ans[b:]
    elif c == 'i':
        print(ans[a:b])
    else:
        ans = ans[:a] + ans[a:b][::-1] + ans[b:]

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    input_str = list(input())
    op_num = int(input())
    for _ in range(op_num):
        operations = input().split()
        op_name = operations[0]
        beg_idx = int(operations[1])
        end_idx = int(operations[2]) + 1
        if "replace" == op_name:
            replace_str = list(operations[3])
            input_str[beg_idx:end_idx] = replace_str
        elif "reverse" == op_name:
            input_str[beg_idx:end_idx] = reversed(input_str[beg_idx:end_idx])
        else:
            print("".join(input_str[beg_idx:end_idx]))

Submission status: Accepted

Solution code:
s = input()
st = list(s)
D = []
n = int(input())
for i in range(n) : 
  B = input().split()
  a = int(B[1])
  b = int(B[2])
  if B[0] == 'print' :
   
    st[a : b+1] = ''.join(st[a:b+1])
    if st[a : b+1] not in D :     
      D.append(''.join(st[a : b+1]))
    
    
  elif B[0] == 'reverse' :
    C = st[a : b + 1]
    C.reverse()
    del st[a : b + 1]
    st[a : a] = C

  elif B[0] == 'replace' :
    del st[a : b + 1]
    st[a : a] = B[3]
    
   
    
st  = ''.join(st) 


for i in D :
  print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
        except EOFError:
            break
    return N

S = input()
N = int(input())
P = []

for i in range(N):
    P.append([x for x in input().split()])

for M in P:
    if M[0] == 'print':
        a = int(M[1])
        b = int(M[2])+1
        print(S[a:b])
    elif M[0] == 'reverse':
        a = int(M[1])
        b = int(M[2])+1
        T = S[a:b]
        S = S[:a]+T[::-1]+S[b:]
    elif M[0] == 'replace':
        a = int(M[1])
        b = int(M[2])+1
        S = S[:a]+M[3]+S[b:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
order = []
str = input()
#print(str)
q = int(input())
for i in range(q):
    s = input().split()
    order.append(s)
#print(order)

for i in range(q):
    a = int(order[i][1])
    b = int(order[i][2])
    #print('a,b=',a,b)
    if order[i][0] == 'print':
            print(str[a:(b+1)])
    elif order[i][0] == 'replace':
        str = str[:a] + order[i][3] + str[(b+1):]
        #print('replace',str)
    elif order[i][0] == 'reverse':
        new_str = list(str[a:(b+1)])
        new_str.reverse()
        new_str = ''.join(new_str)
        str = str[:a] + new_str + str[(b+1):]
        #print('reverse',str)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#class#############################################
class orders():
    def __init__(self,str):
        self.str=str
        
    def printout(self,a,b):
        result=""
        array=[]
        array=list(self.str)

        for i in range(a,b+1):
            result=result+array[i]
        print(result)
    
    def reverse(self,a,b):
        result_r=""
        re_array=[]
        array_r=[]
        array_r=list(self.str)

        for i in range(0,a):
            result_r=result_r+array_r[i]
       
        for j in range(a,b+1):
           
            re_array.append(array_r[j])
          
        for jj in re_array[::-1]:
            result_r=result_r+jj
            
        for k in range(b+1,len(array_r)):
            result_r=result_r+array_r[k]

        self.str=result_r
     
    def replace_out(self,a,b,p):
        result_p=""
        array_r=[]
        array_r=list(self.str)
        for i in range(0,a):
            result_p=result_p+array_r[i]
        
        result_p=result_p+p

        for k in range(b+1,len(array_r)):
            result_p=result_p+array_r[k]
        
        self.str=result_p
###########################################
if __name__=="__main__":
    
    input_text=input()

    number=input()
    num=int(number)
    i=1
    object1=orders(input_text)
    while i <=num:
        in_array=[]
        inp=""
        inp=input()
        in_array=inp.split()

        if in_array[0]=="replace":
            object1.replace_out(int(in_array[1]),int(in_array[2]),in_array[3])
           
        
        elif in_array[0]=="reverse":
            object1.reverse(int(in_array[1]),int(in_array[2]))

        elif in_array[0]=="print":
            object1.printout(int(in_array[1]),int(in_array[2]))

        i=i+1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
for i in range(int(input())):
    op, a, b, *p = input().split()
    a, b = int(a), int(b)
    
    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[0] + s[b + 1:]
        
    else:
        print('op error')