Harryxun/stf_run huggingface dataset:
from collections import deque
MOD = pow(10,9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
P = []; M = []
for i in range(N):
  if A[i] >0:
    P.append(A[i])
  else:
    M.append(A[i])
P.sort(reverse=True)
M.sort(reverse=True)
ans = 1
if K == 1:
  print(P[0]%MOD)
  exit()
if len(M) == 0: #全て正の場合:
  for i in range(K):
    ans = ans*P[i]%MOD
  print(ans)
  exit()
if len(P) == 0: #全て負の場合
  for i in range(K):
    ans = ans*M[i]%MOD
  print(ans)
  exit()
L = [[],[]]
M.sort()
P = deque(P); M = deque(M)
pm = [0,0] #正負の数を保存
pnow = 0; mnow = 0
#print(P,M)

for i in range(K):
  if not P:
    temp = M.popleft()
    pm[1] +=1
    L[1].append(temp)
  elif not M:
    temp = P.popleft()
    pm[0] +=1
    L[0].append(temp)
  elif P and M:
    if P[0] >= abs(M[0]):
      temp = P.popleft()
      pm[0] += 1
      L[0].append(temp)
    else:
      temp = M.popleft()
      pm[1] += 1
      L[1].append(temp)
#一個ずらす
#print(L)

if pm[1]%2 == 1 and (P or M):
  if not M:
    L[1].pop()
    L[0].append(P[0])
  elif not P:
    L[0].pop()
    L[1].append(M[0])
  elif M and P:
    if L[0][-1]*P[0] >= L[1][-1]*M[0]:
      L[1].pop()
      L[0].append(P[0])
    else:
      L[0].pop()
      L[1].append(M[0])
#print(L)    
for num in range(2):
  for s in L[num]:
    ans = ans*s%MOD
print(ans)


### FIXED CODE ###

from collections import deque
MOD = pow(10,9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
P = []; M = []; Z = []
for i in range(N):
  if A[i] >0:
    P.append(A[i])
  elif A[i] <0:
    M.append(A[i])
  else:
    Z.append(0)
P.sort(reverse=True)
M.sort(reverse=True)
ans = 1
if K == 1:
  print(P[0]%MOD)
  exit()
if len(Z) > N-K:
  print(0)
  exit()
if len(M) == 0: #全て正の場合。0があれば0
  for i in range(K):
    ans = ans*P[i]%MOD
  print(ans)
  exit()
if len(P) == 0: #全て負の場合
  if K%2 == 1 and len(Z) > 0:
    print(0)
    exit()
  if K%2 == 1:
    for i in range(K):
      ans = ans*M[i]%MOD
  else:
    M.sort()
    for i in range(K):
      ans = ans*M[i]%MOD
  print(ans)
  exit()

L = [[],[]]
M.sort()
P = deque(P); M = deque(M)
pm = [0,0] #正負の数を保存
pnow = 0; mnow = 0
#print(P,M)

for i in range(K):
  if not P:
    temp = M.popleft()
    pm[1] +=1
    L[1].append(temp)
  elif not M:
    temp = P.popleft()
    pm[0] +=1
    L[0].append(temp)
  elif P and M:
    if P[0] >= abs(M[0]):
      temp = P.popleft()
      pm[0] += 1
      L[0].append(temp)
    else:
      temp = M.popleft()
      pm[1] += 1
      L[1].append(temp)
#一個ずらす
#print(L)
#print(M,P,L)
if pm[1]%2 == 1:
  if not P and not M:
    pass
  elif not M: #もう負の数が残っていない
    L[1].pop()
    L[0].append(P[0])
  elif not P: #もう正の数が残っていない
    L[0].pop()
    L[1].append(M[0])
  elif M and P:
    if L[0] and L[1]:
      if L[0][-1]*P[0] >= L[1][-1]*M[0]:
        L[1].pop()
        L[0].append(P[0])
      else:
        L[0].pop()
        L[1].append(M[0])
    elif not L[0]:
      L[1].pop()
      L[0].append(P[0])
    elif not L[1]:
      L[0].pop()
      L[1].append(M[0])
#print(L)    
for num in range(2):
  for s in L[num]:
    ans = ans*s%MOD
print(ans)
N = int(input())
A = list(map(int,input().split()))

from functools import reduce
import math

R = reduce(math.gcd,A)

print(R)

### FIXED CODE ###

# author:  Taichicchi
# created: 14.09.2020 22:18:44

import sys
from math import gcd

N = int(input())

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

ans = gcd(A[0], A[1])
for i in range(2, N):
    ans = gcd(ans, A[i])

print(ans)
a=int(input())
b=int(input())
c=int(input())
if a+b>c: print("Yes")
else: print("No")

### FIXED CODE ###

a, b, c = map(int, input().split())
if(a+b>=c):
  print("Yes")
else:
  print("No")
a, b, h = map(int, imput().split())

print((a + b) * h / 2)

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
N=int(inout())
S=[input() for i in range(N)]
print(len(set(S)))

### FIXED CODE ###

N = int(input())
List = list(input() for i in range(N))
print(len(set(List)))
import collections as col
import math

def prime(n):
    ans = []
    num = n
    for i in range(2,int(n**0.5)+1):
        if i%2==0 and i!=2: continue
        while num%i == 0: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return ans

def gcd(a,b): return gcd(b,a%b) if a%b else b

a,b = map(int,input().split())
primes = prime(math.gcd(a,b))
cnt = col.Counter(primes)
ans = len(cnt) + 1
print(ans)
        


### FIXED CODE ###

import collections as col

def prime(n):
    ans = []
    num = n
    for i in range(2,int(n**0.5)+1):
        if i%2==0 and i!=2: continue
        while num%i == 0: num //= i ; ans.append(i)
    if num != 1: ans.append(num)
    return ans

def gcd(a,b): return gcd(b,a%b) if a%b else b

a,b = map(int,input().split())
primes = prime(gcd(a,b))
cnt = col.Counter(primes)
ans = len(cnt) + 1
print(ans)
N = int(input())
if N>=1 and N<1000:
    print(ABC)
else:
    print(ABD)


### FIXED CODE ###

N = int(input())
if N>=1 and N<1000:
    print('ABC')
else:
    print('ABD')
"""from operator import mul
from functools import reduce

def cmb(n,r):
  if n<2: return 0
  r = min(n-r,r)
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under
"""
from math import factorial
def cmb(n,r=2):
  
  return factorial(n) / factorial(r) / factorial(n - r)


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

olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
#print(olt)
for j in range(N):
  index=a_lis[j]
  olt[index]-=1
  #print(olt)
  san=0
  for i in set(a_lis):
    if olt[i] <2:
      continue
    #print(i,olt[i])
    san+=cmb(olt[i])
  
  print(int(san))
  olt[index]+=1

### FIXED CODE ###

def combi(count):
  if n==1:return 0
  elif n==2:return 1
  else:return int(count*(count-1)/2)
 
 
n=int(input())
alis=list(map(int,input().split()))
dick={st:0 for st in set(alis)}
for i in range(n):
  p=alis[i]
  dick[p]+=1
#print(dick)
point=0
for v in dick.values():
  point+=combi(v)
 
 
for i in range(n):
  idx=alis[i]
  minus=dick[idx]-1
  print(point-minus)
n = input()
if n % 4 ==0 or n % 7 ==0:
    print('Yes')
    exit()
for i in range(n // 4 + 1):
    for j in range (n // + 1):
        if 4 * i + 7 * j== n:
            print('Yes')
            exit()
print('No')

### FIXED CODE ###

n = int(input())
if n % 4 ==0 or n % 7 ==0:
    print('Yes')
    exit()
for i in range(n // 4 + 1):
    for j in range (n // + 1):
        if 4 * i + 7 * j == n:
            print('Yes')
            exit()
print('No')
t = int(input())
a, b, c, d = map(int, input().split())
for i in range(t):
    if a>=b and c >=b and d>=b:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

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

ans = 0
for i in range (n-1):
    if a[i] == a[i+1]:
        a[i+1] = -1
        ans += 1
print(ans)
C = input()
alpha_list = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
i = alpha_list.index(C)
print(alpha_list[i+1])

### FIXED CODE ###

C = input()
alpha_list = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(alpha_list)-1):
  if C == alpha_list[i]:
    print(alpha_list[i+1])
n=int(input())
lists=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append([a,b])
diflist=[]
for i in range(n):
    for j in range(n):
        if i!=j:
            add=(lists[i][0]-lists[j][0],lists[i][1]-lists[j][1])
            diflist.append(add)
        else:
            continue
import collections
dic=collections.Counter(diflist)
value=dic.values()
a=max(value)
print(n-a)

### FIXED CODE ###

n=int(input())
lists=[]
if n>=2:
    for i in range(n):
        a,b=map(int,input().split())
        lists.append([a,b])
    diflist=[]
    for i in range(n):
        for j in range(n):
            if i!=j:
                add=(lists[i][0]-lists[j][0],lists[i][1]-lists[j][1])
                diflist.append(add)
            else:
                continue
    import collections
    dic=collections.Counter(diflist)
    value=dic.values()
    a=max(value)
    print(n-a)
else:
    print(1)
a=int(input())

b=int(input())

if a+b<10:
  print('%d',a+b)
else:
  print('error')

### FIXED CODE ###

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

if a+b<10:
  print(a+b)
else:
  print("error")
from math import factorial

n, k = map(int, input().split())
mod = 10**9 + 7
def nck(a,b):
    return factorial(a) // (factorial(b) * factorial(a - b))

for i in range(1, k + 1):
	x = (nck(n-k+1,i) * min(i, k-i+1)) % mod
	print(x)


### FIXED CODE ###

n, k = map(int, input().split())
mod = 10**9 + 7

fact = [1] * (n+1)

for i in range(2, n+1):
	fact[i] = fact[i-1] * i


def nck(a,b):
    return fact[a] // (fact[b] * fact[a - b])

for i in range(1, k + 1):
	print((nck(n-k+1,i) * fact[k-1] // (fact[i-1] * fact[k-i])) % mod)
x = int(input())
flg = 0
_flg = 1
while flg == 0:
    mx  = int(x**0.5)
    for i in range(2, mx+1):
        if x % i == 0:
            _flg = 0
            break
    fig = _flg
    if flg == 0:
        x+=1
print(x)


### FIXED CODE ###

s, t = map(str, input().split())
print(t+s)
n = int(input())
x＝[list(map(int,input().split()))]
y = []
for i in range(n):
  if x[i]>x[i+1]:
    y.append(x[i]-1)
  else:
    y.append(x[i])
for j in range(n):
  if y[j]>y[j+1]:
    print("No")
    exit()
print("Yes")

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
m = 0
for i in range(n):
  m = max(m,a[i])
  if a[i] < m-1:
    print("No")
    exit()
print("Yes")
str = inpit().split()
print(str[1]+str=[0])

### FIXED CODE ###

string = input().split()
print(string[1]+string[0])
def check(x):
    a, b = 0, 0
    for ball in x:
        if a > ball:
             a = ball
        elif b > ball:
             b = ball
        else:
             return False
    return True

n = int(raw_input())
for i in range(n):
    all = map(int, raw_input().split())
    print "YES" if check(all) else print "NO"

### FIXED CODE ###

def d(x):
    b, c = 0, 0
    for a in x:
        if b < a:
             b = a
        elif c < a:
             c = a
        else:
             return False
    return True
 
n = int(raw_input())
for i in range(n):
    all = map(int, raw_input().split())
    print "YES" if d(all) else "NO"
import sys
cnt = 1
while 1:
	x=sys.stdin.readline().strip()
	if x == '0':
		break;
	print("Case %d: %s"%(cnt,x))
	cnt++ 

### FIXED CODE ###

cnt = 1
while 1:
	x=int(input())
	if x == 0:
		break;
	print("Case %d: %d"%(cnt,x))
	cnt+=1
A, B, C, X, Y = list(map(int, input().split()))
if(A + B <= 2*C):
    a, b = X, Y
else:
    c = min(X, Y) * 2
    if(X > Y):
        if(A > 2*C):
            c += (X - Y) * 2
        else:
            a = (X - Y)
    else:
        if(B > 2*C):
            c += (Y - X) * 2
        else:
            b = (Y - X)


price = a*A + b*B + c*C
print(price)



### FIXED CODE ###

A, B, C, X, Y = list(map(int, input().split()))
a, b, c = 0, 0, 0
if(A + B <= 2*C):
    a, b = X, Y
else:
    c = min(X, Y) * 2
    if(X > Y):
        if(A > 2*C):
            c += (X - Y) * 2
        else:
            a = (X - Y)
    else:
        if(B > 2*C):
            c += (Y - X) * 2
        else:
            b = (Y - X)


price = a*A + b*B + c*C
print(price)
from sys import stdin
S = (stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
cnt = 0
for i in S:
    if i == "1":
        cnt += 1
    else:
        ans = i
if cnt == K:
    ans = 1
print(ans)

### FIXED CODE ###

from sys import stdin
S = (stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
cnt = 0
for i in S:
    if i == "1":
        cnt += 1
    else:
        ans = int(i)
        break
if cnt >= K:
    ans = 1
print(ans)
def insertionSort(A,N):
  for i in range(1,len(A)):
      j = i
      while (j > 0) and (A[j-1] > A[j]) :
          tmp = A[j-1]
          A[j-1] = A[j]
          A[j] = tmp
          j -= 1
      print(' '.join(map(str, A)))
    
N = input()
N = int(N)
A = input()
A = list(map(int, A.split()))
insertionSort(A,N)


### FIXED CODE ###

def insertionSort(A,N):
  for i in range(N):
      j = i
      while (j > 0) and (A[j-1] > A[j]) :
          tmp = A[j-1]
          A[j-1] = A[j]
          A[j] = tmp
          j -= 1
      print(' '.join(map(str, A)))
  
N = input()
N = int(N)
A = input()
A = list(map(int, A.split()))
insertionSort(A,N)
import fraction
a, b, c, d = map(int, input().split())
m=0
e = c * d/fraction.gcd(c,d)
num_c = int(b/c)-int((a-1)/c)
num_d = int(b/d)-int((a-1)/d)
num_e = int(b/e)-int((a-1)/e)
m = num_c + num_d - num_e
print(b-a+1-m)

### FIXED CODE ###

from fractions import gcd
a, b, c, d = map(int, input().split())

e = (c*d)//gcd(c,d)

def calc(x):
    return x - (x//c)-(x//d)+(x//e)

print(calc(b)-calc(a-1))
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
s_A = sum(A)

if N - s_A >= 0:
    print(N - s_A)
    exit()
if N - s_A < 0:
    print(-1)
    exit()


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in a:
    n-=i
    if n<0: #宿題の総日数が夏休みの日数を上回った場合
        print(-1)
        exit()
print(n)
from collections import defaultdict


def main():

    n = int(input())

    v = list(map(int, input().split(' ')))

    odd = defaultdict(int)
    even = defaultdict(int)

    for i, num in enumerate(v):
        # print(i % 2)
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            # print(i, ": ", num)
            odd[num] += 1

    x = sorted(even.items(), key=lambda x: x[1], reverse=True)
    y = sorted(odd.items, key=lambda x: x[1], reverse=True)

    if x[0][0] != y[0][0]:
        ans = n - x[0][1] - y[0][1]
    else:
        ans = n - max(x[0][1] + y[1][1], x[1][1] + y[0][1])

    print(ans)


main()


### FIXED CODE ###

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

judge_2n_1 = {}
judge_2n = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] not in judge_2n_1.keys():
            judge_2n_1[v[i]] = 1
        else:
            judge_2n_1[v[i]] += 1
    else:
        if v[i] not in judge_2n.keys():
            judge_2n[v[i]] = 1
        else:
            judge_2n[v[i]] += 1

judge_2n = sorted(judge_2n.items(), key=lambda x: x[1], reverse=True)
judge_2n_1 = sorted(judge_2n_1.items(), key=lambda x: x[1], reverse=True)
answer = n - 1

for i in judge_2n[:2]:
    for j in judge_2n_1[:2]:
        if i[0] != j[0]:
            answer = min(answer, n - i[1] - j[1])
        else:
            answer = min(answer, n - max(i[1], j[1]))

print(answer)
a,b,c = map(int raw_input().split())
if a >=b and a>=c:
  print b+c
elif b>=a and b>=c:
  print a+c
else:
  print a+b

### FIXED CODE ###

a,b,c = map(int, raw_input().split())
if a >=b and a>=c:
  print b+c
elif b>=a and b>=c:
  print a+c
else:
  print a+b
def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    
    A.sort()
    print(A[n - 1] - A[0])
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = []
    data = input().split()
    for i in range(N):
        A.append(int(data[i]))
    
    A.sort()
    print(A[N - 1] - A[0])
    
if __name__ == "__main__":
    main()
s=input()
stk = Stack(None)
stri=""
for i in s:
    if(i==" "):
        stk.push(stri)
        stri=""
    elif(i.isdigit()):
        stri="".join([stri,i])
    elif(i=="+" or i=="-" or i=="*"):
        b=stk.pop()
        b=int(b)
        a=int(stk.pop())
        if(i=="+"):
            stri=(str(a+b))
        elif(i=="-"):
            stri=(str(a-b))
        else:
            stri=(str(a*b))
    else:
        break

print(stri)

### FIXED CODE ###

class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val

class Stack:
    member=Trio(None)
    def __init__(self,stri):
        if(isinstance(stri,str)):
            for i,e in enumerate(stri):
                if(i==0):
                    self.member.set_val(e)
                else:
                    self.push(e)

    
    def push(self,n):
        self.member.set_nex(Trio(n,self.member,None))
        self.member=self.member.get_nex()

    def pop(self):
        if(self.member==None):
            return None
        d=self.member.get_val()
        self.member=self.member.get_pre()
        return d

s=input()
stk = Stack(None)
stri=""
for i in s:
    if(i==" "):
        stk.push(stri)
        stri=""
    elif(i.isdigit()):
        stri="".join([stri,i])
    elif(i=="+" or i=="-" or i=="*"):
        b=stk.pop()
        b=int(b)
        a=int(stk.pop())
        if(i=="+"):
            stri=(str(a+b))
        elif(i=="-"):
            stri=(str(a-b))
        else:
            stri=(str(a*b))

print(stri)
n = int(input())
h = list(map(int, input().split()))
sum = 0
max = 0
for i in range(n):
    if max <= h[i]:
        sum += 1
        max = h[i]
print(sum)

### FIXED CODE ###

a,b = map(int, input().split())
if a == b:
    print(a*2)
elif a > b:
    print(a*2-1)
else:
    print(b*2-1)
N = int(input())
A = list(map(int, input().split()))
ans =1;
iszero = False

for 0 in range A:
  if(A[i]==0):
    iszero = True

for i in range(N):
  if(iszero):
    ans = 0
    break
    
  ans *= A[i]
  
  if(ans>10**18):
    ans = -1

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans =1;
iszero = False

if 0 in A:
  iszero = True
for i in range(N):
  if(iszero):
    ans = 0
    break
  ans *= A[i] 
  if ans>10**18:
    ans = -1
    break

print(ans)
t=list(input())
n=len(t)
if t[0]=="?":
    if t[1]=="P":
            t[0]="D"
    if t[1]=="D":
            t[0]="D"
    elif t[1]=="?":
        t[0]="D"
for i in range(1,n):
    if t[i]=="?":
        if t[i-1]=="P":
            t[i]="D"
        if t[i-1]=="D":
            t[i]="D"
print("".join(t))

### FIXED CODE ###

t=list(input())
n=len(t)
for i in range(n):
    if t[i]=="?":
        t[i]="D"
print("".join(t))
s = [int(x) if x!='?' else -1 for x in input()]

mod = 1000000007
length = len(s)
ans = list([0]*13 for i in range(length+1))
ans[0][0] = 1

mod_x10 = [0]*13
for i in range(13):
    mod_x10[i] = i * 10 % 13 - 1

for i in range(length):
    for j in range(13):
        x = mod_x10[j]
        if s[i] == -1:
            for k in range(10):
                x = (x + 1) % 13
                ans[i+1][x] += ans[i][j] % mod
        else:
            x = (x + int(s[i]) + 1) % 13
            ans[i+1][x] += ans[i][j] % mod

print(ans[length][5] % mod)
print('a')


### FIXED CODE ###

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

if (a + b) % 2 == 0:
    print((a+b)//2)
else:
    print('IMPOSSIBLE')
N, K = map(int, input().split())
MOD = 1000000007

fact = [1]
for i in range(1, N):
  fact.append(fact[-1] * i)

def comb(n, k):
  return (fact[n] // (fact[n - k] * fact[k])) % MOD

def f2(n, k):
  return comb(n + k - 1, k - 1)

def f(n, k):
  if n < k:
    return
  if n == 0 and k == 0:
    return 1
  if k < 1:
    return 0
  return f2(n - k, k)

for i in range(1, K + 1):
  blue = f(K, i)
  red = (f(N - K, i - 1) + 2 * f(N - K, i) + f(N - K, i + 1)) % MOD
  ans = blue * red
  print(ans % MOD)

### FIXED CODE ###

N, K = map(int, input().split())
MOD = 1000000007

fact = [1]
for i in range(1, N):
  fact.append(fact[-1] * i)

def comb(n, k):
  return (fact[n] // (fact[n - k] * fact[k])) % MOD

def f2(n, k):
  return comb(n + k - 1, k - 1)

def f(n, k):
  if n < k:
    return 0
  if n == 0 and k == 0:
    return 1
  if k < 1:
    return 0
  return f2(n - k, k)

for i in range(1, K + 1):
  blue = f(K, i)
  red = (f(N - K, i - 1) + 2 * f(N - K, i) + f(N - K, i + 1)) % MOD
  ans = blue * red
  print(ans % MOD)
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
count = 0
for i in A:
  count += 1
  if count != N:
    B[i]=A[i+1]-A[i]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))


### FIXED CODE ###

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
k = 0
for i in A:
  k += 1
  if k != N:
    B[k-1]=A[k]-A[k-1]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))
a,b,c,d = map(int,input().split())
total_num = b-a+1
# # of x%c==0
c_num = b//c - (a-1)//c
d_num = b//d - (a-1)//d
from fractions import gcd
lcm = c*d/gcd(c,d)
cd_num = b//lcm - (a-1)//lcm
print(total_num-c_num-d_num+cd_num)


### FIXED CODE ###

s = input()
for i in range(1,4):
  if s[i]==s[i-1]:
    print('Bad')
    exit()
print('Good')
coin = int(input())
siawase = 0
if coin >= 500:
    siawase = siawase + int(coin / 500) * 1000
    amari = coin % 500
    siawase = siawase + int(amari / 5) *5
elif coin >= 5:
    siawase = siawase + int(coin / 5) * 5
    
print(int(siawase))


### FIXED CODE ###

# 文字列の読み込み
s = input()
a = list(s)
if a[2] == a[3] and a[4] == a[5]:
    print('Yes')
else:
    print('No')
S = str(input())
n = 0
m = 0
if S[n]!='h':
  while S[n]!='h':
    n+=1
    m+=1
while len(S) > n:
    if (n+m) % 2 == 1 and S[n] != 'i':
        print('No')
        exit()
    elif (n+m) % 2 == 0 and S[n] != 'h':
        print('No')
        exit()
    n += 1

print('Yes')

### FIXED CODE ###

#N=int(input())
#N,M=map(int, input().split())
#L=list(map(int, input().split()))
S = str(input())
if len(S)%2==1:
  print('No')
  exit()
n = 0
while len(S) > n:
    if n % 2 == 1 and S[n] != 'i':
        print('No')
        exit()
    elif n % 2 == 0 and S[n] != 'h':
        print('No')
        exit()
    n += 1

print('Yes')
def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


def main2():
    n = int(input())
    total = 0
    tmp = n
    while tmp > 0:
        total += n % 10
        tmp = tmp // 10

    if n % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main2()


### FIXED CODE ###

def main():
    s = input()
    total = 0
    for i in range(len(s)):
        total += int(s[i])

    if int(s) % total == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
xs = map(int, input().split())
for i in range(len(xs)):
    if xs[i] == 0:
        print(i+1)


### FIXED CODE ###

xs = list(map(int, input().split()))
for i in range(len(xs)):
    if xs[i] == 0:
        print(i+1)
imort math
x1,y1,x2,y2=map(float,input().split())
d=math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))
print(d)

### FIXED CODE ###

import math
x1,y1,x2,y2=map(float,input().split())
d=math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))
print(d)
# from pprint import pprint
# import math
# import collections
from numba import jit

N = int(input())

loops = 0


# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))

@jit('i8(i8,i8,i8)', cache=True)
def calc(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


# 全数字が等しい場合
p_eq = [0] * 100
for xyz in range(1, 100 + 1):
    p_eq[xyz] = calc(xyz, xyz, xyz)

p_ne = []
for x in range(1, 100):
    for y in range(1, 100):
        if x + y > 100:
            break
        for z in range(1, 100):
            if x + y + z > 100:
                break
            res = calc(x, y, z)
            p_ne.append(res)

# p_set = p

# p_equal = []
# p_nonequal = []
# for _p in p_set:
#     loops += 1
#     x, y, z = _p[0], _p[1], _p[2]
#
#     if x == y == z:
#         p_equal.append(calc(x, y, z))
#     else:
#         p_nonequal.append(calc(x, y, z))

# print(p_equal)
# print(p_nonequal)

res = [None] * N
for i in range(1, N + 1):
    if i in p_eq:
        res[i] = 1
    elif i in p_ne:
        res[i] = 3
    else:
        res[i] = 0

for s in res:
    print(s)
# print('lp', loops)


### FIXED CODE ###

# from pprint import pprint
# import math
# import collections
from numba import jit

N = int(input())

# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))

@jit(cache=True)
def calc(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


res = [0] * 1000009

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = calc(x, y, z)
            res[n - 1] += 1

for i in range(N):
    print(res[i])
k,t = map(int,input().split())
A = list(map(int,input().split()))
print(max(2*max(A) - sum(A) -1))

### FIXED CODE ###

k,t = map(int,input().split())
A = list(map(int,input().split()))
print(max(0,2*max(A) - sum(A) -1))