peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import math
import fractions
import functools

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
l = list(map(int, input().split()))
a = lcm_list(l)
if a % 2 == 0:
    a = a // 2
print(-(-m // a) // 2)
# Judge status: Accepted
a, b, c = map(int, input().split())

ans='NO'
for i in range(1,b+1):
    if a*i % b ==c:
        ans='YES'
print(ans)
# Judge status: Wrong Answer
(str_len,cng_cnt) = input().split(" ")
str_input = list(input())


cng_cnt= int(cng_cnt)
tmp1=""
cnt=0
cnt2=0
for st in str_input:
    if(tmp1 == st ):
      cnt = cnt+1
    else:
      cnt2= cnt2 + 1
      
    tmp1=st

if (cng_cnt < cnt2 ):
	c_up = cng_cnt * 2 
else:
	c_up= (cnt2 * 2) + (cng_cnt - cnt2)
ans =cnt + c_up

print(ans)
# Judge status: Wrong Answer
print('A%sC'%'BR'[id('A')%7%2])
# Judge status: Accepted
N = int(input())
count = 1
while count ** 2 <= N:
    count += 1

print((count-1)**2)
# Judge status: Accepted
def distance(a,b):
    return abs((a-b)**2)

import math

n,d = map(int,input().split())
x = []
for i in range(n):
    x.append(list(map(int,input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        current = 0
        for k in range(d):
            current += distance(x[i][k],x[j][k])
        current = math.sqrt(current)
        if float.is_integer(current):
            ans += 1
print(ans)
# Judge status: Wrong Answer
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
for i in range(m):
    road = list(map(int, input().split()))
    if hs[road[0]-1] <= hs[road[1]-1]:
        ans[road[0]-1] = 0
    if hs[road[0]-1] >= hs[road[1]-1]:
        ans[road[1]-1] = 0
print(ans.count(0))
# Judge status: Accepted
N = int(input())
DP = [[0]*3 for i in range(N+1)]
for i in range(1,N+1):
    a,b,c = list(map(int,input().split()))
    DP[i][0] = max(DP[i-1][1]+a,DP[i-1][2]+a)
    DP[i][1] = max(DP[i-1][0]+b,DP[i-1][2]+b)
    DP[i][2] = max(DP[i-1][0]+c,DP[i-1][1]+c)
print(max(DP[-1]))
# Judge status: Wrong Answer
N=int(input())
*A,=map(int,input().split())

count1=0
i=0
while i<N:
    count1+=A[i]
    i+=1
    ans1=count1-sum(A[i:])
    if ans1>=0:
        break

if ans1<=count1-i:
    print(ans1)
else:
    print(sum(A[i-1:])-sum(A[:i-1]))
# Judge status: Accepted
def main():
    a, b, t = map(int, input().split())
    print(b * (t//a))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
# t=int(input())
# for _ in range(t):
#     n=int(input())
#     arr=[int(x) for x in input().split()]
n=int(input())
if n%9 == 0:
    print("YES")
else:
    print("NO")
#print(t*need)
# Judge status: Wrong Answer
s=input()
q=int(input())
trans=0
aft=""
bef=""
for i in range(q):
  que=input()
  if que[0]=="1":
    trans=1-trans
  else:
    que=que.split()
    if (que[1]=="1" and trans==0) or (que[1]=="2" and trans==1):
      bef=bef+que[2]
    else:
      aft=aft+que[2]
if trans==0:
  print("".join(bef[::-1])+s+"".join(aft))
else:
  print("".join(aft[::-1])+s+"".join(bef))
# Judge status: Accepted
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))
dif=9999
ans=0
for i in range(n):
  tmp=abs(a-(t-0.006*H[i]))
  if tmp<dif:
    dif=tmp
    ans=i+1
print(ans)
# Judge status: Wrong Answer
def main():
    n,k=map(int,input().split())
    ans=n**2
    ans-=n*k
    for i in range(k+1,n+1):
        temp=n//i
        temp*=k
        temp+=min(n%i,k-1,0)
        ans-=temp 
    print(ans)

main()
# Judge status: Wrong Answer
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

print(range(1, 25)[(A+B-1)%24])
# Judge status: Wrong Answer
from collections import Counter
from sys import maxsize

# input
N = int(input())
S = Counter([input() for i in range(N)])
M = int(input())
T = Counter([input() for j in range(M)])

# check
max_cnt = -maxsize
for s in S.keys():
    cnt = S[s]
    if s in T.keys():
        cnt -= T[s]

    if max_cnt < cnt:
        max_cnt = cnt

print(max)
# Judge status: Accepted
A = [int(input())]

for n in range(2,10**6):
  if A[-1]%2==0:
    if A[-1]//2 in A:
      print(n)
      exit()
    else:
      A.append(A[-1]//2)
  else:
    if 1+3*A[-1] in A:
      print(n)
      exit()
    else:
      A.append(1+3*A[-1])
# Judge status: Wrong Answer
N = int(input())
dict = {}
for i in range(1, N+1):
    S, P_str = tuple(input().split())
    P = int(P_str)
    try:
        dict[S].append((P, i))
    except:
        dict[S] = [(P, i)]

items = sorted(dict.items(), key=lambda x: x[1], reverse=True)
for city, info in items:
    for p, n in sorted(info, key=lambda x: x[0], reverse=True):
        print(n)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))

a.sort()
print(sum(a[1:]))
# Judge status: Accepted
from collections import deque as que
q=que()
n,m=map(int,input().split())
e=[[] for i in range(n)]
for i in range(m):
    a,s=map(int,input().split())
    e[a-1].append(s-1);e[s-1].append(a-1)
table=[0]*n
ok=0
table[0]=1
q.append(0)
while len(q):
    now=q.popleft()
    for to in e[now]:
        if table[to]==0:
            table[to]=now+1
            q.append(to)
            ok+=1
if n-1==ok:
    print("Yes",*table[1:],sep="\n")
else:print("No")
# Judge status: Accepted
def main():
    Q,H,S,D = map(int,input().split())
    N = int(input())
    mincos = min(4*Q,2*H,S)
    t1 = N*mincos
    t2 = (N//2)*D + (N%2)*mincos
    print(min(t1,t2))

if __name__ == '__main__':
    main()
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

N,*A = map(int,read().split())

MOD = 10 ** 9 + 7

lcm = reduce(lambda x,y: x//gcd(x,y)*y, A)

answer = sum(lcm//x for x in A)
answer %= MOD
print(answer)
# Judge status: Accepted

n,p = map(int,input().split())
a = list(map(int,input().split()))

num = 0
count = 0

for i in range(n):
    if a[i] % 2 == 0:
        count += 1

if count == n:
    if p == 0:
        print(2**n)
    elif p == 1:
        print(0)
else:
    print(2**(n-1))
# Judge status: Wrong Answer
import sys
import math
input = lambda: sys.stdin.readline().rstrip()

def comb(a, b):
    return math.factorial(a)//(math.factorial(b)*math.factorial(a-b))

def main():
    n, a, b = map(int, input().split())
    if a > b or (n==1 and a<b):
        print(0)
    elif a == b:
        print(1)
    else:
        print(comb(b-a+n, n) - comb(b-a+n-1, n) * 2)
            
if __name__ == '__main__':
    main()
# Judge status: Accepted
a, b, c = map(int, input().split())
if a == b and b == c:
  print(1)
elif a != b and b != c and c != a:
  print(3)
else:
  print(2)
# Judge status: Wrong Answer
s = int(input())
xy = [-1] * 6
xy[4], xy[5], xy[3], xy[0] = "0000"
a = 1 if s < 10**9 else 2
for i in range(a, int(s**0.5) + 1):
    if s % i == 0:
        xy[2] = str(i)
        xy[1] = str(s // i)
        break
print(" ".join(xy))
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
x = int(input())

res = 0
for i in range(a+1):
    aa = 500*i
    for j in range(b+1):
        bb = 100*j
        for k in range(c+1):
            cc = 50*k
            if aa+ bb+ cc ==x:
                res +=1

print(res)
# Judge status: Accepted
n = int(input())
aa = list(map(int, input().split()))
c1 = 0 # odd 
c2 = 0 
c4 = 0
la = len(aa)

for a in aa:
  if a % 4 == 0:
    c4 += 1
  elif a % 2 == 0:
    c2 += 1
  else:
    c1 += 1
    
if c1 == 0:
  print('Yes')
  exit()

elif c4 >= c1:
  print('Yes')
  exit()
  
elif c4 == c1 - 1 and c2 == 0:
  print('Yes')
  exit()
  
print('No')
# Judge status: Accepted
w, a, b = map(int, input().split())
if a <= b:
    ans = max(b - (a + w), 0)
else:
    ans = max(a - (b + w), 0)
print(ans)
# Judge status: Accepted
S = input()
if S[-1]=="s":
  S += "e"
S += "s"
print(S)
# Judge status: Accepted
import sys
S = list(input())
lis = [0] * (len(S)+1)
 
if len(S) == 1:
    print(1)
    sys.exit()
 
 
#最初は < を処理する
for i in range(len(S)):
    if S[i] == "<":
        lis[i+1] = lis[i] + 1
 
 
 
 
for j in range(len(S)-1,-1,-1):
    if S[j] == ">":
        lis[j] = max(lis[j],lis[j+1] + 1)
 
 
 
print(sum(lis))
# Judge status: Wrong Answer
x = input()
ans = 0
for c in x:
  if c == 'S':
    ans += 1
  elif c != 0:
    ans -= 1
print(-ans * 2)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
a_min=min(a)
a_max=max(a)

s=list(range(a_min,a_max+1))
t=[0]*(a_max+1)

for i in range(n):
  t[a[i]]+=1

x=0
for j in range(1,len(t)-1):
  x=max(x,t[j-1]+t[j]+t[j+1])

print(x)
# Judge status: Accepted
import math
import sys
input = sys.stdin.readline

def main():
    A, B, N = map(int, input().split())

    x = min(B-1, N)
    print(math.floor(A*x/B) - A*math.floor(x/B))

main()
# Judge status: Accepted
N=int(input())

if(N % 10==9):
    print("Yes")
elif(N//10==9):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print('Bad')
else:
  print('Good')
# Judge status: Wrong Answer
N, M = map(int, input().split())

M = M - 1 if M%2==1 else M

if N > 2*M:
    print(M//2)
else:
    if M-2*N >= 4:
        print(N+(M-2*N)//4)
    else:
        print(N)
# Judge status: Wrong Answer
s = input()
t = input()
def matches(x, t):
    for j in range(len(t)):
        if x[j] != '?' and x[j] != t[j]:
            return False
    return True

valid = False
for i in range(len(s)-len(t)+1):
    if matches(s[i:], t):
        valid = True
        s = s[:i] + t + s[i+len(t):]

if valid:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')
# Judge status: Wrong Answer
W,a,b = map(int,input().split())

print(max(a,b)-(min(a,b)+ W))
# Judge status: Accepted
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))

check = [-1] * N
q = deque([1])
now = A[0]
check[0] = 0

for i in range(K):
    if check[now - 1] != -1:
        break
    check[now - 1] = i + 1
    q.append(now)
    now = A[now - 1]

x = check[now - 1]

if x > K:
    ans = q[K]
else:
    r = list(q)[x:]
    ans = q[(K - x) % len(r) + x]

print(ans)
# Judge status: Accepted
s = input()
a = [True for _ in range(26)]
for si in s:
  a[ord(si)-97] = False
for i in range(26):
  if a[i]:
    print(chr(i+97))
    exit()
print('None')
# Judge status: Wrong Answer
n,W=map(int,input().split())
wt=[]
value=[]
for i in range(n):
    x,y=map(int,input().split())
    value.append(x)
    wt.append(y)
dp = [0] * (W + 1)
for i in range(n):
    for j in range(W, wt[i], -1):
        dp[j] = max(dp[j], value[i] + dp[j - wt[i]]);
print(dp[W])
# Judge status: Accepted
import math
a,b = input().split()
A = int(a+b)
if math.sqrt(A).is_integer():
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))
total = 0
max_total = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        total += 1
        max_total = max(max_total, total)
    else:
        total = 0

print(max_total)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

sum_A = sum(A)
sum_i = (N * (N + 1)) / 2

b = (sum_A - sum_i) / N

if b < 0:
    b2 = int(b)
    b1 = b2 - 1
else:
    b1 = int(b)
    b2 = b + 1

ans1 = 0
ans2 = 0
for i, a in enumerate(A, start=1):
    ans1 += abs(a - b1 - i)
    ans2 += abs(a - b2 - i)

print(min(ans1, ans2))
# Judge status: Accepted
S = input()
if S[0] == 'A':
    if S[1] != 'C' and S[-1] != 'C':
        if S.count('C') == 1:
            S = S.lstrip('A')
            S = S.replace('C','c')
            if S.islower():
                print("AC")
                exit(0)
 
print('WA')
# Judge status: Accepted
a,b = map(int,input().split())
c = b-a
wa = c*(c+1)//2
print(wa-b)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
division = {str(i):0 for i in range(9)}
for i in a:
    x = i // 400
    if x > 8:
        x = 8
    division[str(x)] += 1
ans = 0
check = 1
for i in range(8):
    if division[str(i)] != 0:
        ans += 1
        check = 0
min_ans = ans + check
max_ans = ans + division['8']
print(min_ans,max_ans)
# Judge status: Accepted
A = list(input()[::-1])
B = list(input()[::-1])
C = list(input()[::-1])
turn = 'a'
while True:
    if turn == 'a':
        if not A:
            print('A')
            break
        turn = A.pop()
    elif turn == 'b':
        if not B:
            print('B')
            break
        turn = B.pop()
    else:
        if not C:
            print('C')
            break
        turn = C.pop()
# Judge status: Wrong Answer
def main():
    N = int(input())
    csf = [list(map(int,input().split())) for _ in range(N-1)]
    for i in range(N-1):
        x = csf[i][0] + csf[i][1]
        for j in range(i+1,N-1):
            if x < csf[j][1]:
                x += csf[j][1] - x
            x += (x-csf[j][1])%csf[j][2] + csf[j][0]
        print(x)
        if i == N-2:
            print(0)

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = input()
ans = 0
for num in n:
    ans += int(num)
if ans == 1:
    ans = 10
print(ans)
# Judge status: Accepted
import string
# string.ascii_lowercase

N = int(input()) - 1
strs= [string.ascii_lowercase[N % 26]]

while(N >= 26):
    N //= 26
    N -= 1
    strs.append(string.ascii_lowercase[N % 26])

for s in strs[::-1]:
    print(s, end='')
print()
# Judge status: Accepted
from bisect import bisect_left
n,m = map(int, input().split())

l = [[] for _ in range(n)]
city = []
for i in range(m):
  p,y = map(int, input().split())
  city.append([p,y])
  l[p-1].append(y)

for i in l: i.sort()
for i in city:
  ans = ""
  ans += "0"*(6-len(str(i[0])))+str(i[0])
  t = str(bisect_left(l[i[0]-1], i[1]) + 1)
  ans += "0"*(6-len(t))+t
  print(ans)
# Judge status: Wrong Answer
n,d = map(int,input().split())
c = d*2+1
if n%c ==0:
    print(int(n//c))
else:
    print(int(n//d)+1)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
is_up=False
is_even=True
pre_a=a[0]
cnt=1
for aa in a:
  if is_even and pre_a != aa:
    is_even=False
    is_up=pre_a < aa
  if not is_even:
    if (is_up and pre_a > aa) or (not is_up and pre_a < aa):
      is_even=True
      cnt+=1
  pre_a=aa
print(cnt)
# Judge status: Wrong Answer
S = str(input())

while len(S) > 2:
  S = S[:-1]
  if len(S)%2 == 0:
    half = int(len(S)/2)
    if S[:half] == S[half:]:
      print(len(S))
# Judge status: Wrong Answer
n = int(input())
a_lst = [int(input()) for _ in range(n)]

button = a_lst[0]

cnt = 1 #必ずボタン1は押すため一回はカウント
ans = 0
for i in range(n):
    button = a_lst[button-1]
    if button == 2:
        ans = cnt + 1 #2と書かれたボタンを押す分の一回を追加
        break
    cnt += 1

if cnt == n+1 and ans == 0: #cntの初期値が1だからn+1
    print("-1")
else:
    print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
x_ls = list(map(int, input().split()))
ans = float('inf')
for i in range(n-k+1):
    if x_ls[i+k-1] < 0:
        ans = min(ans, abs(x_ls[i]))
    elif x_ls[i] < 0 and x_ls[i+k-1] >= 0:
        near = min(abs(x_ls[i]),abs(x_ls[i+k-1]))
        far = max(abs(x_ls[i]),abs(x_ls[i+k-1]))
        ans = min(ans, 2 * near + far)
    elif x_ls[i] >= 0:
        ans = min(ans, x_ls[i+k-1])
print(ans)
# Judge status: Accepted
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
sumA = 0
for ai in A:
    sumA = (sumA + ai) % MOD
ans = 0
for ai in A:
    sumA = sumA - ai
    ans = (ans + sumA * ai) % MOD

print(ans)
# Judge status: Wrong Answer
a = input()
b = []
for i in range(int(a[0])):
    b.append("".join(sorted(input())))
b.sort()
b = "".join(b)
print(b)
# Judge status: Wrong Answer
n = int(input())
s = input()

slist = []
sval = 0
for i in s :
    if i == "I":
        sval += 1
        slist.append(sval)
    else:
        sval -= 1
        slist.append(sval)
print(max(slist))
# Judge status: Accepted
import string
# print(string.ascii_uppercase)
# print(string.ascii_lowercase)
if input() in string.ascii_uppercase:
    print("A")
else:
    print("a")
# Judge status: Accepted
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))

def lcm(a,b):
    g=math.gcd(a,b)
    return b*(a//g)
l=a[0]//2
for i in range(n):
    r=a[i]//2
    l=lcm(l,r)
for i in range(n):
    if (l//(a[i]//2))%2==0:
        print(0)
        exit()
res=m//l
print((res+1)//2)
# Judge status: Accepted
a, v = list(map(int, input().split(' ')))
b, w = list(map(int, input().split(' ')))
t = int(input())

distance = b - a
relative_velocity = w - v
if relative_velocity > 0:
    print('NO')
else:
    if (abs(relative_velocity)*t >= abs(distance)):
        print('YES')
    else:
        print('NO')
# Judge status: Accepted
a,b,c=map(int,input().split())
d=0
if a%b!=0:
  d=1
print((d+a//b)*c)
# Judge status: Accepted
A, B, C = map(int, input().split())

print(min(B//A,C))
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

f = 0
for a in range(len(A)):
  if A[a] % 2 != 0:
    continue
  else:
    if A[a] % 3 != 0 and A[a] % 5 != 0:
      f = 1
      break
      
if f == 1:
  print('DENIED')
else:
  print('APPROVED')
# Judge status: Accepted
A = int(input())
B = int(input())

print(6 - A - B)
# Judge status: Accepted
S=int(input())
mod = 10**9 + 7
N = 2*S

factorial=[1 for i in range(N+1)]
for i in range(1,N+1):
    if i==1:factorial[i]=1
    else:factorial[i] = factorial[i-1]*i % mod
      
def comb(n,k):
    return (factorial[n]*pow(factorial[n-k]*factorial[k], -1, mod))%mod

ans = 0
for i in range(S//3):
  s = S - (i+1)*3
  ans += comb(s+i,i)
  ans %= mod
  
print(ans)
# Judge status: Accepted
a = input()
if a.islower():
    print("a")
else:
    print("A")
# Judge status: Accepted
N, K = map(int, input().split())
p = list(map(int, input().split()))
r = [0]*N
r[0] = (p[0] + 1) / 2
for i in range(1, N):
    r[i] = r[i-1] + (p[i] + 1) / 2
ans = r[K-1]
for i in range(K, N):
    ans = max(ans, r[i] - r[i - K])
print(ans)
# Judge status: Wrong Answer
S = [i for i in list(input())]
k = ['k', 'e', 'y', 'e', 'n', 'c', 'e'] + ['_']*100
N = len(S)
m = 0;c=0
flag=False
for i in S:
    if i == k[m]:
        m+=1
        if flag:
            flag = False
    else:
        if not flag: c+=1
        flag=True
# print(i, m, c)
if c<=1 and m==7: print('YES')
else: print('NO')
# Judge status: Accepted
from bisect import bisect_right

N, *A = map(int, open(0).read().split())

INF = 10 ** 10
dp = [INF] * N
for i in range(N):
    dp[bisect_right(dp, -A[i])] = -A[i]

print(max(i + 1 for i, v in enumerate(dp) if v < INF))
# Judge status: Wrong Answer
a, b = map(int, input().split())
print((b >= a) + max(((b - a) // (a - 1)), 0))
# Judge status: Wrong Answer
n = int(input())
a,b,c = [list(map(int,input().split())) for i in range(3)]
x = 0
d = -10
for i in range(n):
    x += b[a[i]-1]
    if i-1 == d:
        x+= c[d]
    if d != 0:
        d=i
print(x)
# Judge status: Accepted
S = input()
i = 0
while i < len(S):
    print('x', end='')
    i += 1
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = list(map(int, input().split()))
    B.append(b)
    C.append(c)

total = sum(A)

for i in range(Q):
    if(B[i] in A):
        count = A.count(B[i])

        d = C[i] - B[i]
        total += count * d
        print(total)

        A = [C[i] if x == B[i] else x for x in A]
# Judge status: Accepted
import sys

x = int(input())
flag = False
a = 0

while True:
    for b in range(-a+1,a):
        if  a ** 5 - b  ** 5 == x:
            print(a,int(b))
            sys.exit()
    a += 1
# Judge status: Wrong Answer
#!/usr/bin/env python3
# N = int(input())
# S = input()
P, Q, R = map(int, input().split())
# A = list(map(int, input().split()))

print(min(P + Q, R, P + R, Q + R, 2 * P + Q, 2 * Q + R))
# Judge status: Wrong Answer
n = int(input())
A = list(map(int, input().split()))

ca = [0]
for i in range(n):
    ca.append(A[i]+ca[i])

print(ca)
ans = 2020202020
for i in range(n):
    ans = min(ans, abs(ca[i]-(ca[-1]-ca[i])))

print(ans)
# Judge status: Wrong Answer
x = int(input())
if 360%x==0:
  print(360//x)
else:
  print(360)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
ai=a%2
b=b%2
c=c%2

if a==1:
    print('YES')
elif ai==0 and b==0 and c==1:
    print('NO')
elif ai==1 and b==0 and c==0:
    print('NO')
else:
    print('YES')
# Judge status: Accepted
K = int(input())
if K < 10:
	print(K)
	exit()
L = [1,2,3,4,5,6,7,8,9]
k = 9
i = 0
while k < K:
	l = L[i]
	a = l % 10
	if a > 0:
		L.append(l*10 + a - 1)
		k += 1
	L.append(l*10 + a)
	k += 1
	if a < 9:
		L.append(l*10 + a + 1)
		k += 1
	i += 1
print(L[K-1])
# Judge status: Accepted
N = int(input())
l = list(map(int,input().split()))

upper_ave = int(sum(l)/len(l)) + 1
lower_ave = int(sum(l)/len(l))

ans_1, ans_2 = 0, 0

for i in l:
    ans_1 += (i - upper_ave) ** 2
    ans_2 += (i - lower_ave) ** 2

print(min(ans_1,ans_2))
# Judge status: Wrong Answer
d=int(input())
for i in range(d): print(i+1)
# Judge status: Accepted
N, M = map(int, input().split())
AC = set()
wa = [0] * (N+1)

for _ in range(M):
    p, s = input().split()
    p = int(p)
    if not p in AC:
        if s == 'AC':
            AC.add(p)
        if s == 'WA':
            wa[p] += 1

wa_ans = 0
for i in range(1,N+1):
    if i in AC:
        wa_ans += wa[i]

print(len(AC), wa_ans)
# Judge status: Wrong Answer
n=int(input())
s=list(input())

num=0
for i in range(n):
    x=set(s[:n])
    y=set(s[n:])
    if len(x&y)>num:
        num=len(x&y)

print(num)
# Judge status: Wrong Answer
import bisect
import math
n,h = map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
	a[i],b[i] = map(int,input().split())
a.sort()
b.sort()
 
d = 0
for i in range(n-bisect.bisect_right(b,a[n-1])):
	d += b[n-1-i]
print(math.ceil((h-d)/a[n-1]) + n-bisect.bisect_right(b,a[n-1]))
# Judge status: Wrong Answer
a=list(map(int, input().split()))
a.sort()
print(10*a[0]+a[1]+a[2])
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

snk = A[0]
arg = sum(A)-snk
ans = abs(arg-snk)
for i in range(1, N-1):
  snk += A[i]
  arg -= A[i]
  dif = abs(arg-snk)
  ans = min(ans, dif)
print(ans)
# Judge status: Wrong Answer
N = input()
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

print(P,Q)
# Judge status: Accepted
n = int(input())
txy = []
for _ in range(n):
    t, x, y = map(int, input().split())
    txy.append((t, x, y))
px = py = pt = 0
for t, x, y in txy:
    m = abs(x-px)+abs(y-py)
    dt = t-pt
    if m>dt or (dt-m)%2==1:
        print('No')
        break
    px, py, pt = x, y, t
else:
    print('Yes')
# Judge status: Wrong Answer
n_list = list(input())
#print(n_list)

while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      flag = "ok"
      break
  if flag == "ng":
    break
#print(n_list)
print(len(n_list))
# Judge status: Wrong Answer
n,m=map(int,input().split())
if n==1:print(max(m-2,0))
elif m==1:print(max(n-2,0))
else:print((n-2)*(m-2))
# Judge status: Accepted
def main():
    N = input()
    A = list(map(int, input().split()))

    cnt = 0
    for i in range(len(A)):
        if A[i]!=i+1:
            cnt+=1

    if cnt == 0 or cnt ==2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()