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

for _ in range(int(input())):
    a, *b = input().split()
    if a == "replace":
        *b, p = b
    i, j = map(int, b)
    
    if a == "print":
        print(s[i:j+1])
    elif a == "reverse":
        s = s[:i] + s[i:j+1][::-1] + s[j+1:]
    else:
        s = s[:i] + p + s[j+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def print_str(a, b, str) -> None:
    for i in range(a, b + 1):
        print(str[i], end="")
    print()


s = 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_str(a, b, s)
    elif (cmd == "reverse"):
        s[a:b + 1] = reversed(s[a:b + 1])
    else:
        s[a:b + 1] = c[0]

Submission status: Accepted

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

for i in range(q):
    order_set = list(input().split())
    a, b = int(order_set[1]), int(order_set[2])

    if order_set[0] == "replace":
      string = string[:a] + order_set[3] + string[b+1:]
      
    if order_set[0] == "reverse":
      string = string[:a] + string[a:b+1][::-1] + string[b+1:]
      
    if order_set[0] == "print":
      print(string[a:b+1])

Submission status: Accepted

Solution code:
# Problem - 文字列変換

# input
in_str = list(input())
n = int(input())

# string process
for i in range(n):
    p = input().split()

    if p[0]=='replace':
        a = int(p[1])
        b = int(p[2])
        q = p[3]
        for j in range(len(q)):
            in_str[j+a] = q[j]
    elif p[0]=='reverse':
        a = int(p[1])
        b = int(p[2])
        tmp = in_str[a:b+1]
        tmp = tmp[::-1]
        for j in range(len(tmp)):
            in_str[j+a] = tmp[j]
    elif p[0]=='print':
        a = int(p[1])
        b = int(p[2])
        ans = in_str[a:b+1]
        print("".join(ans))

Submission status: Accepted

Solution code:
str=input()
q=int(input())
i=0
while i<q:
    ord=list(input().split())
    if ord[0]=="print":
        print(str[int(ord[1]):int(ord[2])+1])
    if ord[0]=="reverse":
        str_i = str[:int(ord[1])]
        str_re = str[int(ord[1]):int(ord[2])+1]
        str_re = str_re[::-1]
        str_f = str[int(ord[2])+1:]
        str=str_i+str_re+str_f
    if ord[0]=="replace":
        str_i = str[:int(ord[1])]
        str_f = str[int(ord[2])+1:]
        str=str_i+ord[3]+str_f
    i+=1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
q = int(input())
order = [[x for x in input().split()] for _ in range(q)]

for cmd, left, right, *etc in order:
    left=int(left)
    right=int(right) + 1
    if cmd=='replace':
        s = s[:left] + etc[0] + s[right:]
    elif cmd=='reverse':
        s = s[:left] + s[left:right][::-1] + s[right:]
    else:
        print(s[left:right])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def PRINT(S,a,b):
    print(S[a:b+1])
def REPLACE(S,T,a,b):
    return S[:a] + T + S[b+1:]
def REVERSE(S,a,b):
    tmp = S[a:b+1]
    return S[:a] + tmp[::-1] + S[b+1:] 

S = input()
q = int(input())

for i in range(q):
    order = list(input().split())
    a = int(order[1])
    b = int(order[2])
    if order[0] == "replace":
        S = REPLACE(S,order[3],a,b)
    elif order[0] == "reverse":
        S = REVERSE(S,a,b)
    else:
        PRINT(S,a,b)

Submission status: Accepted

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

for i in range(q):
    x = input().split()
    
    if len(x) == 3:
        order = x[0]
        first = int(x[1])
        second = int(x[2])
        
    else:
        order = x[0]
        first = int(x[1])
        second = int(x[2])
        change = x[3]
        
    
    if order == "print":
        print("".join(sentence[first : (second + 1)]))
        
    elif order == "reverse":
        if len(sentence[first : second + 1]) % 2 == 0:
            for i in range(int(len(sentence[first : second + 1]) / 2)):
                tmp = sentence[first + i]
                sentence[first + i] = sentence[second - i] 
                sentence[second - i] = tmp
                
        else:
            for i in range(len(sentence[first : second + 1] )// 2):
                tmp = sentence[first + i]
                sentence[first + i] = sentence[second - i] 
                sentence[second - i] = tmp
            
    else:
        sentence[first : second + 1] = change

Submission status: Accepted

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

Submission status: Accepted

Solution code:
moji = str(input())
num = int(input())
for i in range(num):
  s = input().rstrip().split(' ')
  command = str(s[0])
  if command == "print":
    start = int(s[1])
    end = int(s[2])
    print(moji[start:end+1])
  elif command == "reverse":
    start = int(s[1])
    end = int(s[2]) + 1
    moji2 = moji[start:end]
    moji3 = ''.join(list(reversed(moji2)))
    moji = moji[:start] + moji3 + moji[end:]
  elif command == "replace":
    start = int(s[1])
    end = int(s[2]) + 1
    beforerep = moji[start:end+1]
    rep = str(s[3])
    moji = moji[:start] + rep + moji[end:]

Submission status: Accepted

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

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

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:
s = input()
q = int(input())

for i in range(q):
    input_value = list(input().split())
    if len(input_value) == 4:
        c, a, b, p = ' '.join(input_value).split()
    else:
        c, a, b = ' '.join(input_value).split()

    a = int(a)
    b = int(b)
    
    if c == 'replace':
        s = s[:a] + p + s[b+1:]
    
    elif c == 'reverse':
        s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]

    
    elif c == 'print':
        print(s[a:b+1])

Submission status: Accepted

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

for i in range(q):
    cmdln = [i for i in input().split()]
    cmd = cmdln[0]
    a, b = (int(i) for i in cmdln[1:3])
    if cmd == "print":
        print(string[a:b+1])
    elif cmd == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif cmd == "replace":
        p = cmdln[3]
        string = string[:a] + p + string[b+1:]

Submission status: Accepted

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

for i in range(q):
    s = input().split()
    if s[0] == "print":
        ans = char[int(s[1]):int(s[2])+1]
        print("".join(ans))
    elif s[0] == "reverse":
        tmp = char[int(s[1]):int(s[2])+1]
        result = ""
        for j in range(len(tmp)):
            result += tmp[-1-j]
        for i in range(len(result)):
            char[int(s[1])+i] = result[i]
    else:
        char = char[:int(s[1])] + list(s[3]) + char[int(s[2])+1:]

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
def getInputListStr():
    outputData = []
    inputData = input().split()
    outputData = [str(n) for n in inputData]

    return outputData

def replace(s, a, b, new_s):
    s = s[:a] + new_s + s[b+1:]
    return s

def reverse(s, a, b):
    tmp = s[a:b+1]
    tmp2 = tmp[::-1]
    s = s[:a] + tmp2 + s[b+1:]
    return s

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()
n = int(input())
for _ in range(n):
    op = list(input().split())
    if op[0]=='replace':
        s = s[:int(op[1])]+op[3]+s[int(op[2])+1:]
    elif op[0]=='reverse':
        s = s[:int(op[1])]+''.join(list(reversed(s[int(op[1]):int(op[2])+1])))+s[int(op[2])+1:]
    else : print(s[int(op[1]):int(op[2])+1])

Submission status: Accepted

Solution code:
st=input()
loop=int(input())
for _ in range(loop):
    order =input().split()
    if order[0] == "print":
        print(st[
            int(order[1]) :
            int(order[2])+1
            ])
    elif order[0] == "reverse":
        gyaku="".join(list(reversed(st[int(order[1]) : int(order[2])+1])))
        st=st[:int(order[1])]+gyaku+st[int(order[2])+1:]
    elif order[0] == "replace":
        st=st[:int(order[1])]+order[3]+st[int(order[2])+1:]

Submission status: Accepted

Solution code:
import re
S = input()
q = int(input())
C = []
for i in range(q):
    C.append(re.split('\s',input()))
for i in C:
    if i[0] == 'replace':
        a = int(i[1])
        b = int(i[2])
        S = S[0:a] + i[3][0:b-a+1] + S[b+1:len(S)]
    elif i[0] == 'reverse':
        a = int(i[1])
        b = int(i[2])
        S = S[0:a] + S[a:b+1][::-1] + S[b+1:len(S)]
    else:
        a = int(i[1])
        b = int(i[2])
        print(S[a:b+1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    s = input().strip()
    N = int(input())
    for i in range(N):
        t = input().strip().split()
        a = int(t[1])
        b = int(t[2])
        if t[0][0] == "p":
            print(s[int(t[1]):int(t[2])+1])
        elif t[0][2] == "p":
            s = s[:a] + t[3] + s[b+1:]
        else:
            s = s[:a] + s[a:b+1][::-1] + s[b+1:]

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
q = int(input())
order_list = list()
for i in range(q):
    order = list(map(str,input().split()))
    order_list.append(order)

for order in order_list:
    a = int(order[1])
    b = int(order[2])
    if order[0] == "print":
        print(s[a:b+1])
    elif order[0] == "reverse":
        s_rv = s[a:b+1]
        s_rv = s_rv[::-1]
        s = s.replace(s[a:b+1], s_rv)
    elif order[0] == "replace":
        s_part = s[a:b+1]
        s_part = s_part.replace(s[a:b+1], order[3])
        s = s[:a] + s_part + s[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    o = [x for x in input().split()]

    a = int(o[1])
    b = int(o[2]) + 1

    if o[0] == "print":
        print(s[a:b])
    if o[0] == "replace":
        s = s[:a] + o[3] + s[b:]
    if o[0] == "reverse":
        tmp = s[a:b]
        s = s[:a] + tmp[::-1] + s[b:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#2020-03-21
lst = input()
count = int(input())
for i in range(count):
    t = input().split()
    a = int(t[1])
    b = int(t[2])
    if t[0] == 'print':
        print(lst[a:b+1])

    elif t[0] == 'replace':
        lst = lst[0 : a] + t[3] + lst[b + 1 :]

    elif t[0] == "reverse":
        lst = lst[0:a] + lst[a:b+1][::-1] + lst[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:
s=str(input())
n=int(input())
c1=0
c2=0
for i in range(n):
    c=list(input().split())

    if c[0]=="replace":
        l=s[:int(c[1])]
        r=s[int(c[2])+1:]
        s=str(l)+c[3]+str(r)


    elif c[0]=="reverse":
        l=s[:int(c[1])]
        r=s[int(c[2])+1:]
        s=str(l)+s[int(c[1]):int(c[2])+1][::-1]+str(r)            
    else:
        for i in range(int(c[1]),int(c[2])+1):
            print(s[i],end="")
        print("")

Submission status: Accepted

Solution code:
S = list(input())
N = int(input())
for _ in range(N):
    Q = input().split()
    if Q[0] == "print":
        si = int(Q[1])
        ei = int(Q[2])
        print(*S[si: ei + 1], sep="")
    elif Q[0] == "reverse":
        si = int(Q[1])
        ei = int(Q[2])
        S[si:ei+1] = S[si:ei+1][::-1]
        #S[] = S[:si+1] + str(rev_S) + S[ei+1:]
    elif Q[0] == "replace":
        si = int(Q[1])
        ei = int(Q[2])
        S[si: ei + 1] = list(Q[3])

Submission status: Accepted

Solution code:
word = list(input())

n = int(input())
orders = [list(input().split()) for i in range(n)]
for order in orders:
  if order[0] == "print":
    print("".join(word[int(order[1]):int(order[2])+1]))
  elif order[0] == "replace":
    replace_word = list(order[3])
    for i in range(len(replace_word)):
      word[int(order[1]) + i] = replace_word[i]
  elif order[0] == "reverse":
    reverse_word = list(reversed(word[int(order[1]):int(order[2])+1]))
    count = 0
    for j in range(int(order[1]),int(order[2])+1):
      word[j] = reverse_word[count] 
      count += 1

Submission status: Accepted

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

for _ in range(n):
    O = input().split()
    o = O[0]
    a = int(O[1])
    b = int(O[2])
    if o == 'print':
        print(''.join(S[a:b+1]))
    elif o == 'replace':
        S[a:b+1] = list(O[3])
    elif o == 'reverse':
        S[a:b+1] = reversed(S[a:b+1])

Submission status: Accepted

Solution code:
s = 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(s[a:b + 1])
    elif command[0] == "reverse":
        t = s[a:b + 1]
        t = t[::-1]
        s = s[:a] + t + (s[b + 1:])
    elif command[0] == "replace":
        s = s[:a] + command[3] + s[b + 1:]

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str = input()
q = int(input())
for i in range(q):
    method, a, b, *p = input().split()

    if method == "print":
        print(str[int(a) : int(b) + 1])
    elif method == "reverse":
        pre = str[: int(a)]
        reverse = str[int(a) : int(b) + 1][::-1]
        after = str[int(b) + 1 :]
        str = pre + reverse + after
    elif method == "replace":
        pre = str[: int(a)]
        after = str[int(b) + 1 :]
        str = pre + "".join(p) + after

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(n):
    quary = list(map(str,input().split()))
    if quary[0] == "print":
        print(s[int(quary[1]):int(quary[2])+1])
    if quary[0] == "replace":
        s = s[0:int(quary[1])] + quary[3] + s[int(quary[2])+1:]
    if quary[0] == "reverse":
        s = s[0:int(quary[1])] + ''.join(list(reversed(s[int(quary[1]):int(quary[2])+1]))) + s[int(quary[2])+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_lst = []
for i in s:
    s_lst.append(i)
q = int(input())
order = [0] * q
for i in range(q):
    order[i] = input().split()
    order[i][1] = int(order[i][1])
    order[i][2] = int(order[i][2])
for i in range(q):
    if order[i][0] == "print":
        s = "".join(s_lst)
        # print(order[i], s_lst )
        print(s[order[i][1]:order[i][2]+1])
    elif order[i][0] == "reverse":
        for j in range((order[i][2]-order[i][1]+1)//2):
            s_lst[order[i][1]+j], s_lst[order[i][2]-j] = s_lst[order[i][2]-j], s_lst[order[i][1]+j]
        # print(order[i], s_lst )
    elif order[i][0] == "replace":
        for j in range(len(order[i][3])):
            s_lst[order[i][1] + j] = order[i][3][j]
        # print(order[i], s_lst )

Submission status: Accepted

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

for i in range(q):
    lis = input().split()
    a = int(lis[1])
    b = int(lis[2])

    if lis[0] == "print":
        print(s[a : b + 1])
    elif lis[0] == "replace":
        p = lis[3]
        s = s[:a] + p + s[b + 1 :]
    else:  # reverse
        slice = (s[a : b + 1])[::-1]
        s = s[:a] + slice + s[b + 1 :]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()
q = int(input())
order = [input().split() for _ in range(q)]
for x in order:
    a,b,c,d = x[0],int(x[1]),int(x[2]),x[3] if x[0] == 'replace' else None
    if a == 'print':
        print(S[b:c+1])
    elif a == 'reverse':
        S = S[:b] + S[b:c+1][::-1] + S[c+1:]
    else:
        S = S[:b] + S[b:c+1].replace(S[b:c+1],d) + S[c+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for i in range(q):
    data = list(input().split())
    if data[0] == "print":
        left = int(data[1])
        right = int(data[2])
        for i in range(left, right+1):
            print(s[i], end="")
        print()
    elif data[0] == "reverse":
        left = int(data[1])
        right = int(data[2])
        s = s[:left] + s[left:right+1][::-1] + s[right+1:]
    elif data[0] == "replace":
        left = int(data[1])
        right = int(data[2])
        s = s[:left] + data[3] + s[right+1:]

Submission status: Accepted

Solution code:
s = input()
q = int(input())
l = [input().split() for _ in range(q)]

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

for _ in range(n):
    t = input().split()
    t1 = int(t[1])
    t2 = int(t[2])
    tmp = s[t1:t2+1]
    if t[0] == 'replace':
        s = s[:t1] + t[3] + s[t2+1:]
    elif t[0] == 'reverse':
        s = s[:t1] + tmp[::-1] + s[t2+1:]
    elif t[0] == 'print':
        print(tmp)

Submission status: Accepted

Solution code:
*s, = input()
for _ in range(int(input())):
    *t, = map(str, input().split())
    t.append("")
    c = t.pop(0)
    a = int(t.pop(0))
    b = int(t.pop(0))
    *p, = t.pop(0)

    if c == "print":
        print("".join(s[a:b+1]))
    elif c == "reverse":
        s = s[:a]+list(reversed(s[a:b+1]))+s[b+1:]
    elif c == "replace":
        s = s[:a]+p+s[b+1:]

Submission status: Accepted

Solution code:
s = list(input())
n = int(input())
op_l = list(input().split() for _ in range(n))

for op in op_l:
    a = int(op[1])
    b = int(op[2])
    if op[0] == 'print':
        print(*s[a:b+1], sep='')
    elif op[0] == 'reverse':
        tmp = list(s[a:b+1])
        cnt = 0
        for i in range(a, b+1):
            cnt += 1
            s[i] = tmp[-cnt]
    elif op[0] == 'replace':
        xx = list(op[3])
        cnt = 0
        for i in range(a, b+1):
            s[i] = xx[cnt]
            cnt += 1

Submission status: Accepted

Solution code:
inp = input()
n = int(input())
for i in range(n):
    od = input().split()
    #print(od)
    inp = list(inp)

    if (od[0] == "replace"):
        inp[int(od[1]):int(od[2])+1] = od[3]
        #print(inp)
    if (od[0] == "reverse"):
        ss = inp[int(od[1]):int(od[2])+1].copy()
        ss.reverse()
        #print(ss)
        inp[int(od[1]):int(od[2])+1] = ss
        #print(inp)

    if (od[0] == "print"):
        print("".join(inp[int(od[1]):int(od[2])+1]))

Submission status: Accepted

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

    if a[0]=="replace":
        tmp=str()
        for j in range(0,int(a[1])):
            tmp+=s[j]
        tmp+=a[3]
        for j in range(int(a[2])+1,len(s)):
            tmp+=s[j]
        s=tmp

    elif a[0]=="reverse":
        tmp=str()
        for j in range(0,max(0,int(a[1]))):
            tmp+=s[j]
        for j in reversed(range(int(a[1]),int(a[2])+1)):
            tmp+=s[j]
        for j in range(int(a[2])+1,len(s)):
            tmp+=s[j]
        s=tmp

    else:
        ans=str()
        for j in range(int(a[1]),int(a[2])+1):
            ans+=s[j]
        print(ans)

Submission status: Accepted

Solution code:
str = input()

q = int(input())

for i in range(q):
    
    command = input().split()
    #print(str, command)
    if command[0] == 'replace':
        a, b, p = command[1:]
        str = str[:int(a)] + p + str[int(b) + 1:]
        
    elif command[0] == 'reverse':
        a, b = [int(x) for x in command[1:]]
        str = str[:a] + ''.join(list(reversed(str[a:b + 1]))) + str[b + 1:]
        
    elif command[0] == 'print':
        a, b = [int(x) for x in command[1:]]
        print(str[a:b + 1])