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:
txt = input()
n = int(input())

for i in range(n):
    inputs = input().split()
    if inputs[0] == 'print':
        s = int(inputs[1])
        e = int(inputs[2])
        print(txt[s:e+1])
    elif inputs[0] == 'reverse':
        s = int(inputs[1])
        e = int(inputs[2])
        t_r = txt[s:e+1]
        t_r = t_r[::-1]
        txt = txt[:s] + t_r + txt[e+1:]
    elif inputs[0] == 'replace':
        s = int(inputs[1])
        e = int(inputs[2])
        rep = inputs[3]
        txt = txt[:s] + rep + txt[e+1:]

Submission status: Accepted

Solution code:
string=input()
n=int(input())
for i in range(n):
    order=list(input().split())
    start=int(order[1])
    end=int(order[2])
    if order[0]=="print":
        print(string[start:end+1])
    elif order[0]=="replace":
        string=string[:start]+order[3]+string[end+1:]
    elif order[0]=="reverse":
        if start!=0:
            string=string[:start]+string[end:start-1:-1]+string[end+1:]
        else:
            string=string[:end+1][::-1]+string[end+1:]

Submission status: Accepted

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

Submission status: Accepted

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

answer = []

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

    if line[0] == "print":
        a = int(line[1])
        b = int(line[2])
        answer.append(inp[a:(b + 1)])
    elif line[0] == "reverse":
        a = int(line[1])
        b = int(line[2])
        reverseStr = inp[a:(b + 1)]
        inp = inp[:a] + reverseStr[::-1] + inp[(b + 1):]
    elif line[0] == "replace":
        a = int(line[1])
        b = int(line[2])
        p = line[3]
        inp = inp[:a] + p + inp[(b + 1):]

[print(answer[i]) for i in range(len(answer))]

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#初期値
input_data = list(input())
processing = int(input())

#処理実行
for i in range(processing):
    order = input().split()
    if order[0] == "print":
        print("".join(input_data[int(order[1]):int(order[2])+1]))
    elif order[0] == "reverse":
        reverse_data = (input_data[int(order[1]):int(order[2])+1])
        reverse_data.reverse()
        input_data = input_data[0:int(order[1])] + reverse_data + input_data[int(order[2])+1:]
    elif order[0] == "replace":
        input_data = input_data[0:int(order[1])] + list(order[3]) + input_data[int(order[2])+1:]

Submission status: Accepted

Solution code:
S = input()
N = int(input())
for n in range(N):
    *w, = input().split()
    a, b = int(w[1]), int(w[2])
    if w[0] == 'replace':
        r = w[3]
        S = S[:a]+r+S[b+1:]
    if w[0] == 'reverse':
        S = S[:a]+S[a:b+1][::-1]+S[b+1:]
    if w[0] == 'print':
        print(S[a:b+1])

Submission status: Accepted

Solution code:
instr = list(str(input()))
num = int(input())
for i in range(num):
    comm = list(input().split())
    if str(comm[0]) =='replace':
        instr[int(comm[1]):int(comm[2])+1]=str(comm[3])
    elif str(comm[0]) =='reverse':
        instr[int(comm[1]):int(comm[2])+1]=list(reversed(instr[int(comm[1]):int(comm[2])+1]))
    elif str(comm[0]) =='print':
        print("".join(instr[int(comm[1]):int(comm[2])+1]))

Submission status: Accepted

Solution code:
string = input()
rep = int(input())
for i in range(rep):
    l = input().split()
    query = l[0]
    a = int(l[1])
    b = int(l[2])

    if   query == "print":
        print(string[a:b+1])
    elif query == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string [b+1:]
        #print(f"str:{string}")
    elif query == "replace":
        p = l[3]
        string = string[:a] + p + string [b+1:]
        #print(f"str:{string}")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def my_print(str, a, b):
  print(str[a:b + 1])
  return str

def my_replace(str, a, b, p):
  return str[:a] + p + str[b + 1:]

def my_reverse(str, a, b):
  r_str = str[a:b + 1][::-1]
  return str[:a] + r_str + str[b + 1:]

str = input()

for i in range(int(input())):
  cmd, *args = input().split(' ')
  args = [int(i) for i in args[0:2]] + args[2:]
  str = globals()['my_' + cmd](str, *args)

Submission status: Accepted

Solution code:
def print2(s, a, b):
    print(s[a:b+1])
    return s

def reverse2(s, a, b):
    if a == 0:
        return s[b::-1] + s[b+1:]
    else:
        return s[:a] + s[b:a-1:-1] + s[b+1:]
   
def replace2(s, a, b, p):
    return s[:a] + p + s[b+1:]

s = input()
q = int(input())
for i in range(q):
    lst = input().split()
    a = int(lst[1])
    b = int(lst[2])
    if len(lst) == 4:
        p = lst[3]
        s = eval(lst[0] + "2(s, a, b , p)")
    else:
        s = eval(lst[0] + "2(s, a, b)")

Submission status: Accepted

Solution code:


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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
c = int(input())
for i in range(c):
    nums = [str(e) for e in input().split()]
    nums[1] = int(nums[1])
    nums[2] = int(nums[2]) + 1
    if nums[0] == "print":
        print(s[nums[1]:nums[2]])
    if nums[0] == "reverse":
        s = s.replace(s[nums[1]:nums[2]],s[nums[1]:nums[2]][::-1])
    if nums[0] == "replace":
        s = list(s)
        s[nums[1]:nums[2]] = nums[3]
        s = "".join(s)

Submission status: Accepted

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

for x in range(xLoop):
    xCmd= input()
    if xCmd[0:7] == 'replace':
        xCmd,a,b,p = xCmd.split()
        a = int(a)
        b = int(b)
        if a == 0:
            str = p + str[b+1:len(str)]
        else:
            str = str[0:a] + p + str[b+1:len(str)]
        
    elif xCmd[0:7] == 'reverse':
        xCmd,a,b = xCmd.split()
        a = int(a)
        b = int(b)
        p = str[a:b+1]
        p = p[::-1]
        if a == 0:
            str = p + str[b+1:len(str)]
        else:
            str = str[0:a] + p + str[b+1:len(str)]

    else:
        xCmd,a,b = xCmd.split()
        a = int(a)
        b = int(b)+1
        print(str[a:b])

Submission status: Accepted

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

for _ in range(q):
    
    order = input().split()
    
    command = order[0]
    n = int(order[1])
    m = int(order[2])
    
    if command == "print":
        print(s[n:m+1])
    elif command == "reverse":
        r = ''.join(list(reversed(s[n:m+1])))
        s = s[:n] + r + s[m+1:]

    elif command == "replace":
        s = s[:n] + order[-1] + s[m+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 文字列を受け取る
inpstr = input()

# 命令の数を受け取る
q = int(input())

# 命令を受け取って処理実行
for i in range(q):
    order = input()
    order_list = [j for j in order.split(" ")]
    order_txt = order_list[0]
    if order_txt == "replace":
        rplc1 = int(order_list[1])
        rplc2 = int(order_list[2])
        rplcstr = order_list[3]
        inpstr = inpstr[:rplc1] + rplcstr + inpstr[rplc2 + 1:]
    elif order_txt == "reverse":
        rvrs1 = int(order_list[1])
        rvrs2 = int(order_list[2])
        tmp_str = inpstr[rvrs1:rvrs2 + 1]
        rvrs_str = "".join(reversed(tmp_str))
        inpstr = inpstr[:rvrs1] + rvrs_str + inpstr[rvrs2 + 1:]
    else:
        prt1 = int(order_list[1])
        prt2 = int(order_list[2])
        print(inpstr[prt1:prt2 + 1])

Submission status: Accepted

Solution code:



if __name__ == "__main__":

    param = input()
    char = [c for c in param]

    n = int(input())

    for _ in range(n):

        command = input().split(" ")

        if   command[0] == "print":
            str = "".join(char[int(command[1]) : (int(command[2]) + 1)])
            print(str)
        elif command[0] == "reverse":
            part = char[int(command[1]):(int(command[2]) + 1)]
            part.reverse()
            char[int(command[1]):(int(command[2]) + 1)] = part[0:]
        elif command[0] == "replace":
            char[int(command[1]):int(command[2]) + 1] = command[3]
        else:
            pass

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:
class Transformation(object):

    def __init__(self, text):
        self.text = text

    def print(self, a, b):
        print(self.text[a:b+1])

    def reverse(self, a, b):
        target = self.text[a:b+1]
        target = target[::-1]
        self.text = self.text[:a] + target + self.text[b+1:]

    def replace(self, a, b, p):
        self.text = self.text[:a] + p + self.text[b+1:]


text = input()
t = Transformation(text)
q = int(input())
for i in range(q):
    commands = input().split()
    command = commands[0]
    a = int(commands[1])
    b = int(commands[2])
    if command == "print":
        t.print(a, b)
    elif command == "reverse":
        t.reverse(a, b)
    elif command == "replace":
        p = commands[3]
        t.replace(a, b, p)

Submission status: Accepted

Solution code:
str_in = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    start_num = int(command[1])
    end_num   = int(command[2])+1
    if command[0] == 'replace':
        rep = list(command[3])
        cnt = 0
        for j in range(start_num, end_num):
            str_in[j] = rep[cnt]
            cnt += 1
    elif command[0] == 'reverse':
        end_num -= 1
        while end_num > start_num:
            str_tmp = str_in[end_num]
            str_in[end_num] = str_in[start_num]
            str_in[start_num] = str_tmp
            end_num -= 1
            start_num += 1
    elif command[0] == 'print':
        for l in range(start_num, end_num):
            print(str_in[l], end="")
        print()
    else:
        pass

Submission status: Accepted

Solution code:
src = input()

request_n = int(input())

for _ in range(request_n):
    request_lst = input().split()
    
    command = request_lst[0]
    start = int(request_lst[1])
    end = int(request_lst[2])
    
    if command == "print":
        print(src[start:end + 1])
    
    elif command == "reverse":
        rev = src[start:end + 1]
        src = src[:start] + rev[::-1] + src[end + 1:]
    
    elif command == "replace":
        target = request_lst[3]
        src = src[:start] + target + src[end + 1:]

Submission status: Accepted

Solution code:
target_strings = input()
num_of_order = int(input())

for i in range(num_of_order):
    order = input().split(" ")
    if order[0] == "replace":
        target_strings = target_strings[:int(order[1])] + \
        order[3] + target_strings[int(order[2])+1:]
    
    elif order[0] == "reverse":
        string2 = target_strings[int(order[1]):int(order[2])+1]
        target_strings = target_strings[:int(order[1])] + \
        string2[::-1] +\
        target_strings[int(order[2])+1:]
       
    else:
        print(target_strings[int(order[1]):int(order[2]) + 1])

Submission status: Accepted

Solution code:
s=list(input())
n=int(input())
for i in range(n):
    inst=list(input().split())
    start=int(inst[1])
    end=int(inst[2])
    if(inst[0]=="print"):
        print(''.join(s[start:end+1]))
    elif(inst[0]=="replace"):
        for j in range(len(inst[3])):
            s[start+j]=inst[3][j]
    elif(inst[0]=="reverse"):
        rev=list(reversed(s[start:end+1]))
        for j in range(len(rev)):
            s[start+j]=rev[j]

Submission status: Accepted

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

for t in range(times):
    s = input().split()
    l = s[0]
    a = int(s[1])
    b = int(s[2]) + 1

    if l == 'print':
        print(letters[a:b])
    
    elif l == 'replace':
        rl = s[3]
        first_part = letters[:a]
        last_part = letters[b:]
        letters = first_part + rl + last_part
        
    elif l == 'reverse':
        temp_letter = ''.join(reversed(letters[a:b]))
        letters = letters.replace(letters[a:b], temp_letter)

Submission status: Accepted

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

for i in range(q):
    opt, *args = input().split()
    a = int(args[0])
    b = int(args[1])
    if opt == "print":
        print(s[a:b+1])
    elif opt == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif opt == "replace":
        p = args[2]
        s = s[:a] + p + s[b+1:]

Submission status: Accepted

Solution code:
str = str(input())
q = int(input())
for i in range(q):
    command, a, b, *p =input().split()
    a = int(a)
    b = int(b)
    p = ''.join(p)
    if command == 'print':
        print(str[a:b+1])

    elif command == 'reverse':
        str = str[:a] + str[a:b+1][::-1] + str[b+1:]
    else:
        str = str[:a] + p +str[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

text=input()
num_of_command=int(input())

for command_ID in range(num_of_command):
    command=input().split()
    start=int(command[1]);
    ed=int(command[2])+1;

    if command[0]=="replace":
        pre=text[:start]
        replace_text=command[3];
        after=text[ed:]
        text=pre+replace_text+after      
    elif command[0]=="reverse":
        text=text[:start]+text[start:ed][::-1]+text[ed:]
    elif command[0]=="print":
        print(text[start:ed])

Submission status: Accepted

Solution code:
S = input()
q = int(input())
L = []
for _ in range(q):
    Op = input().split()
    l, r = int(Op[1]), int(Op[2])
    if Op[0] == 'replace':
        S = S[:l] + Op[3] + S[r+1:]
    elif Op[0] == 'reverse':
        S = S[:l] + S[l:r+1][::-1] + S[r+1:]
    elif Op[0] == 'print':
        print(S[l:r+1])

Submission status: Accepted

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

for i in range(n):
    direction = input().split()
    
    if direction[0]=="replace":
        word = word[:int(direction[1])] + direction[3] + word[int(direction[2])+1:]
        
    elif direction[0]=="print":
        print(word[int(direction[1]):int(direction[2])+1])
        
    elif direction[0]=="reverse":
        word = word[:int(direction[1])] + word[int(direction[1]):int(direction[2])+1][::-1] + word[int(direction[2])+1:]

Submission status: Accepted

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

for i in range(n):
    s = input().split()

    if s[0] == 'print':
        a,b = int(s[1]),int(s[2])
        print(w[a:b+1])
    elif s[0] == 'reverse':
        a,b = int(s[1]),int(s[2])
        p = w[a:b+1][::-1]
        w = w[:a] + p + w[b+1:]
    elif s[0] == 'replace':
        a,b = int(s[1]),int(s[2])
        w = w[:a] + s[3] + w[b+1:]

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    # h0,w0h1,w1 = map(int, input().split())
    s = input()
    n = int(input())
    for _ in range(n):
        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])
            s = s[:a] + t[3] + s[b + 1:]

main()

Submission status: Accepted

Solution code:
sent = list(input())

q = int(input())

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

  if order[0] == "print":
    output = [0 for j in range(b-a+1)]
    for j in range(b-a+1):
      output[j] = sent[a+j]
    print("".join(output))

  elif order[0] == "reverse":
    rev = [0 for j in range(b-a+1)]
    for k in range(b-a+1):
      rev[k] = sent[b-k]

    for l in range(b-a+1):
      sent[a+l] = rev[l]

  else:
    p = order[3]
    for j in range(b-a+1):
      sent[a+j] = p[j]

Submission status: Accepted

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

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

Submission status: Accepted

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

for _ in range(q):
    i = input().split()
    op, a, b = i[0], int(i[1]), int(i[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':
        p = i[3]
        s = s[:a] + p + s[b+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 len(order[0])==5:
        print(s[a:b+1])
    elif len(order)==3:
        s=s[:a]+''.join(reversed(list(s[a:b+1])))+s[b+1:]
    else:
        s=s[:a]+order[3]+s[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str=[i for i in input()]
n=int(input())
l= [input().split() for i in range(n)]
for i in range(n):
    if l[i][0]=="print":
        str = ''.join(str) 
        print(str[int(l[i][1]):int(l[i][2])+1])
        str = [i for i in str]         
    elif l[i][0]=="reverse":
        part_str=list(reversed(str[int(l[i][1]):int(l[i][2])+1]))
        str[int(l[i][1]):int(l[i][2])+1]=part_str
    else:
        replace_str=[j for j in l[i][3]]
        str[int(l[i][1]):int(l[i][2])+1]=replace_str

Submission status: Accepted

Solution code:
import sys
txt=input()
n=int(input())
for i in range(n):
    x=input().split()
    if x[0]=='print':
        print(txt[int(x[1]):int(x[2])+1])
    elif x[0]=='replace':
        txt=txt[:int(x[1])]+x[3]+txt[int(x[2])+1:]
    else:
        txt=txt[:int(x[1])]+''.join(reversed(txt[int(x[1]):int(x[2])+1]))+txt[int(x[2])+1:]

Submission status: Accepted

Solution code:
cord = input()
step = int(input())
for i in range(step):
    thread = input().split()
    if thread[0] == 'print':
        print(cord[int(thread[1]): int(thread[2])+1])
    elif thread[0] == 'replace':
        cord = cord[:int(thread[1])] + thread[3] + cord[int(thread[2])+1:]
    else:
        cord = cord[:int(thread[1])] + cord[int(thread[1]):int(thread[2])+1][::-1] + cord[int(thread[2])+1:]

Submission status: Accepted

Solution code:
str = input()
q = int(input())
line = []
for _ in range(0,q):
    line[:] = input().split()
    cmd = line[0]
    a = int(line[1])
    b = int(line[2])
    #print(' '.join(line))
    if (cmd == 'print'):
        print(str[a:b+1])
    elif (cmd == 'reverse'):
        rev = ''
        for i in range(a, b+1):
            rev = str[i:i+1] + rev
        str = str[:a]+rev+str[b+1:]
    elif (cmd == 'replace'):
        p = line[3]
        str = str[:a]+p+str[b+1:]

Submission status: Accepted

Solution code:
a = str(input())
q = int(input())
for i in range(q):
    ope = list(map(str, input().split(" ")))
    if ope[0] == "replace":
        a_list = list(a)
        a = ""
        for i in range(int(ope[2])-int(ope[1])+1):
            del a_list[int(ope[1])]
        a_list.insert(int(ope[1]), ope[3])
        for i in a_list:
            a += i
    elif ope[0] == "reverse":
        new_a = a[int(ope[1]):int(ope[2])+1]
        a = a.replace(a[int(ope[1]):int(ope[2])+1], new_a[::-1])
    elif ope[0] == "print":
        print(a[int(ope[1]):int(ope[2])+1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = int(input())
for i in range(n):
    line = input()
    line_len = len(line.split())
    #print(line_len)
    if(line_len == 3):
        op,a,b = line.split()
    elif(line_len == 4):
        op,a,b,rep = line.split()
    a = int(a)
    b = int(b)
    if(op == "print"):
        print(S[a:b+1])
    elif(op == "replace"):
        tmp = S[0:a] + rep + S[b+1:]
        S = tmp
        #print(S)
    elif(op == "reverse"):
        tmp = list(S[a:b+1])
        tmp.reverse()
        #print(tmp)
        S = S[0:a] + "".join(tmp) + S[b+1:]
        #print(S)

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for _ in range(q):
    input_list = input().split()
    o = input_list[0]
    a = int(input_list[1])
    b = int(input_list[2])
    if len(input_list) == 4:
        p = input_list[3]
        s = s[:a] + p + s[b+1:]
    elif o == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    else:
        print(s[a:b+1])

Submission status: Accepted

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

for i in range(n):
    command=input().split(" ")

    if command[0]=="replace":
        com1=int(command[1])
        com2=int(command[2])
        com3=list(command[3])
        list_str=list(str)
        for i in range(com1,com2+1):
            list_str[i]=com3[i-com1]
        str="".join(list_str)

    elif command[0]=="reverse":
        com1=int(command[1])
        com2=int(command[2])
        str2=str[com1:com2+1]
        com3=str2[::-1]
        str=str.replace(str[com1:com2+1],com3)

    else:
        com1=int(command[1])
        com2=int(command[2])
        print(str[com1:com2+1])

Submission status: Accepted

Solution code:
s = input()
q = int(input())
for i in range(q):
    m = list(map(str,input().split()))
    if m[0] == "print":
        print(s[int(m[1]):int(m[2])+1])
    elif m[0] == "reverse":
        sr = s[int(m[1]):int(m[2])+1]
        sr = sr[::-1]
        s1 = s[:int(m[1])]
        s2 = s[int(m[2])+1:]
        s = s1 + sr + s2
        #print(s,s1,sr,s2)
    elif m[0] == "replace":
        s1 = s[:int(m[1])]
        s2 = s[int(m[2])+1:]
        s = s1 + m[3] + s2
        #print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
target = input()
num_operations = int(input())

for _ in range(num_operations):
    operation = input().split()
    operation_name = operation[0]
    frm, to = map(int, operation[1:3])
    if operation_name == 'replace':
        new = operation[3]
    
    if operation_name == 'print':
        print(target[frm:to+1])
    elif operation_name == 'reverse':
        reverse_target = target[frm:to+1]
        target = target[:frm] + reverse_target[::-1] + target[to+1:]
    elif operation_name == 'replace':
        target = target[:frm] + new + target[to+1:]
    else :
        raise Exception

Submission status: Accepted

Solution code:
str = 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+1], sep='')
    elif cmd == "reverse":
        str[a:b+1] = reversed(str[a:b+1])
    elif cmd == "replace":
        str[a:b+1] = c[0]

Submission status: Accepted

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

for i in range(q):
    x, a, b, *p = input().split()
    a = int(a)
    b = int(b)

    if x == 'replace':
        str = str[:a]+p[0] +str[b+1:]

    elif x == 'reverse':
        tmp = str[a:b+1]
        str = str[:a]+tmp[::-1]+str[b+1:]

    elif x == 'print':
        print(str[a:b+1])

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

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

s=input().rstrip()
n=int(input().rstrip())
for _ in range(n):
    c,*x=input().split()
    if c=="print":
        print(s[int(x[0]):int(x[1])+1])
    elif c=="reverse":
        s=s[:int(x[0])]+s[int(x[0]):int(x[1])+1][::-1]+s[int(x[1])+1:]
    else:
        s=list(s)
        t=x[2]
        l=0
        for i in range(int(x[0]),int(x[1])+1):
            s[i]=t[l]
            l+=1
        s="".join(s)