A. Range Swap
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, p, q, r, s = list(map(int, input().rstrip('\n').split()))
a = list(map(int, input().rstrip('\n').split()))
for i in range(r-1, s):
a[i], a[i - (r - p)] = a[i - (r - p)], a[i]
print(*a)
if __name__ == '__main__':
solve()
B. Cat
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
s = str(input().rstrip('\n'))
print(s.replace("na", "nya"))
if __name__ == '__main__':
solve()
C. Rotate and Palindrome
import sys
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, a, b = list(map(int, input().rstrip('\n').split()))
s = list(str(input().rstrip('\n')))
s = collections.deque(s)
ans = pow(10, 20)
for i in range(n):
cnt = 0
for j in range(n // 2):
if s[j] != s[-j-1]:
cnt += 1
ans = min(ans, i * a + cnt * b)
s.append(s.popleft())
print(ans)
if __name__ == '__main__':
solve()
D. Money in Hand
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, x = list(map(int, input().rstrip('\n').split()))
dp = [False] * (x + 1)
dp[0] = True
for i in range(n):
a, b = list(map(int, input().rstrip('\n').split()))
for j in range(b):
for k in range(x - a, -1, -1):
if dp[k]:
dp[k+a] = True
print("Yes" if dp[x] else "No")
if __name__ == '__main__':
solve()