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 main():
    string = input()
    q = int(input())
    for _ in range(q):
        command = input().split()
        a = int(command[1])
        b = int(command[2])
        if command[0] == 'print':
            print(string[a:b+1])
        elif command[0] == 'reverse':
            if a == b:
                reversed_string = string[a]
            else:
                c = a-1 if a is not 0 else None
                reversed_string = string[b:c:-1]
            string = string[:a] + reversed_string + string[b+1:]
        elif command[0] == 'replace':
            string = string[:a] + command[3] + string[b+1:]


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
for _ in [0]*int(input()):
    command = []
    command.append(list(map(str,input().split())))
   # print(command[0][0])
    if command[0][0] == 'replace':
        s = s[:int(command[0][1])] + command[0][3] + s[int(command[0][2])+1:]
    elif command[0][0] == 'reverse':
        temp =  s[int(command[0][1]):int(command[0][2])+1:]
        s = s[:int(command[0][1])] +temp[::-1] + s[int(command[0][2])+1:]
    elif command[0][0] == 'print':
        print(s[int(command[0][1]):int(command[0][2])+1])

Submission status: Accepted

Solution code:
S = str(input())
for i in range(int(input())):
    L = input().split()
    o = L[0]
    a = int(L[1])
    b = int(L[2]) + 1
    if len(L) == 4:
        p = L[3]
    else:
        p = 0

    if o == "print":
        print(S[a:b])
    elif o == "reverse":
        S = S[:a]+S[a:b][::-1]+S[b:]
    elif o == "replace":
        S = S[:a]+p+S[b:]

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

num = int(input())

for a in range(num):
    order = input()
    if "replace" in order: #strのa文字目からb文字目までをpに置き換える
        order,header,footer,p = order.split()
        header = int(header)
        footer = int(footer)
        
        string = string[:header] + p + string[footer+1:]
        
        
    elif "reverse" in order:#strのa文字目からb文字目までを逆順にする。
        order,header,footer = order.split()
        
        header = int(header)
        footer = int(footer)
        
        reverse = string[header:footer+1]  
        reverse = reverse[::-1]
        string = string[:header] + reverse + string[footer+1:]
        

    elif "print" in order:#strのa文字目からb文字目までを出力する
        order,header,footer = order.split()
        header = int(header)
        footer = int(footer)
        print(string[header:footer+1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()
q = int(stdin.readline().rstrip())
for i in range(q):
    query = stdin.readline().rstrip().split()
    query[1] = int(query[1])
    query[2] = int(query[2])

    if query[0] == "print":
        print(s[query[1]:query[2]+1])
    elif query[0] == "reverse":
        s = s[:query[1]] + s[query[1]:query[2]+1][::-1] + s[query[2]+1:]
    elif query[0] == "replace":
        s = s[:query[1]] + query[3] + s[query[2]+1:]

Submission status: Accepted

Solution code:
S = str(input())
N = int(input())
for _i in range(N):
    line = input().split()
    start = int(line[1])
    end = int(line[2])

    if line[0] == 'print':
        print(S[start:end + 1])
    if line[0] == 'reverse':
        reversed_word = list(S[start:end + 1])
        reversed_word.reverse()
        S = S[:start] + ''.join(reversed_word) + S[end + 1:]
    if line[0] == 'replace':
        S = S[:start] + line[3] + S[end + 1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

def replace_(x,y,target,replace):
    return target[:x]+replace+target[y+1:]

def reverse_(x,y,target):
    temp_rev = target[x:y+1]
    rev = temp_rev[::-1]
    return target[:x]+rev+target[y+1:]

def print_(x,y,target):
    print(target[x:y+1])


target = input()
num = int(input())
for _ in range(num):
    i = input().split()
    if i[0] == 'replace':
        target = replace_(int(i[1]),int(i[2]),target,i[3])
    elif i[0] == 'reverse':
        target = reverse_(int(i[1]),int(i[2]),target)
    elif i[0] == 'print':
        print_(int(i[1]),int(i[2]),target)

Submission status: Accepted

Solution code:
target = input()
for _ in range(int(input())):
    order = input().split()
    if order[0] == 'print':
        print(target[int(order[1]):int(order[2])+1])
    elif order[0] == 'reverse':
        new_sent = ''
        begin_num=int(order[1])
        end_num=int(order[2])+1
        for i in range(len(target)):
            if begin_num <= i < end_num:
                new_sent += target[begin_num + end_num-1 -i]
            else:
                new_sent += target[i]
        target = new_sent
    else:
        target = target[:int(order[1])] + order[3] + target[int(order[2])+1:]

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
  cmd = list(str(input()).split())
  
  if cmd[0] == 'print':
    print(s[int(cmd[1]):int(cmd[2])+1])
  elif cmd[0] == 'reverse':
    temp = s[int(cmd[1]):int(cmd[2])+1]
    s = s[:int(cmd[1])] + temp[::-1] + s[int(cmd[2])+1:] 
  else: #replace
    s = s[:int(cmd[1])] + cmd[3] + s[int(cmd[2])+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string = input()
for i in range(int(input())):
    lst = list(map(str, input().split()))
    if lst[0] == "replace":
        string = string[:int(lst[1])] + lst[3] + string[int(lst[2])+1:]
    if lst[0] == "reverse":
        rev_str = str(string[int(lst[1]):int(lst[2])+1])
        string = string[:int(lst[1])] + rev_str[::-1] + string[int(lst[2])+1:]
    if lst[0] == "print":
        print(string[int(lst[1]):int(lst[2])+1])

Submission status: Accepted

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

for _ in range(n):
	command = input().split(" ")
	st = int(command[1])
	en = int(command[2]) + 1

	if command[0] == "replace":
		A[st:en] = list(command[3])
	elif command[0] == "reverse":
		B = A[st:en]
		B.reverse()
		A[st:en] = B
	else:
		moji = ""
		for i in A[st:en]:
			moji += str(i)
		print(moji)

Submission status: Accepted

Solution code:

A = list(input())
n = int(input())

for _ in range(n):
	command = input().split(" ")
	st = int(command[1])
	en = int(command[2]) + 1

	if command[0] == "replace":
		A[st:en] = list(command[3])
	elif command[0] == "reverse":
		A[st:en] = reversed(A[st:en])
	else:
		print(*A[st:en],sep="")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
st=input()
n=int(input())
for i in range(n):
  moji=list(map(str,input().split()))

  a=int(moji[1])
  b=int(moji[2])
  if moji[0]=="print":
    print(st[a:b+1])
  if moji[0]=="reverse":
    st=st[:a] + st[a:b+1][::-1] + st[b+1:]
  if moji[0]=="replace":
    st=st[:a]+moji[3]+st[b+1:]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

    if cmd[0] == 'print':
        print(s[a:b+1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b+1:]

Submission status: Accepted

Solution code:
w=raw_input()
n=input()
l=['print','replace','reverse']
for i in range(n):
    c=map(str,raw_input().split())
    if c[0]==l[0]:
        print w[int(c[1]):int(c[2])+1]
    elif c[0]==l[1]:
        w=w[:int(c[1])]+c[3]+w[int(c[2])+1:]
    else:
        w=w[0:int(c[1])]+w[int(c[1]):int(c[2])+1][::-1]+w[int(c[2])+1:]

Submission status: Accepted

Solution code:
s = raw_input()
q = int(raw_input())
for i in range(q):
	m = raw_input().split(' ')
	if m[0]=="print":
		print s[int(m[1]):int(m[2])+1]
	elif m[0] == "replace":
		s = s[:int(m[1])]+m[3]+s[int(m[2])+1:]
	else:
		t = s[int(m[1]):int(m[2])+1]
		s = s[:int(m[1])]+t[::-1]+s[int(m[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 = raw_input()
for _ in [0]*int(raw_input()):
  I = raw_input().split()
  a = I[0][2]
  b = int(I[1])
  c = int(I[2])+1
  if a=='p': s=s[:b]+I[3]+s[c:]
  elif a=='v': s=s[:b]+s[b:c][::-1]+s[c:]
  else: print s[b:c]

Submission status: Accepted

Solution code:
def sub_print(text, a, b):
    print(text[a:b])
    return text

def sub_reverse(text, a, b):
    return text[:a] + text[a:b][::-1] + text[b:]
def sub_replace(text, a, b, p):
    return text[:a] +p + text[b:]

func = {'print':sub_print, 'reverse':sub_reverse, 'replace':sub_replace}

text = input()
q = int(input())
for i in range(q):
    line = input().split()
    text = func[line[0]](text, int(line[1]), int(line[2]) + 1, *line[3:])

Submission status: Accepted

Solution code:
tgtstr = list(raw_input())
n = int(raw_input())

for i in range(n):
    cmd_list = raw_input().split(" ")
    if cmd_list[0] == "replace":
        for idx in range(int(cmd_list[1]), int(cmd_list[2])+1):
            tgtstr[idx] = cmd_list[3][idx - int(cmd_list[1])]
    elif cmd_list[0] == "reverse":
        start = int(cmd_list[1])
        end = int(cmd_list[2])
        while True:
            
            tmp = str(tgtstr[start])
            tgtstr[start] = str(tgtstr[end])
            tgtstr[end] = tmp
            start += 1
            end -= 1
            if start >= end:
                break

    elif cmd_list[0] == "print":
        print "".join(tgtstr[int(cmd_list[1]):int(cmd_list[2])+1])

Submission status: Accepted

Solution code:
import sys

string = raw_input()
string_list = list(string)
#print string_list
q = input()

for i in range(q):
    x = map(str, raw_input().split())
    if(x[0] == 'replace'):
        k = 0
        for j in range(int(x[1]), int(x[2])+1):
            string_list[j] = x[3][k]
            k += 1
        #print "".join(string_list)
    if(x[0] == 'reverse'):
        temp = []
        for j in range(int(x[1]), int(x[2])+1):
            temp.append(str(string_list[j]))
        temp.reverse()
        #print temp        
        temp_list = list(temp)
        k = 0
        for j in range(int(x[1]), int(x[2])+1):
           string_list[j] = temp[k]
           k += 1
        #print "".join(string_list)
    if(x[0] == 'print'):
        for i in range(int(x[1]), int(x[2])+1):
          sys.stdout.write(string_list[i])
        print

Submission status: Accepted

Solution code:
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] + args[3] + text[b + 1:]

Submission status: Accepted

Solution code:
str1 = input()
count = int(input())

for i in range(count):
    args = input().split()
    (a,b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(str1[a:b + 1])
    elif args[0] == 'reverse':
        str1 = str1[0:a] + str1[a:b + 1][::-1] + str1[b + 1:]
    elif args[0] == 'replace':
        str1 = str1[0:a] + args[3] + str1[b + 1:]

Submission status: Accepted

Solution code:
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]

    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] + args[3] + text[b + 1:]

Submission status: Accepted

Solution code:
text = input()
count = int(input())

for c in range(count):
    args = input().split()
    (a, b) = [int(x) for x in args[1:3]]
    if args[0] == 'print':
        print(text[a:b + 1])
    elif args[0] == 'reverse':
        text = text[0:a] + text[a:b + 1][::-1] + text[b + 1:]
    elif args[0] == 'replace':
        text = text[0:a] +  args[3] + text[b + 1:]

Submission status: Accepted

Solution code:
import sys
line = sys.stdin.readline().strip()
n = int(sys.stdin.readline())
for i in range(n):
    v = sys.stdin.readline().split()
    op = v[0]
    a = int(v[1])
    b = int(v[2])
    if op == "print":
        print(line[a: b + 1])
    elif op == "reverse":
        line = line[:a] + line[a: b + 1][::-1] + line[b + 1:]
    elif op == "replace":
        p = v[3]
        line = line[:a] + p + line[b + 1:]

Submission status: Accepted

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

for k in range(q): 
    ls = raw_input().split()
    a = int(ls[1])
    b = int(ls[2])
    if ls[0] == 'print':
        print ''.join(s[a:b+1])
    elif ls[0] == 'reverse':
        if a != 0:
            s[a:b+1] = s[b:a-1:-1]
        else:
            s[a:b+1] = s[b::-1]
    elif ls[0] == 'replace':
        s[a:b+1] = list(ls[3])

Submission status: Accepted

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

def my_reverse(s, a, b):
    return s[:a] + s[a:b+1][::-1] + s[b+1:]

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

if __name__ == '__main__':
    s = input()
    q = int(input())
    for i in range(q):
        code = input().split()
        op, a, b = code[0], int(code[1]), int(code[2])
        if op == 'print':
            my_print(s, a, b)
        elif op == 'reverse':
            s = my_reverse(s, a, b)
        elif op == 'replace':
            s = my_replace(s, a, b, code[3])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
#1_9_D 2015.4.13
s = list(input())
n = int(input())
for i in range(n):
    c = input().split()
    if c[0] == 'print':
        print(''.join(s[int(c[1]) : int(c[2])+1]))
    elif c[0] == 'reverse' and c[1] != '0':
        s[int(c[1]) : int(c[2])+1] = s[int(c[2]) : int(c[1])-1 :-1]
    elif c[0] == 'reverse' and c[1] == '0':
        s[:int(c[2])+1] = s[int(c[2])::-1]
    else: #replace
        s[int(c[1]) : int(c[2])+1] = list(c[3])

Submission status: Accepted

Solution code:
#coding:utf-8
#1_9_D 2015.4.14
s = input()

for i in range(int(input())):
    cmd = input().split()
    a,b = [int(x) for x in cmd[1:3]]

    if cmd[0] == 'print':
        print(s[a:b+1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b+1:]

Submission status: Accepted

Solution code:
word=str(input())
count=int(input())
for i in range(count):
	com=list(map(str,input().split()))
	if com[0]=='print':
		print(word[int(com[1]):int(com[2])+1])
	elif com[0]=='replace':
		word=word[:int(com[1])]+com[3]+word[int(com[2])+1:]
	elif com[0]=='reverse':
		word=word[:int(com[1])]+word[int(com[1]):int(com[2])+1][::-1]+word[int(com[2])+1:]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(raw_input())
for loop in xrange(input()):
    c = raw_input().split()
    if c[0] == "replace":
        s[int(c[1]): int(c[2]) + 1] = list(c[3])
    if c[0] == "reverse":
        s[int(c[1]): int(c[2]) + 1] = s[int(c[1]): int(c[2]) + 1][::-1]
    if c[0] == "print":
        print "".join(s[int(c[1]): int(c[2]) + 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string = raw_input()
for _ in xrange(input()):
    order = raw_input().split()
    a, b = map(int, order[1:3])
    if order[0] == 'print':
        print string[a:b+1]
    elif order[0] == 'reverse':
        # string = string[:a] + string[b:a-1:-1] + string[b+1:]
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif order[0] == 'replace':
        string = string[:a] + order[3] + string[b+1:]

Submission status: Accepted

Solution code:
string = input()
n = int(input())
for _ in range(n):
    query = input().split()
    if query[0] == 'replace':
        op, a, b, p = query
        a, b = int(a), int(b)
        string = string[:a] + p + string[b + 1:]
    elif query[0] == 'reverse':
        op, a, b = query
        a, b = int(a), int(b)
        string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
    elif query[0] == 'print':
        op, a, b = query
        a, b = int(a), int(b)
        print(string[a: b + 1])

Submission status: Accepted

Solution code:
str0 = raw_input()
q = int(raw_input())

for i in xrange(q):
  # print "###########################"
  # print "str0 = " + str0
  line = raw_input().split(" ")
  temp = str0[int(line[1]):int(line[2])+1]
  if line[0] == "print":
    print temp
  elif line[0] == "reverse":
    temp2 = [] 
    # print "temp = " + temp
    for j in xrange(len(temp)):
      temp2.append(temp[len(temp) - j - 1])
    str0 = str0[:int(line[1])] + "".join(temp2) + str0[int(line[2]) + 1:]
    # print "str0 = " + str0
  elif line[0] == "replace":
    str0 = str0[:int(line[1])] + line[3] + str0[int(line[2]) + 1:]
    # print "str0 = " + str0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()
Q = input()
for q in range(Q):
    str_order = raw_input().split()
    if str_order[0] == 'print':
        print s[int(str_order[1]):int(str_order[2])+1]
    elif str_order[0] == 'reverse':
        start = s[:int(str_order[1])]
        mid = s[int(str_order[1]):int(str_order[2])+1]
        mid = mid[::-1]
        end = s[int(str_order[2])+1:]
        s = start+mid+end
    elif str_order[0] == 'replace':
        start = s[:int(str_order[1])]
        mid = str_order[3]
        end = s[int(str_order[2])+1:]
        s = start+mid+end

Submission status: Accepted

Solution code:
s = list(raw_input())
Q = input()
for q in range(Q):
    str_order = raw_input().split()
    a = int(str_order[1])
    b = int(str_order[2])
    if str_order[0] == 'print':
        print ''.join(s[a:b+1])
    elif str_order[0] == 'reverse':
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp
    elif str_order[0] == 'replace':
        s[a:b+1] = list(str_order[3])

Submission status: Accepted

Solution code:

string = list(raw_input())
q = input()
List = [0]*q
for i in range(q):
	List[i] = raw_input().split()
	List[i][1:3] = map(int,List[i][1:3])
	if List[i][0] == 'print' :
		print '%s' %"".join(string[List[i][1]:List[i][2]+1])
	elif List[i][0] == 'reverse':
		s = [0] * (List[i][2]-List[i][1])
		s = reversed(string[List[i][1]:List[i][2]+1])
		string[List[i][1]:List[i][2]+1] = s
	else :
		string[List[i][1]:List[i][2]+1] = list(List[i][3])

Submission status: Accepted

Solution code:
string = input()

n = int(input())

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

Submission status: Accepted

Solution code:
str = input()
num = int(input())
for i in range(num):
    command = input().split()
    c1, c2, c3 = command[0], int(command[1]), int(command[2])
    if c1 == 'print':
        print(str[c2:c3 + 1])
    elif c1 == 'reverse':
        str = str[:c2] + str[c2:c3 + 1][::-1] + str[c3 + 1:]
    elif c1 == 'replace':
        str = str[:c2] + command[3] + str[c3 + 1:]

Submission status: Accepted

Solution code:
in_str = raw_input()
q = int(raw_input())
for i in range(q):
    oper = raw_input().split()
    if oper[0] == 'print':
        print in_str[(int(oper[1])):(int(oper[2]))+1]
    elif oper[0] == 'reverse':
        buf = ''
        for i in range(int(oper[1])):
            buf += in_str[i]
        for i in reversed(range(int(oper[1]),int(oper[2])+1)):
            buf += in_str[i]
        buf += in_str[(int(oper[2]))+1:]
        in_str = buf
    elif oper[0] == 'replace':
        buf = in_str[:(int(oper[1]))]
        buf += oper[3]
        buf += in_str[(int(oper[2]))+1:]
        in_str = buf

Submission status: Accepted

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

Submission status: Accepted

Solution code:
instr = raw_input().strip()
commandnum = input()
for c in xrange(commandnum):
    command = raw_input().split()
    if command[0]=="replace":
        instr = instr[:int(command[1])]+command[3]+instr[int(command[2])+1:]
    elif command[0]=="reverse":
        instr = instr[:int(command[1])]+instr[int(command[1]):int(command[2])+1][::-1]+instr[int(command[2])+1:]
    elif command[0]=="print":
        print instr[int(command[1]):int(command[2])+1]
    else:
        print "invalid command."
        break

Submission status: Accepted

Solution code:
s = list(raw_input())
Q = input()
for q in range(Q):
  str_order = raw_input().split()
  a = int(str_order[1])
  b = int(str_order[2])
  if str_order[0] == 'print':
    print ''.join(s[a:b+1])
  elif str_order[0] == 'reverse':
    tmp = s[a:b+1]
    tmp.reverse()
    s[a:b+1] = tmp
  elif str_order[0] == 'replace':
    s[a:b+1] = list(str_order[3])

Submission status: Accepted

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

for i in range(n):
    tmp = map(str, raw_input().split())
    if tmp[0] == "print":
        print string[int(tmp[1]): int(tmp[2]) + 1]
    elif tmp[0] == "reverse":
        s = ""
        for i in range(int(tmp[1])):
            s += string[i]
        for i in range(int(tmp[2]) - int(tmp[1]) + 1):
            s += string[int(tmp[2]) - i]
        for i in range (len(string) - int(tmp[2]) - 1):
            s += string[i + int(tmp[2]) + 1]
        string = s
    elif tmp[0] == "replace":
        s = string[:int(tmp[1])] + tmp[3] + string[int(tmp[2]) + 1:]
        string = s

Submission status: Accepted

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

def reverse_ab(s, a, b):
    s_f = s[:a]
    s_m = s[a:b+1]
    s_b = s[b+1:]

    return s_f + s_m[::-1] + s_b

def replace_ab(s, a, b, p):
    s_f = s[:a]
    s_b = s[b+1:]

    return s_f + p + s_b

if __name__ == "__main__":
    s = input()
    q = int(input())

    for i in range(q):
        ops = input().split()
        if ops[0] == "print":
            print_ab(s, int(ops[1]), int(ops[2]))
        elif ops[0] == "reverse":
            s = reverse_ab(s, int(ops[1]), int(ops[2]))
        elif ops[0] == "replace":
            s = replace_ab(s, int(ops[1]), int(ops[2]), ops[3])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def s_print(s, line):
    a, b = map(int, line.split()[1:])
    print(s[a:b + 1])
    return s


def s_reverse(s, line):
    a, b = map(int, line.split()[1:])
    return s[:a] + s[a:b + 1][::-1] + s[b + 1:]


def s_replace(s, line):
    ls = line.split()
    a, b = map(int, ls[1:3])
    rep = ls[-1]
    return s[:a] + rep + s[b + 1:]


func_dict = {'pri': s_print, 'rev': s_reverse, 'rep': s_replace}

s, q = input(), int(input())
while q:
    line = input()
    s = func_dict[line[:3]](s, line)
    q -= 1

Submission status: Accepted

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