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:
def rvrs(base, start, end):
    r = base[int(start):int(end) + 1][::-1]
    return base[:int(start)] + r + base[int(end) + 1:]
def rplc(base, start, end, string):
    return base[:int(start)] + string + base[int(end) + 1:]

ans = input()
q = int(input())
for _ in range(q):
    ORD = list(input().split())
    if ORD[0] == 'print':
        print(ans[int(ORD[1]):int(ORD[2])+1])
    elif ORD[0] == 'reverse':
        ans = rvrs(ans, int(ORD[1]), int(ORD[2]))
    elif ORD[0] == 'replace':
        ans = rplc(ans, int(ORD[1]), int(ORD[2]), ORD[3])

Submission status: Accepted

Solution code:
str=input()
s=list(str)
q=int(input())
for i in range(q):
    Q=input()
    l=list(Q)
    if 'print' in Q:
        for p in range(6):
            l.pop(0)
        for X in range(len(l)):
            if l[X]==' ':
                x=X
        A=l[0:x]
        a=''.join(A)
        a=int(a)
        B=l[x+1:len(l)]
        b=''.join(B)
        b=int(b)+1
        t=s[a:b]
        str=''.join(t)
        print(str)
    elif 'reverse' in Q:
        for v in range(8):
            l.pop(0)
        for Y in range(len(l)):
            if l[Y]==' ':
                y=Y
        A=l[0:y]
        a=''.join(A)
        a=int(a)
        B=l[y+1:len(l)]
        b=''.join(B)
        b=int(b)+1
        t=s[a:b]
        t.reverse()
        s[a:b]=t
    elif 'replace' in Q:
        for r in range(8):
            l.pop(0)
        for Z in range(len(l)):
            if l[Z]==' ':
                z=Z
                break
        N=0
        while True:
            if l[z+N+1]==' ':
                n=z+N+1
                break
            else:
                N+=1
        A=l[0:z]
        a=''.join(A)
        a=int(a)
        B=l[z+1:n]
        b=''.join(B)
        b=int(b)+1
        t=l[n+1:len(l)]
        s[a:b]=t

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S,Q,*C = open(0).read().split()
s = list(S)

i = 0
while i < len(C):
    cmd = C[i]
    i += 1
    if cmd == "replace":
        a = int(C[i])
        b = int(C[i+1])
        p = C[i+2]
        i += 3
        for j in range(a, b+1):
            s[j] = p[j - a]
    elif cmd == "reverse":
        a = int(C[i])
        b = int(C[i+1])
        i += 2
        r = list(reversed(s[a:b+1]))
        for j, c in enumerate(r):
            s[j + a] = c
    elif cmd == "print":
        a = int(C[i])
        b = int(C[i+1])
        i += 2
        print("".join(s[a:b+1]))
    else:
        print(cmd)
        break

Submission status: Accepted

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

s_array = []
for i in range(len(s)):
    s_array.append(s[i])

for i in range(n):
    order = input().split()
    if order[0] == "replace":
        first = int(order[1])
        last = int(order[2])
        for j in range(last-first+1):
            s_array[first+j] = order[3][j]
    elif order[0] == "reverse":
        a = int(order[1])
        b = int(order[2])
        buf = []
        for j in range(b, a-1, -1):
            buf.append(s_array[j])
        for j in range(b+1-a):
            s_array[a+j] = buf[j]
    elif order[0] == "print":
        a = int(order[1])
        b = int(order[2])
        for j in range(a, b+1):
            print("%s" % s_array[j], end="")
        print()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def rev(val, v1, v2):
    for i in range((v2-v1)//2 +1):
        val[v1+i], val[v2-i] = val[v2-i], val[v1+i]
    return val

def rep(val1, val2, v1, v2):
    for i in range(v2-v1):
        val1[v1+i] = val2[i]
    return val1

st = input()
lst = [i for i in st]
q = int(input())
for i in range(q):
    f = list(map(str, input().split()))
    if f[0] == 'print':
        s = ''.join(lst[int(f[1]):int(f[2])+1])
        print(s)
    elif f[0] == 'reverse':
        lst = rev(lst, int(f[1]), int(f[2]))
    elif f[0] == 'replace':
        x = [i for i in f[3]]
        lst = rep(lst, x, int(f[1]), int(f[2])+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__=="__main__":
    main()

Submission status: Accepted

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

S = input().strip()
m = int(input())

for _ in range(m):
    ope = input().strip().split()
    a, b = int(ope[1]), int(ope[2])
    if ope[0] == "print":
        print(S[a:b+1])
    elif ope[0] == "reverse":
        S = S[:a] + S[a:b+1][::-1] + S[b+1:]
    elif ope[0] == "replace":
        S = S[:a] + ope[3] + S[b+1:]

Submission status: Accepted

Solution code:
letters = input()
q = int(input())
for _ in range(q):
    words = input().split()
    command = words[0]
    a, b = map(int, words[1:3])

    if command == 'replace':
        letters = ''.join([letters[:a], words[3], letters[b+1:]])
    elif command == 'reverse':
        letters = ''.join([letters[:a ], letters[a:b+1][::-1], letters[b+1:]])
    elif command == 'print':
        print(letters[a:b+1])

Submission status: Accepted

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

rvs = []
i = 0
j = 0
p = []
order = []
for i in range(q):
    
    order.append(input().split())
    
    if order[i][0] == "replace":
        p = []
        p = list(order[i][3])

        for j in range(int(order[i][1]), int(order[i][2]) + 1):
            s[j] = p[j - int(order[i][1])]

    elif order[i][0] == "reverse":
        ss = "".join(s[int(order[i][1]):int(order[i][2]) + 1])
        rvs = list(ss)
        rvs.reverse()
        for j in range(int(order[i][1]), int(order[i][2]) + 1):
            s[j] = rvs[j - int(order[i][1])]
        
        # temp = s[int(order[i][1])]
        # s[int(order[i][1])] = s[int(order[i][2])]
        # s[int(order[i][2])] = temp

    elif order[i][0] == "print":
        ss = "".join(s)
        print("%s" % ss[int(order[i][1]):int(order[i][2]) + 1])

Submission status: Accepted

Solution code:
s = list(input())
q = int(input())
for i in range(q):
    cmd, a, b, *p = [x for x in input().split()]
    a = int(a)
    b = int(b)
    if cmd=='print':
        print(''.join(s[a:b+1]))
    if cmd=='reverse':
        stack = []
        for _ in range(b+1-a):
            stack.append(s.pop(a))
        for i in range(a, b+1):
            s.insert(i, stack.pop())
    if cmd=='replace':
        for i,c in zip(range(a,b+1), list(p[0])):
            s[i] = c

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

num = int(input())
for index in range(num):
    
    code = input().split()
    instruction = code[0]
    start, end  = int(code[1]), int(code[2])

    if instruction == "replace":
        word = word[:start] + code[3] + word[end+1:]
    elif instruction == "reverse":
        reversed_ch = "".join(reversed(word[start:end+1]))
        word = word[:start] + reversed_ch + word[end+1:]
    else:
        print(word[start:end+1])

Submission status: Accepted

Solution code:
text=input()
n=int(input())
for i in range(n):
    order=input().split()
    a,b=map(int,order[1:3])
    if order[0]=="print":
        print(text[a:b+1])
    elif order[0]=="reverse":
        re_text=text[a:b+1]
        text=text[:a]+re_text[::-1]+text[b+1:]
    else :
        text=text[:a]+order[3]+text[b+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:
s = input()
q = int(input())

printlist = []

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

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

for p in printlist:
    print(p)

Submission status: Accepted

Solution code:
S = input()
N = int(input())
for i in range(N):
    operate = input().split()
    if operate[0] == "replace":
        n = int(operate[1])
        m = int(operate[2])+1
        left_str = S[:n]
        right_str = S[m:]
        center_str = operate[3]
        S = left_str + center_str + right_str
    elif operate[0] == "reverse":
        n = int(operate[1])
        m = int(operate[2])+1
        left_str = S[:n]
        center_str = S[n:m]
        right_str = S[m:]
        center_str = center_str[::-1]
        S = left_str + center_str + right_str
    elif operate[0] == "print":
        n = int(operate[1])
        m = int(operate[2])+1
        left_str = S[:n]
        center_str = S[n:m]
        right_str = S[m:]
        print(center_str)

Submission status: Accepted

Solution code:
s = input()

q = int(input())
query = []

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

Submission status: Accepted

Solution code:
string = input()
num = int(input())
o = 0
for _ in range(num):
    source = input().split(' ')
    if source[0] == 'print':
        print(string[int(source[1]):int(source[2]) + 1])
    elif source[0] == 'replace':
        string = string[:int(source[1])] + source[3] + string[int(source[2]) + 1:]
    else:
        string = string[:int(source[1])] + string[int(source[1]):int(source[2]) + 1 ][::-1] + string[int(source[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:
s = input()
n = int(input())
for i in range(n):
    l = input().split()
    if l[0] == 'replace':
        s = s[:int(l[1])] + str(l[3]) + s[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] == 'print':
        print(s[int(l[1]):int(l[2]) + 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
print a b: strの a 文字目から b 文字目までを出力する。
reverse a b: strの a 文字目から b 文字目までを逆順にする。
replace a b p: st の a 文字目から b 文字目までを p に置き換える
"""
s = str(input())
n_order = int(input())
# print(s)

for _ in range(n_order):
    list_order = [i for i in input().split(" ")]
    order = list_order[0]
    a = int(list_order[1])
    b = int(list_order[2])

    if order == 'print':
        s_a2b = s[a : b + 1]
        print(s_a2b)
    elif order == 'reverse':
        s_a2b = s[a : b + 1]
        s_a2b_rev = s_a2b[::-1]
        s = s[:a] + s_a2b_rev + s[b + 1:]
        # print("->",s)
    elif order == 'replace':
        p = str(list_order[3])
        s = s[:a] + p + s[b + 1:]
        # print("->", s)
    else:
        print("error")

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

s = list(s)

for i in range(n):
  arv = [a for a in input().split()]

  if (arv[0] == "reverse"):
    reverse_s = s[int(arv[1]) : int(arv[2])+1]
    reverse_s.reverse()
    s[int(arv[1]) : int(arv[2])+1]= reverse_s
  
  if (arv[0] == "replace"):
    s[int(arv[1]) : int(arv[2])+1] = list(arv[3])
        
  if (arv[0] == "print"):
    print("".join(s[int(arv[1]):int(arv[2])+1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
temp = input()
n = int(input())
for _ in range(n):
    order,a,b,*value = input().split()
    a = int(a)
    b = int(b)

    if order == "print":
        print(temp[a:b+1])
    elif order == "reverse":
        rev = temp[a:b+1]
        temp = temp[:a] + rev[::-1] + temp[b+1:]
    else:#replace
        temp = temp[:a] + value[0] + temp[b+1:]

Submission status: Accepted

Solution code:
import sys
S = input()
N = int(input())
for i in range(N):
  a = sys.stdin.readline().split()
  if a[0] == "replace":
    S = S[:int(a[1])] + a[3] + S[int(a[2])+1:]
  elif a[0] == "reverse":
    X =  S[int(a[1]):int(a[2])+1]
    X = X[::-1]
    S = S[:int(a[1])] + X +S[int(a[2])+1:]
  elif a[0] == "print":
    print(S[int(a[1]):int(a[2])+1])

Submission status: Accepted

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

for loop in range(num_query):

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(q):
    od = list(map(str, input().split()))

    if od[0] == "print":
        print(word[int(od[1]): int(od[2]) + 1])

    elif od[0] == "reverse":
        if int(od[1]) == 0:
            word = "{}{}{}".format(word[: int(od[1])], word[int(
                od[2])::-1], word[int(od[2]) + 1:])
        else:
            word = "{}{}{}".format(word[: int(od[1])], word[int(
                od[2]): int(od[1]) - 1:-1], word[int(od[2]) + 1:])

    elif od[0] == "replace":
        word = "{}{}{}".format(
            word[: int(od[1])], od[3], word[int(od[2]) + 1:])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

# abcde

# axyze
# yxaze
# xaze

def mreplace(s, e, rep_str,v_str):
  replaced_str = v_str[:s] + rep_str + v_str[e + 1:]
  #print(replaced_str)#TODO delete
  return replaced_str

def mreverse(s, e, v_str):
  reversed_str = v_str[:s]+ v_str[s:e+1][::-1]+v_str[e+1:]
  #print(reversed_str)  #TODO delete
  return reversed_str


def mprint(s, e, v_str):
  print(v_str[s:e+1])


STR = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
for i in range(q):
  A = list(stdin.readline().split())
  if A[0] == "print":
    mprint(int(A[1]),int( A[2]), STR)
  elif A[0] == "replace":
    STR = mreplace(int(A[1]), int(A[2]), A[3], STR)
  elif A[0] == "reverse":
    STR = mreverse(int(A[1]), int(A[2]), STR)

Submission status: Accepted

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

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

Submission status: Accepted

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

for x in range(q):
    ip = list(input().split())

    if ip[0] == "print":
        print(st[int(ip[1]):int(ip[2])+1])
    elif ip[0] == "replace":
        ip[1] = int(ip[1])
        ip[2] = int(ip[2])
        temp = st[0:ip[1]] + ip[3] + st[ip[2]+1:]
        st = temp
    elif ip[0] == "reverse":
        ip[1] = int(ip[1])
        ip[2] = int(ip[2])
        temp = st[0:ip[1]] + st[ip[1]:ip[2]+1][::-1] + st[ip[2]+1:]
        st = temp

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    text = input().rstrip()
    n = int(input().rstrip())
    for i in range(n):
        s = input().split()
        if s[0] == "print":
            print(text[int(s[1]):int(s[2])+1])
        elif s[0] == "replace":
            new_text = ""
            new_text += text[:int(s[1])]
            new_text += s[3]
            new_text += text[int(s[2])+1:]
            text = new_text
        elif s[0] == "reverse":
            new_text = ""
            new_text += text[:int(s[1])]
            for i in range(int(s[2])-int(s[1]) + 1):
                new_text += text[int(s[2]) - i]
            new_text += text[int(s[2])+1:]
            text = new_text
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def run():
    s=input()
    command_num=int(input())
    
    for i in range(command_num):
        command = input().split()
        command = list(map(lambda x: int(x) if x.isdigit() else x,command))
        
        # print(s)
        if command[0] == "print":
            a=command[1]
            b=command[2]
            print(s[a:b+1])
            
        elif command[0] == "reverse":
            a=command[1]
            b=command[2]
            
            rev=s[a:b+1]
            rev=rev[::-1]
            #境界処理がめんどくさい
            pre= "" if a==0 else s[0:a]
            post="" if b==len(s)-1 else s[b+1:]
            
            s=pre+rev+post
            
            
        elif command[0] == "replace":
            a=command[1]
            b=command[2]
            p=command[3]
            #境界処理がめんどくさい
            pre= "" if a==0 else s[0:a]
            post="" if b==len(s)-1 else s[b+1:]
            
            s=pre+p+post
            
        else:
            assert False

run()

Submission status: Accepted

Solution code:
string=list(input())
num=int(input())
orders=[]
for n in range(num):
	orders.append(input().split(' '))

for order in orders:
	if order[0] == 'print':
		a=int(order[1])
		b=int(order[2])
		target_l=string[a:b+1]
		for i in target_l:
			print(i,end="")
		print()
		
	elif order[0] == 'reverse':
		a=int(order[1])
		b=int(order[2])
		target_l=string[a:b+1]
		for i in range(len(target_l)//2):
			tmp=target_l[i]
			target_l[i]=target_l[-(i+1)]
			target_l[-(i+1)]=tmp

		new_l=string[:a]+target_l+string[b+1:]
		string=new_l

	elif order[0] == 'replace':
		a=int(order[1])
		b=int(order[2])
		rep=list(order[3])
		for i,x in enumerate(string[a:b+1]):
			ii=i+a
			string[ii]=rep[i]

Submission status: Accepted

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

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

    if e[0] == "print":
        print(S[a:b+1])
    elif e[0] == "reverse":
        SS = S[a:b+1]
        S = S[:a] + SS[::-1] + S[b+1:]
    elif e[0] == "replace":
        S = S[:a] + e[3] + S[b+1:]

Submission status: Accepted

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

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

    if i_name == 'print':
        print(s[a:b+1])
    elif i_name == 'reverse':
        s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]
    elif i_name == 'replace':
        p = instruction[3]
        s = s[:a] + p + s[b+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

temp = []
for i in range(q):
    comm = input().split()

    if comm[0] == "replace":
        temp = list(comm[3])
        for i in range(0,int(comm[2])-int(comm[1])+1):
            str[int(comm[1])+i]=temp[i]
        temp.clear()
    elif comm[0] == "reverse":
        for i in reversed(range(int(comm[1]), int(comm[2])+1)):
            temp.append(str[i])
        for i in range(0, int(comm[2])-int(comm[1])+1):
            str[i+int(comm[1])] = temp[i]
        temp.clear()
    else:
        for i in range(int(comm[1]), int(comm[2])+1):
            temp.append(str[i])
        print(''.join(temp))
        temp.clear()

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
    lst = list(input().split())
    a = int(lst[1])
    b = int(lst[2])

    if lst[0] == 'replace':
        t1 = code[0:a]
        t2 = code[a:b+1]
        t3 = code[b+1:len(code)]
        code = t1 + lst[3] + t3

    elif lst[0] == 'reverse':
        s = code[a:b+1]
        ss = ''.join(list(reversed(s)))
        t1 = code[0:a]
        t2 = code[a:b+1]
        t3 = code[b+1:len(code)]
        code = t1 + ss + t3

    elif lst[0] == 'print':
        print(code[a:b+1])

Submission status: Accepted

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

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

Submission status: Accepted

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


resolve()

Submission status: Accepted

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

for i in range(N):
    a = input().split()
    x = int(a[1])
    y = int(a[2])
    if a[0] == "print":
        print(str[x:y+1])
    elif a[0] == "replace":
        #str = str.replace(str[x:y+1],a[3],1)
        #s = str[x:y+1]
        str = str[:x] + a[3] + str[y+1:]
    elif a[0] == "reverse":
        # str_sub = str[x:y+1]
        # str_sub = str_sub[::-1]
        # str = str.replace(str[x:y+1],str_sub,1)
        str = str[:x] + str[x:y+1][::-1] + str[y+1:]

Submission status: Accepted

Solution code:
mojiretsu = list(input())
q = int(input())
text = ""

for i in range(q):
    order = list(input().split())
    a = int(order[1])
    b = int(order[2])
    if order[0] == "print":
        for i in range(a, b+1):
            text += mojiretsu[i]
        print(text)
        text = ""

    elif order[0] == "reverse":
        if a == 0:
            mojiretsu = mojiretsu[b::-1] + mojiretsu[b+1:]
        else:
            mojiretsu = mojiretsu[:a] + mojiretsu[b:a-1:-1] + mojiretsu[b+1:]

    elif order[0] == "replace":
        replace_word = list(order[3])
        mojiretsu = mojiretsu[:a] + replace_word + mojiretsu[b+1:]

Submission status: Accepted

Solution code:
text = list(input())
num = int(input())

for i in range(num):
    orderList = list(input().split(" "))
    start, end = int(orderList[1]), int(orderList[2])
    loopCount = end - start + 1
    
    if orderList[0] == 'replace':
        replaceText = list(orderList[3])
        for i in range(loopCount):
            text[i + start] = replaceText[i]
            
    elif orderList[0] == 'reverse':
        tmpList = []
        for i in range(loopCount):
            tmpList.append(text[i + start])
        for i in range(loopCount):
            text[i + start] = tmpList[loopCount - i - 1]
            
    else:
        answer = []
        for i in range(loopCount):
            answer += text[i + start]
        answer = "".join(answer)
        print(f"{answer}")

Submission status: Accepted

Solution code:
s = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(''.join(s[a:b+1]))
    elif command[0] == 'reverse':
        while a < b:
            s[a], s[b] = s[b], s[a]
            a += 1
            b -= 1
    elif command[0] == 'replace':
        p = list(command[3])
        j = 0
        while a + j <= b:
            s[a + j] = p[j]
            j += 1
    else:
        pass