peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
A=[tuple(map(int, input().split())) for _ in range(3)]
N=int(input())
B=[int(input())for _ in range(N)]
C=[[False]*3 for _ in range(3)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                C[i][j]=True
ans=False
for i in range(3):
    ans|=all(C[i][j] for j in range(3))
    ans|=all(C[j][i] for j in range(3))
ans|=all(C[j][j] for j in range(3))
print("YNeos"[not ans::2])
# Judge status: Wrong Answer
n,m=map(int,input().split())
g=[[] for i in range(n)]
for _ in range(m):
  u,v=map(int,input().split())
  g[u-1].append(v-1)
  g[v-1].append(u-1)
for x in g[0]:
  for y in g[x]:
    if y==n-1:
      print('POSSIBLE')
    else:
      print('IMPOSSIBLE')
# Judge status: Accepted
import numpy as np
n = int(input())
g = []
for _ in range(n):
  a, b = map(int, input().split())
  g.append([a,b])
g = np.array(g)
g = g[np.argsort(g[:, 1])]
a = 0
for i,j in g:
  a+=i
  if a>j:
    print('No')
    exit(0)
print('Yes')
# Judge status: Accepted
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
 

def maxProfit(prices) -> int:
    if len(prices) < 2:
        return 0
    ans = 1000
    for i in range(1,len(prices)):
        if prices[i] > prices[i - 1]:
            stock = ans // prices[i - 1]
            ans += stock * (prices[i] - prices[i - 1]) 
    return ans

def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]

    ans = maxProfit(A)
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
a=input()
b=''
for i in a:
    if i=='0':
        b+='0'
    elif i=='1':
        b+='0'
    else:
        b+=b[:-1]
print(b)
# Judge status: Wrong Answer
x = list(map(int, input().split()))

for i in range(4):
    if x[i] == 0:
        print(i + 1)
# Judge status: Wrong Answer
n,k=map(int,input().split())
if(n<k):
    print(1)
else:
    print(n%k)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())
print('Yes' if A <C<B else 'No')
# Judge status: Accepted
N = int(input())
ans = []
if N == 0:
  ans.append("0")
while N != 0:
  ans.append(str(N % 2))
  N = -(N // 2)
ans.reverse()
print("".join(ans))
# Judge status: Accepted
n=int(input())
d=dict()
a=0
for _ in range(n):
    s=''.join(sorted(input()))
    if s in d:
        a+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(a)
# Judge status: Accepted
n=int(input())
arr=[]
for i in range(n):
	arr.append(list(map(int,input().split())))
flag=0
for i in range(n-2):
	if(arr[i][0]==arr[i][1] and arr[i+1][0]==arr[i+1][1] and arr[i+2][0]==arr[i+2][1]):
		flag=1
		print("Yes")
		break
if(flag==0):
	print("No")
# Judge status: Accepted
a,b,x=map(int,input().split())
ax=(a-1)//x
bx=b//x
print(bx-ax)
# Judge status: Wrong Answer
s=input()
cnt=0
if s=='RRR':
  cnt = 3
elif s== 'RRS':
  cnt = 2
elif s== 'SRR':
  cnt = 2
elif s == 'RSS':
  cnt= 1
elif s == 'RSR':
  cnt=1
elif s=='SSR':
  cnt=1
print(cnt)
# Judge status: Wrong Answer
a, b, c, d = map(int, input().split())
print("Yes") if a+b>c+d else print("No")
# Judge status: Wrong Answer
K, X = map(int,input().split())

K = K*500
if(K >= X):
    print("yes")
else:
    print("No")
# Judge status: Accepted
a,b,c = map(int,input().split())
d = max(a,b,c)
e = min(a,b,c)
f = (a + b + c) - (d + e)
print(10 * d + e + f)
# Judge status: Accepted
h = int(input())
w = int(input())
n = int(input())

MAX = max(h, w)

if n % MAX == 0:
    print(n // MAX)
else:
    print(n // MAX + 1)
# Judge status: Accepted
n = int(input())
z = 1000000000
 
if n==z*z:
	print(z, 0, 0, z, 0, 0)
elif n > z:
    a = n//z
    b = n%z
    print(a+1, b, 0, z, 1, 0)
else:
    print(n, 0, 1, 1, 0, 0)
# Judge status: Accepted
a,b = map(int,input().split())
som = 1
cnt = 0
f = 0
while(som < b):
    som = som+a-1
    cnt = cnt+1
    if som >= b:
        f = 1
        break

print(cnt)
# Judge status: Accepted
N = int(input())
blocks = list(map(int, input().split()))
target = 1
for block in blocks:
  if block == target:
    target += 1
if target > 1:
  print(N-target+1)
else:
  print(-1)
# Judge status: Accepted
Q, H, S,D = map(int,input().split())
N=int(input())

L=min(4*Q, 2*H,S)
if 2*L<=D:
    ans=N*L
else:
    m=N//2
    ans=m*D+L*(N-2*m)
    
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
ans = 0
outlets = 1
while outlets < b:
    outlets -= 1
    outlets += a
    ans += 1
print(ans)
# Judge status: Accepted
A,B,C,D = map(int,input().split())

if -(-C//B) > -(-A//D):
    print("No")
else:
    print("Yes")
# Judge status: Accepted
import collections

count = collections.Counter
mod = 1000000007

def main():
    N = int(input())
    S = input()

    valuelist = list(count(S).values())
    ans = 1
    for v in valuelist:
        ans = (ans * (v + 1))%mod

    ans -= 1

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())
A = int(input())
if N%500 <= A:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N, M = map(int, input().split())
arr = sorted([list(map(int, input().split())) for _ in range(N)])

count = 0
money = 0
for list in arr:
    for i in range(list[1]):
        money += list[0]
        count += 1
        if count == M:
            print(money)
            exit()
# Judge status: Wrong Answer
A = list(map(int,input().split()))
print(A[2] - (A[0]-A[1]))
# Judge status: Accepted
from fractions import gcd
X, Y = map(int, input().split())
if (gcd(X, Y) == Y):
    print(-1)
else:
    print(X)
# Judge status: Accepted
from math import pi, atan

a, b, x = map(int, input().split())

if a**2 * b * 0.5 <= x:
    theta = atan(2 * (a**2 * b - x) / a**3)
else:
    theta = atan(a * b**2 * 0.5 / x)

print("{:.10f}".format(theta / pi * 180))
# Judge status: Accepted
n,m = map(int,input().split())
ans = 0

if n <= m//2:
    ans += n
    m -= 2*n
    ans += m//4
else:
    ans = m//2

print(ans)
# Judge status: Wrong Answer
x=int(input())
cnt=(x//11)*2
if x%11 >5:
    cnt+=2
elif 0< x%11 <=5:
    cnt+=1

print(cnt)
# Judge status: Accepted
A,B,C=map(int,input().split())
K=int(input())
flag=True
for i in range(K):
    if A>=B:
        B*=2
        continue
    if B>=C:
        C*=2
        continue
    if C>B and B>A:
        flag=False
        break
if C>B and B>A:
    flag=False
print('Yes' if flag==False else "No")
# Judge status: Accepted
S = input()
n = len(S)
a = [0]*(n+1)
for i in range(n):
    if S[i] == '<':
        a[i+1] = max(a[i+1], a[i] + 1)
for i in range(n)[::-1]:
    if S[i] == '>':
        a[i] = max(a[i], a[i+1] + 1)
# print(a)
print(sum(a))
# Judge status: Accepted
w,h,n=map(int,input().split())

A=[0,w,0,h]
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        A[0]=max(A[0],x)
    elif a==2:
        A[1]=min(A[1],x)
    elif a==3:
        A[2]=max(A[2],y)
    else:
        A[3]=min(A[3],y)

if (A[1]-A[0])<=0 or (A[3]-A[2])<=0:
    print(0)
else:
    print((A[1]-A[0])*(A[3]-A[2]))
# Judge status: Accepted
def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	if A.count(0) > 0:
		print(sum([abs(a) for a in A]))
		return 0
	minus = 0
	for i in range(len(A)):
		if A[i] < 0:
			minus += 1
	if minus % 2 == 0:
		print(sum([abs(a) for a in A]))
		return 0
	A.sort(key=lambda a: abs(a))
	print(sum([abs(a) for a in A[1:]]) - abs(A[0]))

main()
# Judge status: Accepted
import math
n,d = map(int,input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t+=(x[i][k]-x[j][k])**2 
        if math.sqrt(t)==int(math.sqrt(t)):
            ans += 1
print(ans)
# Judge status: Accepted
import sys
import math
import bisect

def solve(A):
    n = len(A)
    A.sort()
    l = (n - 1) // 2
    r = l + 1
    return A[r] - A[l]

def main():
    n = int(input())
    A = list(map(int, input().split()))
    print(solve(A))

if __name__ == "__main__":
    main()
# Judge status: Accepted
import collections

n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
for i in range(1,n+1):
    print(c[i])
# Judge status: Wrong Answer
n, k = map(int,input().split())
a = input().split()
ls = []
times = 1

for j in range(n-k):
    for i in range(j,j+k):
        times *= int(a[i])
    ls.append(times)
    times = 1
    i += 1

for x in range(len(ls)-1):
    if ls[x] < ls[x+1]:
        print('Yes')
    print('No')
# Judge status: Accepted
# coding: utf-8

S  = input()
print('2018' + S[4:])
# Judge status: Accepted
mat=[]
for i in range(3):
  array=list(map(int,input().split()))
  mat.append(array)
#print(mat)

diff_tate=[]
for i in range(2):
  diff_tate.append([mat[i][0]-mat[2][0],mat[i][1]-mat[2][1],mat[i][2]-mat[2][2]])
#print(diff_tate)

diff_yoko=[]
for i in range(2):
  diff_yoko.append([mat[0][i]-mat[0][2],mat[1][i]-mat[1][2],mat[2][i]-mat[2][2]])
#print(diff_yoko)

for diff in diff_tate+diff_yoko:
  dset=set(diff)
  if len(dset)>1:
    print("No")
    break
else:
  print("Yes")
# Judge status: Accepted
S = input()
count = 0
if 'R' in S:
    count = 1
if 'RR' in S:
    count = 2
if 'RRR' in S:
    count = 3
print(count)
# Judge status: Accepted
import sys, heapq, bisect, math, fractions
from collections import deque

N, D = map(int, input().split())

i = 0
res = 0
while i < N:
    res += 1
    i += 2 * D + 1

print(res)
# Judge status: Wrong Answer
a=sorted(input())
for i in range(4):
  if a.count(a[0]) <= 3:
    print('Yes')
    exit()
print('No')
# Judge status: Accepted
N = int(input())

ans = [0] * 10**4
for x in range(1, 110):
    for y in range(1, 110):
        for z in range(1, 110):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n <= 10**4:
                ans[n-1] += 1
                
for i in range(N):
    print(ans[i])
# Judge status: Accepted
from math import floor

def main():
    X=int(input())
    tmp=100
    for year in range(1,4000):
        tmp *= 1.01
        tmp = floor(tmp)
        if tmp >= X:
            print(year)
            exit()

main()
# Judge status: Wrong Answer
n=int(input())
li=[int(x) for x in input().split()]
d={}
for i in range(len(li)):
	if li[i] in d:
		d[li[i]]+=1
	else:
		d[li[i]]=1
c=0
for u,v in d.items():
	print(v)
	c+=1

while c<n:
	print(0)
	c+=1
# Judge status: Accepted
from heapq import *
N,M=map(int,input().split())
P=0
X=[[] for i in range(10**5+1)]
A,B=0,0
for i in range(N):
  A,B=map(int,input().split())
  if A>M:
    continue
  X[M-A].append(B)
Q=[]
heapify(Q)
for i in range(M-1,-1,-1):
  for j in range(len(X[i])):
    heappush(Q,-X[i][j])
  if len(Q):
    P-=heappop(Q)
print(P)
# Judge status: Accepted
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)
# Judge status: Accepted
a, b = list(map(int, input().split()))

if b < a:
    print(a-1)
else:
    print(a)
# Judge status: Wrong Answer
a=int(input())

print(int((a - 1) * a / 2))
# Judge status: Accepted
a, b = map(int, input().split())
ans = 0

if a == b or a < b:
    ans += 1

for i in range(1, a):
    ans += 1

print(ans)
# Judge status: Wrong Answer
from collections import deque

n = int(input())
a_L = list(map(int,input().split()))

ans = deque()

for i in range(0,n):
    if i %2 != 0:
        ans.appendleft(a_L[i])
    else:
        ans.append(a_L[i])

print(*ans)
# Judge status: Accepted
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    S = {
        'a': list(input()),
        'b': list(input()),
        'c': list(input())
    }
    turn = 'a'
    while S[turn]:
        turn = S[turn].pop(0)
    print(turn.upper())

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N=int(input())
H=list(map(int,input().split()))
base=0
for h in H:
    if base>h:
        print("No")
        break
    base=h-1
else:
    print("Yes")
# Judge status: Wrong Answer
data = int(input())
result = (data // 1000) * 2000
data %= 1000
result += (data // 5) * 5
print(result)
# Judge status: Accepted
def main():
  N, M = list(map(lambda a: int(a), input().split(" ")))

  if N >= M:
    print(0)
    return 0
  
  X = list(map(lambda x: int(x), input().split(" ")))
  X.sort()
  D = [X[i+1] - X[i] for i in range(len(X) - 1)]
  D.sort()
  print(sum(D[:M-N]))

main()
# Judge status: Accepted
x,k,d=map(int,input().split())
x=abs(x-0)
if (x-(k*d))>0:
    print((x-(k*d)))
else:
    k1=0
    k1=x//d
    k-=k1
    a=(x-(k1*d))
    if k%2==0:
        print(a)
    else:
        print(abs(a-d))
# Judge status: Accepted
x,a,b=map(int,input().split())
 
if b-a<=0:
  print('delicious')
elif b-a<=x:
  print('safe')
else:
  print('dangerous')
# Judge status: Accepted
n=int(input())
a_list=[int(i) for i in input().split()]
a_list.sort(reverse=True)
second_list=a_list[1:2*n:2]
print(sum(second_list))
# Judge status: Accepted
import math
def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,M = map(int,input().split())
count = 0
if N <= 1:
    a = 0
else:
    a = comb(N,2)

if M <= 1:
    b = 0
else:
    b = comb(M,2)
print(a+b)
# Judge status: Wrong Answer
line = int(input())
print(int((line * line * 3.14) // (1 * 1 * 3.14)))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

judge = 'equal'
cnt = 1
for i in range(n-1):
  if a[i] < a[i+1]:
    if judge == 'equal':
      judge = 'high'
    elif judge == 'low':
      judge = 'equal'
      cnt += 1
  elif a[i] > a[i+1]:
    if judge == 'equal':
      judge = 'low'
    elif judge == 'high':
      judge = 'equal'
      cnt += 1

      
print(cnt)
# Judge status: Accepted
# -*- coding: utf-8 -*-

def main():

    s = input()
    listS = list(s)
    n = len(listS)

    aIndex = 0
    zIndex = 0

    for i in range(n):
        if listS[i] == 'A':
            aIndex = i
            break

    for i in range(n):
        if listS[-(i + 1)] == 'Z':
            zIndex = n - i
            break

    ans = zIndex - aIndex

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
a,b,c,d = map(int,input().split())
ans = 0
ans += b // c - (a-1) // c
ans += b // d - (a-1) // d
l = lcm(c,d)
ans -= b // l - (a-1) // l
print(b-a+1-ans)
# Judge status: Wrong Answer
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()

ans = 1000000
for i in range(n-k+1):
    ans = min(ans, h[i+k-1] - h[i])
print(ans)
# Judge status: Wrong Answer
n, x, t = map(int, input().split())

if n % t == 0:
  ans = (n // x) * t
else:
  ans = (n // x + 1) * t

print(ans)
# Judge status: Wrong Answer
n,a,b  = map(int,input().split())
ans = 0
for i in range(1,n+1):
  d = i
  s=0
  while d:
    r = d %10
    d = int(d/10)
    s+=r
  if a<=s<=b:
    ans += 1
print(ans)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
for i in range(n):
	if b[i]-a[i]>=0:
		ans+=a[i]
		if (b[i]-a[i])-a[i+1]>=0:
			ans+=a[i+1]
			a[i+1]=0
		else:
			ans+=b[i]-a[i]
			a[i+1]-(b[i]-a[i])
	else:
		ans+=b[i]
print(ans)
# Judge status: Accepted
N = int(input()) 
DP = [10000000]*(2*N+1)
DP[0] = 0
for i in range(0, N+1):
  DP[i+1] = min(DP[i+1],DP[i]+1)
  s = 6
  while s <= N:
    DP[i + s] = min(DP[i + s],DP[i]+1) 
    s = s*6
  n = 9
  while n <= N:
    DP[i + n] = min(DP[i + n],DP[i]+1)  
    n = n*9
print(DP[N])
# Judge status: Accepted
s = input()
t = input()

ans = float("inf")

for i in range(len(s) - len(t) + 1):
    num = 0
    for j in range(len(t)):
        if s[i + j] == t[j]:
            continue
        else:
            num += 1

    ans = min(ans, num)

print(ans)
# Judge status: Wrong Answer
N=str(input())
if N[0]==9 or N[1]==9:
  print('Yes')
else:
  print('NO')
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
ruiseki_WA=[0]
for i in range(n):
    ruiseki_WA.append(ruiseki_WA[i]+a[i])
ans=float("inf")
for i in range(n):
    kari=abs(ruiseki_WA[i]-(ruiseki_WA[-1]-ruiseki_WA[i]))
    ans=min(ans,kari)
print(ans)
# Judge status: Accepted
D = 10 ** 9 + 7
N = int(input())
L= list(map(int, input().split()))

ans = L[0] * L[1] % D
sub = L[0] + L[1]
for n in range(2,N):
    ans += L[n] * sub
    sub += L[n]
    
print(ans % D)
# Judge status: Wrong Answer
import math

def colcu (bli,ali,D):
    num = 0
    for i in range(D):
        num += (bli[i] - ali[i]) ** 2
    return math.sqrt(num)

N,D = map(int, input().split())
pli = []
for i in range(N):
  pli.append(list(map(int, input().split())))

an = 0
for i in range(N-1):
 for t in range(i+1,N):
     if colcu(pli[i],pli[t],D).is_integer():
         an += 1
     print(colcu(pli[i],pli[t],D))
print(an)
# Judge status: Wrong Answer
x=int(input())
if x==7 or x==5 or x==3:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import math

n,k = map(int, input().split())

p = 0
if (n-(k-1) >= 1):
    p += (n-(k-1))/n
    for i in range(1, k):
        a = math.ceil(math.log2(k/i))
        p += (1/n) * ((1/2)**a)
else:
    for i in range(1, n+1):
        a = math.ceil(math.log2(k/i))
        p += (1/n) * ((1/2)**a)
    
print(p)
# Judge status: Accepted
a,b,c = map(int,input().split())
k = int(input())

for l in range(1,k+1):
  for i in range(l+1):
    for j in range(l+1-i):
      for k in range(l+1-i-j):
        if b*pow(2,j) > a*pow(2,i) and c*pow(2,k) > b*pow(2,j):
          print('Yes')
          exit()
print('No')
# Judge status: Accepted
import sys
input = sys.stdin.readline

N = int(input())
XL = []
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    XL.append(tmp)
LR = []
for i in XL:
    LR.append([i[0] - i[1], i[0] + i[1]])
LR.sort()
ans = N
last = LR[0][1]
for i in range(1, N):
    if last > LR[i][0]:
        if last > LR[i][1]:
            last = LR[i][1]
        ans -= 1
    else:
        last = LR[i][1]
print(ans)
# Judge status: Wrong Answer
def prime(p):
    memo = []
    for i in range(2,(int(p**0.5)+1)):
        jousu = 1
        while p%(i**jousu)==0:
            p //= i**jousu
            memo.append(i**jousu)
            jousu += 1
    if p == n and n != 1:
        memo.append(p)
    return memo
 
n=int(input())
 
memo = prime(n)

if len(memo) == 0:
  print(0)
else: 
  print(len(memo))
# Judge status: Wrong Answer
n, *l = map(int, open(0).read().split())

a = 1
for i in l:
	a *= i
	if a > 1e18:
		a = -1
		break
print(a)
# Judge status: Wrong Answer
x, y ,z = map(int, input().split())
print(int(0.5*x**y))
# Judge status: Wrong Answer
L, R, d = list(map(int, input().split()))
print(R//d - L//d)
# Judge status: Accepted
import math

N, D = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
  dist = L[i][0] ** 2 + L[i][1] ** 2
  if math.sqrt(dist) <= D:
    ans += 1

print(ans)
# Judge status: Accepted
s=input()
t=input()
n=len(s)

for i in range(n):
  if t==s[i:]+s[:i]:
    print("Yes")
    exit()
print("No")
# Judge status: Wrong Answer
import sys
MOD = 10**9 + 7
n, m = map(int, input().split())
a = [int(x) for x in sys.stdin.readlines()]
p1, p2 = 0, 0
if 1 not in a:
    p1, p2 = 0, 1
if 2 not in a and n >=2:
    p1, p2 = p2, p2 + 1

for i in range(2, n):
    if i+1 not in a:
        p1, p2 = p2, (p2 + p1)%MOD
    else:
        p1, p2 = p2, 0
print(p2)
# Judge status: Accepted
n_plus, n_zero, n_minus, n_cards = map(int, input().split())

if n_cards <= n_plus:
  print(min(n_plus, n_cards))
elif n_cards <= (n_plus + n_zero):
  print(n_plus)
else:
  print(n_plus - (n_cards - n_plus - n_zero))
# Judge status: Accepted
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_win = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_win//2))

print(-sum(a))
# Judge status: Accepted
N = int(input())

A = 0
W = 0
T = 0
R = 0
for i in range(N):
    word = input()
    if ("AC" == word):
        A += 1
    elif ("WA" == word):
        W += 1
    elif ("TLE" == word):
        T += 1
    else:
        R += 1

print("AC x " + str(A))
print("WA x " + str(W))
print("TLE x " + str(T))
print("RE x " + str(R))
# Judge status: Accepted
N = int(input())
B = [int(i) for i in input().split(' ')]
A = [0]*(N)
for i,a in enumerate(B):
    if i == 0: #index最初
        A[i] = a
        A[i+1] = a
    else:#二番目以降
        if B[i-1] < B[i]:
            A[i+1] = a
        else:
            A[i] = a
            A[i+1] = a

print(sum(A))
# Judge status: Wrong Answer
N=int(input())
n=[str(input()) for i in range(N)]
M=int(input())
m=[str(input()) for i in range(M)]
for i in range(N):
  print(max(0, n.count(n[i])-m.count(n[i])))
# Judge status: Accepted
import sys

cand = [7, 5, 3]

x = int(sys.stdin.readline().rstrip())

def main():
    return 'YES' if x in cand else 'NO'

if __name__ == '__main__':
    ans = main()
    print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
p=list(map(int,input().split()))
s=[0]*(n+1)
for i in range(n):
    x=p[i]
    s[i+1]=(x+1)/2+s[i]
ans=0
for i in range(k,n+1):
    ans=max(ans,s[i]-s[i-k])
print(ans)
# Judge status: Wrong Answer
import itertools
N = int(input())
S = input()
#Rc1,Gc1,Bc1
out = S.count('R') * S.count('G') * S.count('B')
print(out)

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))

for i in range(1, N):
  for j in range(N-i*2):
    #三つ連続であり、RGBで構成されている
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)
# Judge status: Wrong Answer
d,t,s = map(int,input().split())
if (d / s) <= t:
  print("yes")
else:
  print("no")
# Judge status: Accepted
a, b, c = map(int, input().split())

sum_out = 0

for i in range(1, a+1):
    d = str(i)
    keta = len(d)

    sum_a = 0
    for j in range(keta):
        sum_a += int(d[j])

    if b <= sum_a & sum_a <= c:
        sum_out += i

print(sum_out)
# Judge status: Accepted
N,M = map(int, input().split())

H=list(map(int,input().split()))

graph=[[0] for _ in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    graph[A-1].append(H[B-1])
    graph[B-1].append(H[A-1])

ans=0

for i in range(N):
    if H[i]>max(graph[i]):
        ans+=1
        
print(ans)
# Judge status: Wrong Answer
O = input()
E = input()
for o, e in zip(O, E):
    print(o,e, sep='', end='')
# Judge status: Accepted
a,b,c=input().split()
print(a[0],b[0],c[0],sep="")
# Judge status: Accepted
n = int(input())
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
result = 0
for i in range(n):
  if a[i] > b[i]:
    result += b[i]
    b[i] = 0
  else:
    result += a[i]
    b[i] -= a[i]
    if a[i + 1] > b[i]:
      result += b[i]
      a[i + 1] -= b[i]
    else:
      result += a[i + 1]
      a[i + 1] = 0
print(result)
# Judge status: Accepted
x = int(input())
if x == 2:
    print(1, -1)
    exit(0)
for d in range(1, int(x ** 0.5) + 1):
    for w in [-d, -x // d, d, x // d]:
        for a in range(-1000, 1000):
            if a ** 5 - (a - w) ** 5 == x:
                print(a, a - w)
                exit(0)
# Judge status: Accepted
H,N=map(int,input().split())
a=list(map(int,input().split()))
if H>sum(a):
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline  #文字列入力では注意！

N,W = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    w,v = map(int,input().split())
    for j in range(W+1):
        if j+w <= W:
            dp[i+1][j+w] = dp[i][j]+v
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
print(dp)
print(dp[N][W])
# Judge status: Accepted
n, p, *a = map(int, open(0).read().split())
print([[2**n, 0][p], 2**~-n][sum(i%2 for i in a)>0])
# Judge status: Accepted
from collections import deque
k = int(input())


def generate_lunlun(x):
    d = int(x) % 10
    if d != 0:
        yield x+str(d-1)
    yield x+str(d)
    if d != 9:
        yield x+str(d+1)


d = deque([str(i) for i in range(1, 10)])
for _ in range(k):
    x = d.popleft()
    for y in generate_lunlun(x):
        d.append(y)
print(x)