peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

INF = float('inf')
abs_min = INF
neg_cnt = 0
res = 0

for i in range(N):
    if A[i] < 0:
        neg_cnt += 1
    abs_min = min(abs_min, abs(A[i]))
    res += abs(A[i])

if neg_cnt % 2:
    res -= 2 * abs_min

print(res)
# Judge status: Wrong Answer
import sys


def check(S, T):
    count = 0
    for s, t in zip(S, T):
        if s != t:
            count += 1
    return count


def main():
    S = input()
    T = input()
    dif = len(S) - len(T)
    ans = 10000
    for i in range(dif):
        compare = S[i: i+len(T)]
        count = check(compare, T)
        if count < ans:
            ans = count

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = input().rstrip()

    M = len(N)

    tot = 0

    for i in range(M):
        tot += int(N[i])
        tot %= 9

    if tot == 0:
        res = 'Yes'
    else:
        res = 'No'

    print(res)



main()
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))

i = 1
j = 0

if not 1 in set(a):
    print(-1)

while j < N and i in set(a[j:]):
    j = a[j:].index(i) + j
    # print(i, j)
    i += 1

print(N - i + 1)
# Judge status: Wrong Answer
n, k = map(int, input().split())

dig = 0
while True:
  if n > pow(k,dig):
    dig += 1
  else:
    break
print(dig)
# Judge status: Accepted
from collections import defaultdict

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

li_count = defaultdict(int)

# 要素ごとの出現数を記録
for a in li:
    li_count[a] += 1

max_x_count = 0

for x in range(1, 10**5):
    # xにできるやつ
    x_count = li_count[x-1] + li_count[x] + li_count[x+1]
    max_x_count = max(max_x_count, x_count)
print(max_x_count)
# Judge status: Wrong Answer
s = list(set(input()))
l = [["N","S"], ["W","E"], ["N", "S", "W", "E"]]
for i in l:
    x = 0
    for j in s:
        if j in i:
            x += 1
    if x == len(s):
        print("Yes")
        exit()
print("No")
# Judge status: Accepted
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX = max(A)
    dp = [True] * (MAX+1)
    A.sort()
    cnt = Counter(A)
    ans = 0
    for a in A:
        if dp[a]:
            if cnt[a] == 1:
                ans += 1
            x = a
            while x <= MAX:
                dp[x] = False
                x += a
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n=int(input())
a=[list(map(int, input().split())) for _ in range(2)]
ans=0
s=a[0][0]+sum(a[1])
for i in range(1, n):
  s=s+a[0][i]-a[1][i-1]
  if s>ans:
    ans=s
print(ans)
# Judge status: Accepted
s = str(input())
n = len(s)
x = [0]*2019
x[0] = 1
m = 0
j = 1
for i in range(n):
  m = (m + int(s[-i-1])*j)%2019
  x[m] += 1
  j = (j*10)%2019
ans = 0
for i in range(2019):
  ans += (x[i]*(x[i]-1))//2
print(ans)
# Judge status: Accepted
from math import factorial    #階乗計算
#print(math.factorial(5))   ->   120

N, M = map(int, input().split())
mod = 10**9+7

if abs(N-M)>=2:
    print(0)
    exit()

n = factorial(N)%mod
m = factorial(M)%mod
ans = n*m%mod

if N==M:
    print(ans*2%mod)
else:
    print(ans)
# Judge status: Accepted
C1=input()
C2=input()
C1new="".join(list(reversed(C1)))
C2new="".join(list(reversed(C2)))
if (C1==C2new)&(C2==C1new):
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer

n=int(input())
a = list(map(int, input().split()))
an=0
for i in range(n-1):
    s=a[i]
    for j in range(s+i+1,n):
        if a[j]==s:
            an+=1
print(an)
# Judge status: Wrong Answer
N = int(input())

ans = 0
while ans < 111:
    ans += 111
print(ans)
# Judge status: Accepted
import math
count = 0
amari = 10
for i in range(5):
  n = int(input())
  if n%10 == 0:
    count += n
  else:
    count += math.ceil(n/10)*10
    amari = min(amari,n%10)
if amari %10 == 0:
  print(count + amari - 10) 
else:
  print(count + amari -10)
# Judge status: Accepted
k,s = map(int,input().split())
ans = 0

for x in range(min(k,s)+1):
    for y in range(min(k,s)+1):
        if 0 <= s - x - y <= min(k,s):
            ans += 1
    
print(ans)
# Judge status: Wrong Answer
n = int(input())
num_list = list(map(int,input().split()))
sum_cnt = sum(num_list)
sunuke = 0
arai = 0
tmp = 0
for i in range(len(num_list)-1):
    if i == 0:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
    else:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        if tmp - abs(arai - sunuke) <= 0:
            break
        else:
            tmp = abs(arai - sunuke)
print(tmp)
# Judge status: Accepted
S = {}
S["a"] = [c for c in input()]
S["b"] = [c for c in input()]
S["c"] = [c for c in input()]
p = "a"

while True:
    if len(S[p]) == 0:
        print(p.capitalize())
        break

    p = S[p].pop(0)
# Judge status: Accepted
n = int(input())

pf={}
m=n
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

ans = 0

for i in pf.items():
    m = i[1]

    a = 1
    cnt = 1

    while a <= m:
        cnt += 1
        a += cnt
    
    cnt -= 1

    ans += cnt

print(ans)
# Judge status: Wrong Answer
X = int(input())
tf=True
if X == 2:
  print(X)
  exit(0)
  
while tf:
    if X % 2 == 0:
        X+=1
    else:
        for i in range(1,X):
            if X % i == 0:
                X += 1
            else:
                tf = False
print(X)
# Judge status: Wrong Answer
'''input
3
28 27 24
'''
n = input()
a = map(int, input().split())

ok = 0
for i in a:
	if i % 2 == 0:
		if i % 3 != 0 and i % 5 != 0:
			ok = 0

if ok == 1:
	print("APPROVED")
else:
	print("DENIED")
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
re = 0
re2 = 0

for i in range(n):
    re = a[i]*sum(a[i+1:])
    #for m in range(n-i-1):
        #re = a[i]*a[i+m+1]
        #re2 += re

ans = re %1000000007
print(ans)
# Judge status: Accepted
import sys

X, Y = [int(n) for n in input().split()]

for a in range(101):
    for b in range(101):
        if a + b == X and 2*a + 4*b == Y:
            print('Yes')
            sys.exit(0)

print('No')
# Judge status: Accepted
n, x = map(int, input().split())
a = list(map(int, input().split()))
t = a[0] - min(a[0], x)
a[0] -= t
for i in range(1, n):
    if a[i] + a[i - 1] > x:
        diff = (a[i] + a[i - 1]) - x
        t += diff
        a[i] -= diff
print(t)
# Judge status: Accepted
N = int(input())
List = []
for c in range(100//4 + 1):
  for d in range((100-4*c)//7 + 1):
    if 4*c + 7*d == N:
      List.append(c+d)
    else:
      continue
if bool(List) == True:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))

if len(A) == len(set(A)):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
W, a, b = map(int, input().split())

if a+W < b:
    print(b-a-W)
elif b+W < a:
    print(a-b-W)
else:
    print(0)
# Judge status: Accepted
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
suma = sum(a)
counter = Counter(a)
for i in range(q):
    suma -= bc[i][0] * counter[bc[i][0]]
    suma += bc[i][1] * counter[bc[i][0]]
    counter[bc[i][1]] += counter[bc[i][0]]
    counter[bc[i][0]] = 0
    print(suma)
# Judge status: Accepted
a,b,c,d = map(int,input().split())
ans = min(b,d) - max(a,c)
if ans < 0: print(0)
else: print(ans)
# Judge status: Wrong Answer
a,b = map(int,input().split())
print(a + b / 2)
# Judge status: Wrong Answer
N, Y = [int(_) for _ in input().split()]
x = 0
y = 0
z = 0
isOK = False


def sumMoney(x, y, z):
    return x*10000+y*5000+z*1000


for z in range(N):
    for y in range(N-z):
        x = N-z-y
        if sumMoney(x, y, z) == Y:
            print(x, y, z)
            isOK = True
            break
    if isOK:
        break


if not isOK:
    print(-1, -1, -1)
# Judge status: Wrong Answer
# input
A1, A2, A3 = map(int, input().split())

if sum([A1, A2, A3]) <= 22:
    print("bust")
else:
    print("win")
# Judge status: Wrong Answer
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

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

tmp =[]
for i in list(n):
    ni = int(i)
    while True:
        if ni in d:
            ni += 1
        else:
            tmp.append(ni)
            break

print("".join(list(map(str,tmp))))
# Judge status: Accepted
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

ans = 0
best = 10**7
for i in range(N):
  temp = T - 0.006*H[i]
  if abs(temp - A) < best:
    best = abs(temp - A)
    ans = i+1
    
print(ans)
# Judge status: Accepted
import math
N, D = map(int, input().split())
D = (D*2)+1
print(math.ceil(N/D))
# Judge status: Wrong Answer
#116A
# 1.値を正しく取得
a, b, c = (int(x) for x in input().split())

# 2.正しく処理
menseki = a * b / 2

print(menseki)
# Judge status: Accepted
n = int(input())
s = input()
t = input()

cnt = 0
for i in range(n):
  for j in range(n-i):
    if not s[i+j] == t[j]:
      break
  else:
    print(i+n)
    exit()

else:
  print(2*n)
# Judge status: Wrong Answer
def myAnswer(X:int)-> int:
   if(X < 100) : return 0
   total = 0
   first = X % 10**(len(str(X)) - 2)
   secand = X % 10**(len(str(X)) - 1) - first
   if(first <=5 and first >=0):
      total += 100+first
   else:
      total += 200 + first
   total += (secand//5)*105
   return 1 if(total <= X) else 0



def modelAnswer():
   tmp=1
def main():
   X = int(input())
   print(myAnswer(X))

if __name__ == '__main__':
   main()
# Judge status: Accepted
import sys

N = int(sys.stdin.readline())

stations = []
for _ in range(N-1):
    c, s, f = map(int, sys.stdin.readline().split())
    stations.append((c, s, f))

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        c, s, f = stations[j]
        if t <= s:
            t = s + c
        else:
            tmp = t - s
            t = s + f * ((tmp - 1) // f + 1) + c

    print(t)
print(0)
# Judge status: Accepted
#A
R = int(input())
print(2*R*3.141592)
# Judge status: Accepted
import numpy as np


def main():
    S = int(input())
    MOD = 10**9 + 7

    dp = np.zeros((S+1,), dtype=int)
    dp[3:] = 1

    for i in range(3, S):
        for j in range(3, S-i+1):
            dp[i+j] += dp[i]
            dp[i+j] %= MOD
    print(dp[S])


if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
r = 0
l = sum(A)
ans = 10**20
for a in A[:-1]:
    r += a
    l -= a
    if ans > abs(r-l):
        ans = abs(r-l)
print(ans)
# Judge status: Accepted
N, K, Q = map(int,input().split())
A = [int(input())-1 for i in range(Q)]
S = [0]*N
for i in range(Q):
  S[A[i]] += 1
ans = [K]*N
for i in range(N):
  ans[i] -= (Q-S[i])
for a in ans:
  if a > 0:
    print("Yes")
  else:
    print("No")
# Judge status: Accepted
import sys
input=sys.stdin.readline
n,hp=map(int,input().split())
ata,sute=zip(*[tuple(map(int,input().split())) for i in range(n)])
ata=max(ata)
sute=sorted(list(sute),reverse=1)

ans=float("inf")
for i in range(n):
    hp-=sute[i]
    ans=min(ans,-(-max(0,hp)//ata)+i+1)
print(ans)
# Judge status: Accepted
# coding: utf-8
# Your code here!
import math
from decimal import *
getcontext().prec = 70

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


if N<= K:
    print(min(N,K-N))
else:

    N = N - math.floor(Decimal(N)/Decimal(K))*K 
    print(min(N, K-N))
# Judge status: Accepted
import sys

def solve():
    s = input()
    t = input()
    x = len(s)
    for i in range(x):
        s = s[x - 1] + s[:x - 1]
        if s == t:
            print("Yes")
            break
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()
# Judge status: Accepted
N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

if N%K==0:
    print('0')
else:
    print('1')
# Judge status: Accepted
a,b,c=map(int,input().split())
l=[a,b,c]
l=sorted(l)
print(l[0]+l[1])
# Judge status: Accepted
def main():
  N, M = (int(_) for _ in input().split())
  ret = min(M // 2, N)
  M = M - 2 * ret
  ret += M // 4
  print(ret)

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
n = int(input())
x = [list(map(int,input().split())) for i in range(n)]

count=0
for i in x:
    if count==3:
        print("Yes")
        break
    elif i[0]==i[1]:
        count+=1
    else:
        count=0
else:
    print("No")
# Judge status: Accepted
N = int(input())
A, B = [],[]
for _ in range(N):
	ta,tb = map(int, input().split())
	A.append(ta)
	B.append(tb)

A = A[::-1]
B = B[::-1]

ans = 0
for i in range(N):
	A[i] += ans
	ans += -A[i] % B[i]

print(ans)
# Judge status: Accepted
N=int(input())
*A,=map(int,input().split())

from collections import*
C=Counter(A)
ans=0
for k,v in zip(C.keys(),C.values()):
    if k<=v:
        ans+=v-k
    else:
        ans+=v

print(ans)
# Judge status: Accepted
import decimal
a,b = input().split()
c = decimal.Decimal(a)
d = decimal.Decimal(b)
#print(c,d)
#rint(c*d)
print(int(c*d))
# Judge status: Accepted
x=int(input())
y=int((x**0.5)//1)
for i in range(y,y+x):
    if (i+1)*i//2>=x:
        print(i)
        exit()
# Judge status: Accepted
n,c,k = map(int,input().split())
t = [0]*n
for i in range(n):
    t[i] = int(input())
t.sort()
ind = 0
ans = 0
bus = 0
while ind <= n-1:
    bus += 1
    ind_o = ind
    for i in range(c):
        if ind_o+i > n-1:
            ind_o += i-1
            break
        if t[ind_o+i] > t[ind_o]+k:
            break
        else:
            ind += 1
print(bus)
# Judge status: Accepted
def main():
    S = input()
    if (S.count("N") >= 1 and S.count("S") >= 1 and S.count("E") == 0 and S.count("W") == 0)\
       or (S.count("N") == 0 and S.count("S") == 0 and S.count("E") >= 1 and S.count("W") >= 1)\
       or (S.count("N") >= 1 and S.count("S") >= 1 and S.count("E") >= 1 and S.count("W") >= 1):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n,d=map(int,input().split())

if d%2==0: 
    print(n//(d*2)+1)
    
else:
    print(n//(2*d+1))
# Judge status: Accepted
s = str(input())
nickname = s[0:3]
print(nickname)
# Judge status: Wrong Answer
n=int(input())
list=input().split()
for f in list:
    f=int(f)
count=0
c=0
for i in range(n-2):
    count=count+1
    if list[count]<list[count+1] and list[count]>list[count-1]:
        c=c+1
    elif list[count]>list[count+1] and list[count]<list[count-1]:
        c=c+1
print(c)
# Judge status: Wrong Answer
N,M = map(int,input().split())
A=list(map(int,input().split()))

if N-sum(A) >0:
    print(N-sum(A))
else:
    print(-1)
# Judge status: Wrong Answer
k=list(map(str,input().split()))
k.sort()
l=str(k[0]+k[1])
print(int(l)+int(k[2]))
# Judge status: Accepted
import math
x = int(input())
if x == 6 or (x-6)%11 == 0:
  x -= 1  
print(math.ceil(x/5.5))
# Judge status: Accepted
N = int(input())
dp = [[0 for i in range(3)] for j in range(N+1)]

for i in range(1, N+1):
    hapiness = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i-1][k] + hapiness[k])

print(max(dp[N][0], dp[N][1], dp[N][2]))
# Judge status: Accepted
import sys
def S(): return sys.stdin.readline().rstrip()
print(S().replace('?','D'))
# Judge status: Wrong Answer
N, X = map(int, input().split())
Xs = [int(i) for i in input().split()]

Xs.append(X)
dist = sorted(Xs)

diff = 10 ** 9
for i in range(1, len(dist)):
    tmp = dist[i] - dist[i-1]
    if tmp < diff:
        diff = tmp

print(diff)
# Judge status: Accepted
ABC = list(map(int,input().split()))
count = 0
while True:
    ABC = list(sorted(ABC))
    if ABC[0] +2 <= ABC[2]:
        ABC[0] += 2
        count += 1
    elif ABC[0] < ABC[2]:
        ABC[0] += 1
        ABC[1] += 1
        count += 1
    if max(ABC) == min(ABC):
        break
print(count)
# Judge status: Accepted
n = input()
a = [int(num) for num in input().split(" ")]

mod_value = 10**9 + 7

sum = 0
total = 0
for i in reversed(range(1, len(a))):
    sum += a[i]
    total += a[i-1] * sum

print(total%mod_value)
# Judge status: Accepted
import sys
input = sys.stdin.readline
import math
a, b, h, m = map(int,input().split())
c = ((h%12) * 60 + m) / (60 * 12)
d = m / 60
t = abs(c-d) * 2 * math.pi
# print(t)
print((a**2 + b**2 - 2*a*b*math.cos(t)) ** 0.5)
# Judge status: Accepted
N, A, B = map(int,input().split())
ans = (N // (A+B)) * A
N = N % (A+B)
ans += min(A,N)
print (ans)
# Judge status: Wrong Answer
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

s = k()
q = s//(mod-7)
r = s%(mod-7)

print(0,0,10**9,1,10**9-r,q+1)
# Judge status: Accepted
n,x = map(int, input().split())
a = [int(t) for t in input().split()]

ans = 0

for i in range(1,n):
    res = x
    if a[i-1] + a[i] > x:
        ans += a[i-1]+a[i] - x
        a[i] = max(x-a[i-1],0)
        if a[i] == 0:
            res -= a[i]
            a[i-1] -= res

print(ans)
# Judge status: Accepted
n, k = map(int, input().split())
xx = tuple(map(int, input().split()))

ans = 10 ** 9
for i in range(n - k + 1):
    if xx[i + k - 1] <= 0:
        ans = min(ans, -xx[i])
    elif xx[i] >= 0:
        ans = min(ans, xx[i + k - 1])
    else: #if xx[i] <= 0 and xx[i + k - 1] >= 0:
        ans = min(
            ans,
            -xx[i] * 2 + xx[i + k - 1],
            -xx[i] + 2 * xx[i + k - 1]
        )
print(ans)
# Judge status: Accepted
N,M = map(int, input().split())
if N==M==1:
    print(1)
elif N == 1 or M == 1:
    print(max(N,M)-2)
else:
    print((N-2) * (M-2))
# Judge status: Wrong Answer
x=int(input())
count=0
hap=list(map(int,input().split()))
count=max(hap)
k=hap.index(count)
for _ in range(1,x):
    hap=list(map(int,input().split()))
    m=-1
    for j in range(len(hap)):
        if j!=k:
            if hap[j]>m:
                m=hap[j]
                ano=j
    count+=m
    k=ano
print(count)
# Judge status: Wrong Answer
def main():
    N, A, B = map(int, input().split())
    if A % 2 == B % 2:
        return abs(A - B)//2
    else:
        x = A + (B - A - 1)//2
        y = (N - B + 1) + (- A + B + 1)//2
        return min(x, y)

print(main())
# Judge status: Accepted
import sys

a, b, c = map(int, sys.stdin.readline().split())
if (c-(a+b))>0 and (a**2 + b**2 + c**2) > 2*(a*b + b*c + c*a):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
A,B,C,X,Y,=map(int,input().split())
ans=10000000000000
for i in range(0,max(X,Y)+1):
    ans=min(ans,2*i*C+max(0,X-i)*A+max(0,Y-i)*B)
print(ans)
# Judge status: Wrong Answer
def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return chr(64+num%26)
      
b = int(input())
a = input()
lista = list(a)

for i in range(len(lista)):
  tmp = alpha2num(lista[i])
  tmp += b
  lista[i] = num2alpha(tmp)
  
print(''.join(lista))
# Judge status: Wrong Answer
# coding:utf-8
n = int(input())
s = [int(input()) for _ in range(n)]
ans = sum(s)

if sum(s) % 10 != 0:
    print(ans)
    exit()
else:
    s.sort()
    for item in s:
        ans -= item
        if ans % 10 != 0:
            break
print(ans)
# Judge status: Accepted
n = int(input())
s = input()

if n % 2 == 1:
    print("No")
else:
    t = s[:n//2]
    if t * 2 == s:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n=int(input())
ans=1
if n%11>6:
  ans+=1
k=n//11
if (k+1)*11<=n:
  k+=1
if n%11==0:
  print(2*k)
else:
  print(2*k+ans)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
hashmap = {}
for a in A:
    if a not in hashmap:
        hashmap[a] = 0
    hashmap[a]+=1

len1 = 0
len2 = 0

for k,v in hashmap.items():
    if v>=4:
        len1, len2 = max(len1,k), max(len2,k)
    elif v>=2:
        if len1<k:
            len1, len2 = k, len1
        else:
            len2 = max(len2,k)
print(len1*len2)
# Judge status: Accepted
N, M = list(map(int, input().split()))
height_list = list(map(int, input().split()))
tenbo_list = []

count = 0

for n in range(N):
    tenbo_list.append([])

for n in range(M):
    A, B = list(map(int, input().split()))
    tenbo_list[A-1].append(B-1)
    tenbo_list[B-1].append(A-1)

ite = 0
for t in tenbo_list:
    count += 1
    for a in t:
        if height_list[a] >= height_list[ite]:
            count -= 1
            break
    ite += 1

print(count)
# Judge status: Accepted
N=int(input())
S=input()

numb=[0]
numw=[0]
cond="b"
for i in range(N):
    numb.append(numb[-1])
    numw.append(numw[-1])
    if S[i]=="#":
        numb[-1]+=1
    else:
        numw[-1]+=1

ans=[0 for _ in range(N+1)]
for j in range(N+1):
    ans[j]=numb[j]+(numw[-1]-numw[j])
print(min(ans))
# Judge status: Accepted
a,b,c=sorted(list(map(int, input().split())))
print("Yes" if (a==b and b!=c) or (a!=b and b==c) else "No")
# Judge status: Accepted
import numpy as np
N = int(input())
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
temp = np.median(X,axis=0)
if N % 2 == 1:
    print(int(temp[1]-temp[0]+1))
else:
    print(int(2*temp[1]-2*temp[0]+1))
# Judge status: Accepted
N = int(input())
X = list(map(int, input().split()))

ans = float('inf')
for i in range(1, 101):
    ans_i = 0
    for j in range(N):
        ans_i += (X[j] - i) ** 2
    ans = min(ans, ans_i)
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if a < 10 and b < 10:
  print(a*b)
else:
  print(-1)
# Judge status: Wrong Answer
numbers = input()
print(numbers)
if int(numbers) == 0: 
    print(0)
elif int(numbers) == 111:
    print(3)
elif int(numbers) == 101 or int(numbers) == 110 or int(numbers) == 11:
    print(2)
else:
    print(1)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
ans = [0]*n
for i in range(n):
  ans[a[i]-1] = i+1

print(*ans,sep=' ')
# Judge status: Wrong Answer
a,b=map(str,input().split())
c=a+b
c=int(int(c)**(1/2))
if isinstance(c, int)==True:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import math

n=int(input())

def ts(x):
    return x*(x+1)
m=n
for i in range(math.ceil(math.sqrt(2*n)-2),math.floor(math.sqrt(2*n))+1,1):
    if ts(i)<=2*n<=ts(i+1):
        m=i+1
        break

a=n%(m+1)
b=n//(m+1)
if a!=0:
    print(a)
i=1
c=0
while c!=b:
    if i!=a and m+1-i!=a:
        print(i)
        print(m+1-i)
        c+=1
# Judge status: Accepted
# C - Maximal Value
def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []

    for i in range(n):
        if i == 0:
            a.append(b[0])
        elif i == n - 1:
            a.append(b[-1])
        else:
            a.append(min(b[i-1], b[i]))

    print(sum(a))

if __name__ == '__main__':
    main()
# Judge status: Accepted
a,b = map(int,input().split())
if a == b:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
def main():
    s = input()
    MOD = 2019
    r = [0]*MOD
    r[0] = 1
    z = 0
    t = 1
    for i in reversed(s):
        z = int(i) * t + z
        z %= MOD
        t *= 10
        t %= MOD
        r[z] += 1
    print(sum(i*(i-1)//2 for i in r))


if __name__ == '__main__':
    main()