peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
count = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1,N + 1):
    a, b = int(str(i)[0]), int(str(i)[-1])
    count[a][b] += 1
for i in range(1,10):
    for j in range(10):
        ans += count[i][j] * count[j][i]
print(ans)
# Judge status: Accepted
N,M=map(int,input().split())
A = [str(input()) for _ in range(N)]
B = [str(input()) for _ in range(M)]
k=N//M + N%M
def macthing(y,x):
  flag=0
  for p in range(M):
    if A[y+p][x:x+M]!=B[p]:
      flag=1
      break
  if flag==0:
    return True
  else:
    return False

for i in range(k):
  for j in range(k):
    if macthing(i,j):
      print('Yes')
      exit()
print('No')
# Judge status: Wrong Answer
S=input()
Q=int(input())
def rev(s):
    l = len(s)
    return s[-1]+s[1:l-1]+s[0]
    
s=S[0]
for i in range(Q):
    T = input().split()
    if T[0]=='1':
        s=rev(s)
    elif T[0]=='2':
        F,C=T[1],T[2]
        if F=='1':
            s=str(C)+s
        else:
            s=s+str(C)
print(s)
# Judge status: Accepted
n = "0" + input()
n = list(map(int, list(n)))
n.reverse()

pay = 0
turi = 0

pls = 0
for i in range(len(n)):
  val = n[i] + pls
  pls = 0
  if val < 5:
    pay += val
  elif val == 5:
    pay += val
    if n[i + 1] >= 5:
      pls = 1
  else:
    turi += 10 - val
    pls = 1

ans = pay + turi
print(ans)
# Judge status: Wrong Answer
number = input()
check = False
for i in range(len(number)-1):
    if i == len(number)-2:
        break
    elif number[i] == number[i+1]:
        check = True
if check == True:
    print("Bad")
else:
    print("Good")
# Judge status: Wrong Answer
import collections
n = int(input())
a = list(map(str, input().split()))

b = collections.deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

print(" ".join(b))
# Judge status: Wrong Answer
import fractions

A, B = map(int, input().split())

i = fractions.gcd(A, B)

C = []

for j in range(2, int(i**0.5)+1):
    while True:
        if i%j == 0:
            i //= j
            C.append(j)
        else:
            break

print(len(set(C))+1)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,


def solve(S):
    alphabets = ['A', 'C', 'G', 'T']
    max_count = 0
    count = 0
    for s in S:
        if s in alphabets:
            count += 1
        else:
            max_count = max(max_count, count)
            count = 0
    return max_count


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))
# Judge status: Wrong Answer
import re
import sys


def main():
    s = sys.stdin.readline().rstrip().replace("?", ".")
    t = sys.stdin.readline().rstrip()

    n = len(s)
    m = len(t)
    ans = 0

    for i in range(n, n - m + 1, -1):
        tmp = s[i - m : i]
        if re.fullmatch(tmp, t):
            s = re.sub(tmp, t, s)
            ans = 1
            break

    if ans == 1:
        print(s.replace(".", "a"))
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input()) 
P = [list(map(int, input().split())) for i in range(N)] 
P.insert(0,[0,0,0])

ans = "Yes"
for i in range(N):
	norm = abs(P[i+1][1]-P[i][1])+abs(P[i+1][2]-P[i][2])
	move = (P[i+1][0]-P[i][0]) - norm
	if ((move%2 != 0) or (move < 0)):
		ans = "No"
		break
	
print(ans)
# Judge status: Accepted
N=int(input())
X=list(map(int,input().split()))
def P(n):
    return sum([(X[i]-n)**2 for i in range(0,N)])
l=[P(i) for i in range(1,101)]
print(min(l))
# Judge status: Wrong Answer
n = int(input())
v = list(map(int,input().split()))
v.sort()

for i in range(0,n-1):
  sum = int((v[i] + v[i+1])/ 2)
  v[i+1] = sum 

print(v[n-1])
# Judge status: Accepted
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
# if (v-w)*t>=(b-a):print("YES")
# else:print("NO")
q = abs(a-b)
e = (v-w)*t
if q<=e:
	print("YES")
else:
	print("NO")
# Judge status: Accepted
x, y = map(int, input().split())
judge='No'

for i in range(x+1):
  if(x==1 and (y==4 or y==2)):
    judge='Yes'
  if(y%4==0 and y/4==x):
    judge='Yes'
  if(y%2==0 and y/2==x):
    judge='Yes'
  for j in range(x+1-i):
    if((i*2+j*4)==y and i+j==x):
      judge='Yes'
    if((i*4+j*2)==y and i+j==x):
      judge='Yes'
      
if(y%2==1):
  judge='No'

print(judge)
# Judge status: Accepted
import collections
cc = collections.Counter()
for l in raw_input():
	cc[l] +=1
	cc[l] %= 2
print 'Yes' if all([cc[k]%2==0 for k in cc]) else 'No'
# Judge status: Wrong Answer
X = int(input())

kyu = [600,800,1000,1200,1400,1600,2000]
N = 8

for i in range(len(kyu)):
    if X < kyu[i]:
        print(N - i)
        break
# Judge status: Wrong Answer
n,a,b = map(int, input().split())
cnt = 0

def digidsum(x):
  s = str(n)
  array_list = list(map(int,s))
  return sum(array_list)



for i in range(n):
  if digidsum(i+1) >= a and digidsum(i+1) <= b:
    cnt += i
print(cnt)
# Judge status: Accepted
n = input()
a = map(int, raw_input().strip().split())
s = list(set(a))

if len(s) != n:
    print "NO"
else:
    print "YES"
# Judge status: Accepted
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ret = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a+100*b+50*c == X:
        ret += 1
print(ret)
# Judge status: Accepted
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])
# Judge status: Wrong Answer
import random
import numpy as np

S =list =["A","B"]
x = np.random.choice(S)
y = np.random.choice(S)
z = np.random.choice(S)
#print(x,y,z)
if x == y == z:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
n,h=map(int,input().split())
ab=[]
ans=0
for i in range(n):
  aa,bb=map(int,input().split())
  ab.append([aa,bb])

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0

for a,b in ab:
  if b>katana:
    cnt+=1

for i in range(cnt):
  if h<=0:break
  h-=ab[i][1]
  ans+=1
if h>0:
  ans+=(h+katana-1)//katana
print(ans)
# Judge status: Wrong Answer
N = int(input())
if N == 2:
    print(0)
    import sys
    sys.exit()
if N == 3:
    print(3)
    import sys
    sys.exit()


s = 0
for n in range(1, N//2):
    s += (N//n if N%n != 0 else N//n - 1)

print(s+N//2)
# Judge status: Accepted
line = input().split(" ")

N, K = int(line[0]), int(line[1])

ans = 0
while N > 0:
	N //= K
	# print(N, K)
	ans += 1

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

a.sort()

ans_n = a[-1]
del a[-1]
ans_r = a[0]

dif = 1001001000
for i in range(n-1):
    if dif > abs(ans_n / 2 - a[i]):
        ans_r = a[i]
        dif = abs(ans_n / 2 - a[i])

print('%d %d' % (ans_n, ans_r))
# Judge status: Accepted
a=int(input())
result=[]
for i in range(1,a+1):
    for j in range(2,a+1):
        if j>=10:
            continue
        if i**j<=a:
            result.append(i**j)
result.append(1)
print(max(result))
# Judge status: Accepted
x,y=map(int,input().split())
a=(y-2*x)//2
b=x-a
 
if y%2==0 and a>=0 and b>=0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
def solve():
    S = input()
    T = input()
    for _ in range(len(S)):
        if T == S:
            print('Yes')
            exit()
        S = S[1:] + S[0]
    print('No')

if __name__ == "__main__":
    solve()
# Judge status: Accepted
a,b=input().split()
a=int(a)
b=int(b)
if a<=8:
  if b<=8:
    print("Yay!")
  else:
    print(":(")
else:
  print(":(")
# Judge status: Wrong Answer
#文字列ｓのうちA～Zまでを取り出す
s = list(input())
sa = s.index("A")
m = [i for i, x in enumerate(s) if x == 'Z']
mz = int(m[-1])
p = (s[sa:mz])
print(len(p))
# Judge status: Accepted
from math import ceil
n,d = map(int,input().split())
print(ceil(n/(d*2+1)))
# Judge status: Wrong Answer
a = list(input())
n = len(a)
for i in range(n):
  a[i] = "x"
l = "".join(a)
print(l)
# Judge status: Wrong Answer
import collections
N=int(input())
A=list(map(int,input().split()))
A=collections.Counter(A)
A=A.most_common()
na=A[0][1]
if na==1:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
def fn(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3*n + 1


s = int(input())

a = []
b = s
count = 0
for i in range(10**6 + 1):
    a.append(b)
    b = fn(b)
    if b == 1:
        count += 1
        if count == 3:
            break

for i in range(len(a)):
    for j in range(i+1, len(a)):
        if a[i] == a[j]:
            result = j
            break
print(j)
# Judge status: Wrong Answer
S = input()
nS = len(S)
white = ("01"*10000)[:nS]
black = ("10"*10000)[:nS]
sa_white = len([1 for x,y in zip(S, white) if x!=y])
sa_black = len([1 for x,y in zip(S, black) if x!=y])
print(min(sa_white, sa_black))
# Judge status: Accepted
from collections import Counter

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

P = sorted([i for i in A.items() if i[1] >= 2])

if len(P) < 2:
  print(0)
elif P[-1][1] >= 4:
  print(P[-1][0] ** 2)
else:
  print(P[-1][0] * P[-2][0])
# Judge status: Accepted
n = int(input()[-1])

if n in [2, 4, 5, 7, 9]:
  print("hon")
elif n in [0, 1, 6, 8]:
  print("pon")
else:
  print("bon")
# Judge status: Accepted
from math import sqrt
N = int(input())
ans = 10 ** 12
for i in range(int(sqrt(N))):
  if N % (i + 1) != 0: continue
  else: ans = min(ans, i + N // (i + 1) - 1)
print(ans)
# Judge status: Accepted
N=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(N) :
    if p[i]==i+1 :
        ans+=0
    else :
        ans+=1
print("YES"if ans==0 or ans==2 else "NO")
# Judge status: Accepted
n,s=int(input()),str(input())
l=[0]
for i in s:
  x= -1 if i=="D" else 1
  l+=[l[-1]+x]
print(max(l))
# Judge status: Accepted
n = int(input())
s = input()
temp = 0
res = 0
for i in range(n):
  if s[i] == 'I':
    temp += 1
  else:
    temp -= 1
  res = max(res, temp)
print(res)
# Judge status: Wrong Answer
S = list(input())
T = list(input())

length = int(len(S))
difference = 0

for i in range(length):
    if S[i] != T[i]:
        difference = difference + 1

if difference%2 == 0:
    change = int(difference/2)
if difference%2 != 0:
    change = int((difference+1)/2)
    
print(str(change))
# Judge status: Accepted
def main():
    N = int(input())
    cell = [[int(a) for a in input().split()] for j in range(2)]
    mcandies = 0
    for i in range(N):
        s = sum(cell[0][:i+1]) + sum(cell[1][i:])
        if mcandies < s:
            mcandies = s
    print(mcandies)
if __name__ == "__main__":
    main()
# Judge status: Accepted
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
distances = []

if N >= M:
    print(0)
else:
    for i in range(M-1):
        distance = X[i+1] - X[i]
        distances.append(distance)

    distances = sorted(distances, reverse=True)
    ans = sum(distances)

    for i in range(N-1):
        ans -= distances[i]

    print(ans)
# Judge status: Wrong Answer
def a_number_of_multiples(l,r,d):
    r = r+1
    range_list = list(range(l,r))
    per_list = []
    for i in range_list:
        if i % d == 0:
            per_list.append(i)
        else:
            pass
    count_list = len(per_list)
    return count_list
# Judge status: Accepted

from collections import Counter

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    print(sum([v if v < k else v-k for k,v in counter.items()]))
    
solve()
# Judge status: Accepted
# -*- coding: utf-8 -*-

def solve():
    S = input()
    if S[2]==S[3] and S[4]==S[5]:
        return 'Yes'
    else:
        return 'No'

if __name__ == '__main__':
    print(solve())
# Judge status: Wrong Answer
N = int (input ())
t2 = 0
x2 = 0
y2 = 0
for i in range (N):
    t,x,y = map(int, input().split())
    if abs (t-t2) >= abs ((x-x2)+(y-y2)):
        if (round (((t-t2)-((x-x2)+(y-y2)))/2))*2 ==((t-t2)-((x-x2)+(y-y2))):
            ans = 'YES'
        else:
            ans = 'NO'
            break
    else:
        ans = 'NO'
        break
    t2 = t
    x2 = x
    y2 = y
print (ans)
# Judge status: Accepted
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = N - sum(A)
if ans >= 0:
  print(ans)
else:
  print(-1)
# Judge status: Wrong Answer
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

time = 0
count = 0
while A or B:
    if A and B:
        desk = A if A[0] < B[0] else B
    else:
        desk = A if A else B
    time += desk.popleft()

    if time > K:
        break
    else:
        count += 1

print(count)
# Judge status: Accepted
p,q,r=map(int,input().split())
lis=[p+q,q+r,r+p]
print(min(lis))
# Judge status: Accepted
import math
import sys

k, a, b = map(int, sys.stdin.readline().rstrip().split())

if b - a <= 2:
    print(k + 1)
else:
    t = max(0, (k - a + 1) // 2)
    print(k + 1 + t * (b - a - 2))
    # print(max(0, math.ceil((k - a + 1)/2)))
# Judge status: Wrong Answer
n,l=map(int,input().split())
taste_list=[]
for i in range(1,n+1):
    taste_list.append(l+i-1)
taste=sum(taste_list)
if taste_list[0]>0:
    print(taste-taste_list[0])
elif taste_list[0]<0:
    print(taste-taste_list[n-1])
# Judge status: Accepted
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]

for i in range(n):
  a.append(a[i] + A[i])
  
for i in range(m):
  b.append(b[i] + B[i])
  
ans, j = 0, m

for i in range(n+1):
  if a[i] > k:
    break
  while a[i] + b[j] > k:
    j -= 1
  ans = max(ans, i+j)

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

ans = -(-(N-1) // (K-1))
print(ans)
# Judge status: Wrong Answer
def main():
    A, B = map(int,input().split())
    print( A * B if (A % 10 == 0) & (B % 10 == 0) else -1) 
    return 0
    
if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = int(input())

ans = (n // 11) * 2

rem = n % 11

if rem <= 5:
    ans += 1
else:
    ans += 2

print(ans)
# Judge status: Accepted
n = int(input())
a = int(input())

print('Yes' if n % 500 <= a else 'No')
# Judge status: Wrong Answer
n = int(input())
l1 = 2
l2 = 1
l3 = l2 + l1

if n == 1:
    print(l1)
elif n == 2:
    print(l2)
else:
    for i in range(n - 2):
        l1 = l2
        l2 = l3
        l3 = l2 + l1
    print(l3)
# Judge status: Wrong Answer
n = int(input())
x = input().split()
a = 0
b = 1
while a <= n - 1 and b <= 10^8:
  b = b * int(x[a])
  a += 1
if b > 10^8:
  print('-1')
else:
  print(b)
# Judge status: Wrong Answer
n,m=map(int,input().split())
if n==1 and m==1: print(1)
elif n==1 and m!=1: print(m-2)
else: print((n-2)*(m-2))
# Judge status: Wrong Answer
n = int(input())
seq = [x for x in input().split(' ')]

b = [seq[n-1]]

if n % 2 == 0:
    for j in range(1, n, 2):
        if j != n-1:
            b.append(seq[j])
    for i in range(0, n, 2):
        b.append(seq[i])

else:
    for j in range(0, n, 2):
        if j != n-1:
            b.append(seq[j])
    
    for i in range(1, n, 2):
        b.append(seq[i])

print(' '.join(b))
# Judge status: Accepted
S = list(input())

for i in range(2, len(S)):
    miniS = S[0:-i]
    if len(miniS) % 2 == 0:
        front = ''.join(miniS[0:len(miniS)//2])
        back = ''.join(miniS[len(miniS)//2:len(miniS)])
        if front == back:
            print(len(miniS))
            exit()
# Judge status: Accepted
x=int(input())
if x==3 or x==5 or x==7:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
n = int(input())
if n == 1:
    print(1)
else:
    Li = 2
    Lj = 1
    cnt = 2
    while True:
        Lk = Li + Lj
        if cnt == n:
            print(Lk)
            break
        cnt += 1
        Li = Lj
        Lj = Lk
# Judge status: Wrong Answer
x,n = map(int, input().split())
a = list(map(int, input().split()))
candicate = []
for i in range(101):
  exist = False
  for d in a:
    if i == d:
      exist = True
      break
  if exist == False:
    candicate.append(i)

for j in range(len(candicate) - 1):
  if candicate[j] == x or candicate[j + 1] == x:
    print(x)
    break
  elif candicate[j] < x and x < candicate[j+1]:
    if abs(candicate[j] - x) <= abs(candicate[j+1] - x):
      print(candicate[j])
    else:
      print(candicate[j+1])
# Judge status: Wrong Answer
x=int(input())
a=list(map(int, input().split()))
suma=sum(a)
ans=0
mindiff=10000000

for i in range(len(a)):
  ans+=a[i]
  if ans>=suma/2:
    diff=abs(2*ans-suma)
    mindiff=min(diff,mindiff)
    
print(mindiff)
# Judge status: Accepted
a,b=map(int,input().split())
h="-"
s=input()
if s[:a].isdecimal() and s[a]==h and s[-b:].isdecimal():
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
name = input()
for i in range(3):
  print(name[i])
# Judge status: Accepted
n = int(input())
a_list = [int(input()) for nesya in range(n)]
s = 1
a = 1
while a <= n:
  s = a_list[s-1]
  if s == 2:
    print(a)
    break
  elif a == n:
    print(-1)
  a += 1
# Judge status: Accepted
import sys
def slove(n, k):
    a_list = [int(i) for i in k.split()]
    num = len([i for i in a_list if i % 4 == 0])
    tmp =  [i for i in a_list if i % 4 != 0]
    num2 = len([i for i in tmp if i % 2 == 0]) // 2
    return "Yes" if (num + num2)>= n // 2 else "No"

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    k = input()
    print(slove(n, k))
# Judge status: Wrong Answer
n,x = map(int, input().split())
l = tuple(map(int, input().split()))

d = []
for i in range(n):
    if i == 0: d.append(0)
    else:
        di = d[i-1] + l[i-1]
        d.append(di)
        
print(len([i for i in d if i <= x]))
# Judge status: Wrong Answer
#!/usr/bin/env python3

s = str(input())

flag = 1
if s[0] != "A":
    flag = 0


num_C = 0
for i in s[2:-1]:
    if i == "C":
        num_C += 1
    else:
        if i.isupper():
            flag = 0
if num_C != 1:
    flag = 0


if flag == 0:
    print("WA")
else:
    print("AC")
# Judge status: Wrong Answer
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
cnt = 0
for i in range(1, n-1):
  if li[i-1] <= li[i] <= li[i+1]:
    cnt += 1
print(cnt)
# Judge status: Accepted
n = int(input())
apple = [4*i+7*j for i in range(100) for j in range(100)]
print("Yes" if n in apple else "No")
# Judge status: Accepted
import sys
import math
from collections import deque
input = sys.stdin.readline
#S,L,R = map(int, input().split())

N = int(input())

A = [0]
B = []

Answer = 0

j = 1;
while j*j<=N:
    A.append(j)
    if N//j != j:
        B.append(N//j)
    j+=1

B.reverse()
A =  A + B

Answer = 0
for i in range(1,len(A)):
    num = ((N//A[i])*(N//A[i]+1)//2)
    num *= ((A[i]*(A[i]+1)//2)-(A[i-1]*(A[i-1]+1)//2))
    Answer += num

print(Answer)
# Judge status: Wrong Answer
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))
K=min(N,K)

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,K):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])
    print(dp)

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])
# Judge status: Accepted
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
#i番目駅からのスタート
for i in range(n):
  #時間
  t = 0
  for j in range(i,n-1):
    c,s,f = l[j]
    if t>=s:
      if t%f!=0:
        t += -(t%f)+f
      else:
        t += 0
    else:
      t += (s-t)
      if t%f!=0:
        t += -(t%f)+f
      else:
        t += 0
    t += c
  print(t)
# Judge status: Accepted
S = int(input())
x1, y1 = 0, 0
x2, y2 = 10 ** 9, 1
y3 = S // (10 ** 9) + 1
x3 = 10 ** 9 * y3 - S
if (S == 10 ** 18):
    print(0, 0, 10**9, 0, 0, 10**9)
else:
    print(x1, y1, x2, y2, x3, y3)
# Judge status: Wrong Answer
N = int(input())

dic = {}
B = []

for i in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if '{}'.format(b) in dic:
        dic['{}'.format(b)] += a
    else:
        dic['{}'.format(b)] = a

Bs = sorted(B)

time = 0

for i, num in enumerate(Bs):
    time += dic['{}'.format(num)]
    if num < time:
        print('No')
        break

    if i == len(Bs)-1:
        print('Yes')
# Judge status: Accepted
"""
Aの値が大きいものからheapqにぶち込んでいけばよい。
"""
from heapq import heappop,heappush
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(reverse=True)
que = []
for a,b in AB:
    if M >= a:
        heappush(que,b)
        M -= 1
    elif que:
        if que[0] < b:
            heappop(que)
            heappush(que,b)
print(sum(que))
# Judge status: Accepted
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

a = ri()
s = rs()

if a >= 3200:
	print(s)
else:
	print('red')
# Judge status: Accepted
n = int(input())

ans = x = 0
for _ in range(n):
    a = int(input())
    if a == 0:
        ans += x//2
        x = 0
    x += a
else:
    ans += x//2

print(ans)
# Judge status: Accepted
n=int(input())
l=[]
for i in range(2,int((n**0.5))+1):
  if n%i==0:
    l.append(i)
if len(l)>=1:
  print(max(l)-1+n//max(l)-1)
else:
  print(n-1)
# Judge status: Wrong Answer
N = int(input())

for i in range(N):
    if int(i * 1.08) == N:
        print(i)
        exit(0)
else:
    print(":(")
# Judge status: Accepted
from itertools import zip_longest

O = input()
E = input()

if len(O) == len(E):
    print("".join([o + e for o, e in zip_longest(O, E)]))
else:
    print("".join([o + e for o, e in zip_longest(O[:-1], E)]) + O[-1])
# Judge status: Accepted
X = int(input())
l = []
if X == 1:
    print(1)
else:
    for b in range(2, int(X ** 0.5) + 1):
        for p in range(2, 2 ** 10):
            if b **p <= X:
                l.append(b ** p)
    print(max(l))
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = []
c = 0
s = sum(A)
table = [0] * 100001
 
for i in A:
    table[i] += 1
 
for i in range(Q):
    B, C = map(int,input().split())
    c = table[B]
    s += (C - B) * c
    table[C] += table[B]
    table[B] = 0
    S.append(s)

for s in S:
    print(s)
# Judge status: Wrong Answer
S = input()

tmp1 = [0 for _ in range(len(S)+1)]
tmp2 = [0 for _ in range(len(S)+1)]

for i in range(len(S)):
  if S[i] == '>':
    tmp1[i] = 1
  else:
    tmp2[i+1] = 1

for i in range(1, len(S)+1):
  if tmp1[-i-1] != 0:
    tmp1[-i-1] = tmp1[-i] + tmp1[-i-1]

for i in range(2, len(S)):
  if tmp2[i] != 0:
    tmp2[i] = tmp2[i] + tmp2[i-1]

ans = 0
for i in range(len(S)):
  ans += max(tmp1[i], tmp2[i])

print(ans)
# Judge status: Accepted
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
c = tuple(map(int, input().split()))
l = len(c)

ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if n - 1 > i and a[i] + 1 == a[i + 1]:
        ans += c[a[i] - 1]

print(ans)
# Judge status: Wrong Answer
s = input()
if s[0] == '9' or s[1] or '9':
  print('Yes')
else:
  print('No')
# Judge status: Accepted
def main():
    n, *a = map(int, open(0).read().split())
    b = [i for i in a if i <= 0]
    *ab, = map(abs, a)
    c = sum(ab)
    if len(b) % 2 == 0:
        print(c)
    else:
        print(c - 2 * min(ab))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
x, y = map(int, input().split())

a = [1,3,5,7,8,12]
b = [4,6,9,11]
c = [2]

if (x in a) and (y in a):
  print("YES")
elif (x in b) and (y in b):
  print("YES")
elif (x in c) and (y in c):
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer

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

cost = [0]*n
cost[0] = arr[0]
for i in range(1, n):
  if i > 1:
    cost[i] = min(abs(arr[i]-arr[i-2])+cost[i-2], abs(arr[i]-arr[i-1])+cost[i-1])
  else:
    cost[i] = abs(arr[i]-arr[i-1])
    
print(cost[-1])