peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n = int(input())
h = [int(x) for x in input().split()]
h.insert(0, -1)
dp = [-1] * (n+1)
dp[1] = 0
dp[2] = abs(h[1] - h[2])

for i in range(3, n+1):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), 
                dp[i-2] + abs(h[i] - h[i-2]))

print(dp[n])
# Judge status: Accepted
N = int(input())
L = list(map(int, input().split()))

# SL = list(set(L))
SL = L
SL.sort()

anss = set()
for ix in range(len(SL)):
    for jx in range(ix+1,len(SL)):
        for ux in range(jx+1,len(SL)):
            if SL[ix] != SL[jx] != SL[ux] and SL[ix]+SL[jx] > SL[ux]:
                anss.add((ix+1, jx+1, ux+1))

print(len(anss))
# Judge status: Accepted
import sys
import copy
import math
import itertools
import numpy as np

A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500+b*100+c*50==X:
                cnt+=1
print(cnt)
# Judge status: Wrong Answer
s = input()
q = int(input())
a = ""
b = ""
for i in range(q):
  l = list(input().split())
  if len(l) == 1:
    a, b = b, a
  else:
    if l[1] == "1":
      s = a + s
      a = l[2]
      if b == "":
        b = s
        s = ""
    else:
      s = s + b
      b = l[2]
      if a == "":
        a = s
        s = ""
print(a+s+b)
# Judge status: Accepted
a,b=map(int,input().split())
c=input()
n=c[b-1]
n=n.lower()
c=list(c)
c[b-1]=n
c=''.join(c)
print(c)
# Judge status: Accepted
def boolean(a,b):
    D = abs(a[0] - b[0]) -abs(a[1] - b[1]) - abs(a[2] - b[2])
    if(D >= 0 and D %2 == 0):
        return 0
    else:
        return 1

N = int(input())
txy=[0 for i in range(N+1)]
txy[0]=[0,0,0]
for i in range(N):
    a=list(map(int,input().split()))
    txy[i+1]=a
ans = "Yes"
for i in range(1,N + 1):
    if(boolean(txy[i-1],txy[i])):
        ans = "No"
        break
print(ans)
# Judge status: Accepted
import sys
import collections

N = int(input())
S = [ch for ch in input()]
counter = collections.Counter(S)
if len(counter.keys()) != 3:
    print(0)
    sys.exit()
total = 1
for k, v in counter.items():
    total *= v

for i in range(len(S)):
    l, r = i - 1, i + 1
    while 0 <= l and r < len(S):
        if len(set([S[i], S[l], S[r]])) == 3:
            total -= 1
        l -= 1
        r += 1
print(total)
# Judge status: Accepted
N, M = map(int, input().split())
A = list(map(int, input().split()))

if N >= sum(A):
  print(N - sum(A))
else:
  print('-1')
# Judge status: Accepted
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    tmp = 0
    ans = 0

    for i in range(n-1):
        if h[i] >= h[i+1]:
            tmp+=1
            ans = max(tmp, ans)
        else:
            tmp=0
    print(ans)

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

if w >= abs(a-b):
    print(0)
elif a > b:
    print(b+w-a)
elif b > a:
    print(a+w-b)
# Judge status: Accepted
n,l = map(int,input().split())
s = [input() for i in range(n)]
s.sort()
print("".join(s))
# Judge status: Accepted
s=input()
t=input()
mx=0
for i in range(len(s)-len(t)+1):
    sm=0
    for j in range(len(t)):
        if s[i+j]==t[j]:
            sm+=1
    mx=max(sm,mx)
print(len(t)-mx)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
if b>c:
  print('delicious')
elif a>=c-b:
  print('safe')
else:
  print('dangerous')
# Judge status: Accepted
a = int(input())
b = [i * j for i in range(1, 10) for j in range(1, 10)]
print("Yes" if a in b else "No")
# Judge status: Wrong Answer
n, k = map(int, input().split())
a_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append([a, b])
a_list.sort(key=lambda x: x[0])
print(a_list)
for i in range(n):
	k -= a_list[i][1]
	if k <= 0:
		print(a_list[i][0])
		break
# Judge status: Wrong Answer
S  = input()
m = 0
c = 0
for s in S:
  if s == 'R':
    c += 1
  else:
    c == 0
  m = max(m, c)
print(m)
# Judge status: Accepted
# coding: utf-8
import math
    
n = int(input())
ans = 0
for i in range(n):
    for j in range(n):
        x=math.gcd(i+1,j+1)
        for k in range(n):
            ans += math.gcd(x,k+1)
print(ans)
# Judge status: Accepted
_,a=open(0)
*a,=map(int,a.split())
x=1000
for i,j in zip(a,a[1:]):x+=x//i*(j-i)*(i<j)
print(x)
# Judge status: Wrong Answer
n = int(input())
A = list(map(int, input().split()))
ans = 0
if len(A) > 2:
  for a in A[::2]:
    if a % 2 == 1:
      ans += 1
print(ans)
# Judge status: Accepted
dat = {}

for i in range(0, 500):
	for j in range(0, 500):
		res = i ** 5 - j ** 5
		dat[res] = [i, j]
		res = i ** 5 + j ** 5
		dat[res] = [i, -j]

tmp = int(input())
if tmp in dat:
	print(dat[tmp][0], dat[tmp][1])
# Judge status: Accepted
n=int(input())
w=list(map(int,input().split()))
s=[w[0]]
sum=sum(w)
ans=sum
for i in range(1,n):
    temp=s[i-1]+w[i]
    s.append(temp)
    ans=min(ans,abs(sum-2*s[i]))
print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
S = list(input())
S[k-1] = S[k-1].lower()
print("".join(S))
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, read().split())
ans = 0
for i in range(1, n + 1):
    cnt = 0
    check = i
    while k > check:
        check *= 2
        cnt += 1
    if cnt == 0:
        ans += 1 / n
    else:
        ans += 0.5 ** cnt * (1 / n)
print(ans)
# Judge status: Accepted
n = int(input())
res = []
for i in input():
    a = ord(i) + n
    if a > 90:
        res.append(chr(a % 90 + 64))
    else:
        res.append(chr(a))
print("".join(res))
# Judge status: Wrong Answer
from itertools import accumulate

N = int(input())
A = list([int(x) for x in input().split()])

count = 0
ironbar = list(accumulate(A))

i = 0
j = len(A) - 1

while i + 1 < j:
    left = ironbar[i]
    right = ironbar[j] - ironbar[i]
    if left > right:
        j = (i+j) // 2
    elif left < right:
        i = (i+j) // 2
    else:
        print(0)
        exit()

left = ironbar[i]
right = ironbar[j] - ironbar[i]

print(abs(left-right))
# Judge status: Accepted
s = input()
b = 0
w = 0
for i in range(len(s)):
    if(s[i] == '0'):
        b = b+1
    if(s[i] == '1'):
        w = w+1

print(2*min(b,w))
# Judge status: Accepted
n = int(input())
s = input().split()

sum = 0
for i in range(n):
  sum += int(s[i])

a = float(sum)/float(n)
if int(a)+0.5 <= a:
  a = int(a)+1
else:
  a = int(a)
  
ans = 0
for i in range(n):
  ans += (int(s[i])-a)**2

print(ans)
# Judge status: Accepted
n=int(input())
#n,m=map(int,input().split())
#t=int(input())
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

flag="Yes"

for i in range(n-2,-1,-1):
    righth=hl[i+1]
    cur=hl[i]
    if cur<=righth:
        pass
    elif cur==righth+1:
        hl[i]=cur-1
    else:
        flag="No"
        break

print(flag)
# Judge status: Accepted
N , R =map(int, input().split())
if N <=10:
    print(R + 100 * ( 10 - N))
else:
    print(R)
# Judge status: Accepted
n = list(map(int, input()))

if n[0] == 7:
    print("Yes")
elif n[1] == 7:
    print("Yes")
elif n[2] == 7:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
X = str(input())

if '9' in X:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
n = int(input())
s = input()
a = 0
if n%2 == 0:
  for i in range (n//2):
    if s[i] == s[n//2-1+i]:
      continue
    else:
      a = 1
      break
else:
  a = 1
print('Yes' if a==0 else 'No')
# Judge status: Wrong Answer
a,b,c,k = map(int,input().split())
count = 0
if k == 0:
  if abs(a-b) >= 10**8:
    print('Unfair')
  else:
    print(a-b)
  exit()

while count == k:
  a1 = a
  b1 = b
  c1 = c
  a = b1 + c1
  b = a1 + c1
  c = a1 + b1
  count += 1
if abs(a-b) >= 10**8:
  print('Unfair')
else:
  print(a-b)
# Judge status: Accepted
# coding: utf-8
N = int(input())
B = list(map(int, input().split()))
A = B
A.insert(0, B[0])
for i in range(1, N - 1):
    if A[i] > A[i+1]:
        A[i] = A[i+1]
print(sum(A))
# Judge status: Wrong Answer
n, *a = map(int, open(0).read().split())
f = 0
t = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
if 2*f + t >= len(a):
    print('Yes')
    quit()
elif 2*f + t + 1 == len(a) and f != 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
def actual(s):
    N = len(s)
    count_operation = 0

    for i in range(N):
        head = s[i]
        tail = s[N - 1 - i]

        if head != tail:
            count_operation += 1

    return int(count_operation / 2)

s = input()
print(actual(s))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
m4 = 0
m2 = 0
for i in range(len(a)):
    if (a[i] % 4 == 0):
        m4 += 1
    elif (a[i] % 2 == 0):
        m2 += 1

if (m4*2+m2 >= len(a) or m4*2+1 >= len(a)):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a, b = map(int, input().split())
ans = (a+b)%24
print(ans)
# Judge status: Wrong Answer
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]
true_buy = float("inf")
for i in range(2**n):
  buy = []
  buy_sum = 0
  for j in range(n):
    if (i>>j) & 1:
      buy.append(ca[j])
      buy_sum += ca[j][0]
  for k in range(m):
    gain = 0
    for l in range(len(buy)):
      gain += buy[l][k]
    if gain < x:
      buy_sum = float("inf")
  true_buy = min(buy_sum,true_buy)
if true_buy == float("inf"):
  print(-1)
else:
  print(true_buy)
# Judge status: Accepted
N,W=map(int,input().split())
MV=[list(map(int, input().split())) for _ in range(N)]
dp=[0]*(W+1)

for w,v in MV:
    for tw in range(W,w-1,-1):
        dp[tw]=max(dp[tw],dp[tw-w]+v)
        #print(dp,tw)

print(max(dp))
# Judge status: Accepted
import math
N, D = map(int, input().split())
count = 0
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
for i in range(N):
  if math.sqrt(x[i] * x[i] + y[i] * y[i]) <= D:
    count += 1
print(count)
# Judge status: Wrong Answer
N = int(input())
print(int(1/2*N*(N-1)))
# Judge status: Accepted
K, S = map(int, input().split())
c = 0
for x in range(K + 1):
    for y in range(x + 1):
        if x + y > S:
            break
        z = S - x - y
        if z >= 0 and z < y + 1:
            if x != y and x!= z and y!= z:
                c += 6
            elif x == y and x == z and y == z:
                c += 1
            else:
                c += 3
print(c)
# Judge status: Accepted
from math import gcd

n, *a = map(int, open(0).read().split())

l = [0] * n
r = [0] * n
for i in range(n - 1):
    l[i + 1] = gcd(l[i], a[i])
for i in range(n - 1, 0, -1):
    r[i - 1] = gcd(r[i], a[i])
print(max(gcd(l[i], r[i]) for i in range(n)))
# Judge status: Accepted
import sys
input = sys.stdin.readline
A, B = [int(x) for x in input().split()]
S = input().rstrip()
if S[A] != "-":
    print("No")
    sys.exit()
if "-" in S[:A] or "-" in S[A+1:]:
    print("No")
    sys.exit()
print("Yes")
# Judge status: Accepted
n = int(input())

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

money = 1000

for i in range(1,n):
    if a[i-1] < a[i]:
        money = money%a[i-1]+a[i]*(money//a[i-1])

print(money)
# Judge status: Accepted
N,M=map(int,input().split())
G=[]
for i in range(0,N):
    G.append([])

for i in range(0,M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

q=[]
sign=[-1]*N
sign[0]=0
q.append(0)
while q:
    x=q.pop(0)
    for nv in G[x]:
        if sign[nv]==-1:
            sign[nv]=x
            q.append(nv)

print("Yes")
for i in range(1,N):
    print(sign[i]+1)
# Judge status: Accepted
a,b,c,d,k = map(int,input().split())
h = c-a
mn = d-b

time = h*60+mn
ans = time-k
print(ans)
# Judge status: Wrong Answer
K = int(input())
m = 0
for i in range(K):
    m = (m * 10 + 7) % K
    if m == 0:
        print(i+1)
        break
    elif m == K-1:
        print(-1)
        break
# Judge status: Accepted
import os, sys, re, math

(H, N) = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

if sum(A) >= H:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N, A, B = map(int, input(). split())
amari = N%(A+B)
kaisu = N//(A+B)
kazu = kaisu*A + min(amari, A)
print(kazu)
# Judge status: Wrong Answer
k=int(input())
if k%2==0:
  ans=(k//2)**2
else:
  ans=(k//2)*(k//2+1)
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))
g=1
while k+(k-1)*(g-1)< n:
  g+=1
print(g)
# Judge status: Wrong Answer
s = list(input().split())

if len(s)==len(set(s)):
    print("yes")
else:
    print("no")
# Judge status: Wrong Answer
s=input()
def kai(s):
    if len(s)//2 == 0:
        if s[:int(len(s)/2-1)] == s[int(len(s)/2):]:
            return True
        else:
            return False

    else:
        if s[:int((len(s)-1)/2)] == s[int((len(s)+1)/2):]:
            return True
        else:
            return False

if kai(s) and kai(s[:int((len(s)-1)/2)]) and kai(s[int((len(s)+1)/2):]):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
a = [list(map(int,input().split())) for _ in range(2)]

ans = 0
for i in range(n):
  candy = 0
  for j in range(n):
    if j <= i:
      candy += a[0][j]
    if j >= i:
      candy += a[1][j]
  ans = max(ans, candy)

print(ans)
# Judge status: Accepted
N, A, B = map(int, input().split())
if (N == 1 and A != B) or A > B:
  print(0)
  exit()
min_ab = (N-1)*A+B
max_ab = (N-1)*B+A
print(max_ab-min_ab+1)
# Judge status: Accepted
# B - 754
S = input()

def f(i):
    return abs(100*int(S[i])+10*int(S[i+1])+int(S[i+2])-753)

ans = 10000
for i in range(len(S)-2):
    ans = min(ans, f(i))
print(ans)
# Judge status: Wrong Answer
S = input()
list = []
for i in S:
    list.append(int(i))
n = len(S)
ans =[]
for i in range(n-2):
    ans.append(100*list[i]+10*list[i+1]+list[i+2])

print(abs(max(ans)-753))
# Judge status: Wrong Answer
dp = [999999] * 100100
n = int(input())
dp[0] = 0
for i in range(0, 100010):
    dp[i+1] = min(dp[i+1], dp[i] + 1)
    for j in range(1,100):
        c = i + 6**j
        if (i+c) > 100000:
            break
        dp[c] = min(dp[c], dp[i] + 1)

    for j in range(1,100):
        c = i + 9**j
        if (i+c) > 100000:
            break
        dp[c] = min(dp[c], dp[i] + 1)

#print(dp[:100])
print(dp[n])
# Judge status: Accepted
N,x=map(int,input().split())
A=list(map(int,input().split()))+[0]
ans=0
for i in range(N):
  eated=max(0,A[i]+A[i-1]-x)
  ans+=eated
  A[i]-=eated
print(ans)
# Judge status: Wrong Answer
a, b = input().split()
x = int(a + b)
n = 1000
for i in range(n):
  if i**2 == x:
    print('Yes')
    break
print('No')
# Judge status: Accepted
a, b, x = map(int, input().split())
print("YES" if a <= x and x <= a+b else "NO")
# Judge status: Accepted
x,y = map(int, input().split())

if (x+y)%3 != 0:
    print(0)
    exit()

if 2*y<x or y>2*x:
    print(0)
    exit()

dan = (x+y)//3+1
num=y-dan+1

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def comb(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

ans = comb(dan-1,num)
print(int(ans))
# Judge status: Wrong Answer
word = input()
start = 0
end = len(word)
while(True):
	i = word.find('?', start, end)
	if (i == -1):
		break
	elif (i == (end-1)):
		word = word.replace('?', "D", 1)   
	elif (word[i-1] == 'P'):
		word = word.replace('?', "D", 1)
	elif ((word[i+1] == "?") or (word[i+1] == "D")):
		word = word.replace('?', "P", 1)
	start = i + 1
print(word)
# Judge status: Wrong Answer
# coding: utf-8
import math
n, k = map(int, input().split())
print(math.ceil(math.log(n, k)))
# Judge status: Accepted
from numpy import*
a,b=median(t:=loadtxt(open(0),skiprows=1),0)
print(int((a-b)*~(~len(t)%2))+1)
# Judge status: Wrong Answer
a=input()
count=0
for i in range(len(a)):
  if a[i] in a:
    count=count+1
if count==0:
  print("yes")
else:
  print("no")
# Judge status: Accepted
#!/usr/bin/env python3
n, k, *P = map(int, open(0).read().split())
p = [(i + 1) / 2 for i in P]
s = [float()]
for i in range(n):
    s.append(s[i] + p[i])
print(max(s[i + k] - s[i] for i in range(n - k + 1)))
# Judge status: Accepted
s = input().split()
if int(s[0]) * int(s[1]) % 2 == 0:
    print("Even")
else:
    print("Odd")
# Judge status: Wrong Answer
n = int(input())
a = []
for i in list(map(int, input().split())):
    # 番号の差の絶対値の最大以上の身長を持つものは条件を満たさないのでパス
    if i < n - 1:
        a.append(i)

answer = 0
for i, hi in enumerate(a):
    for j in range(i + 1, len(a)):
        hj = a[j]
        if abs(i - j) == hi + hj:
            answer += 1
print(answer)
# Judge status: Wrong Answer
x, y = map(int, input().split())

c = 0

while x >= 0:
    if c * 2 + x * 4 == y:
        break 
    c += 1
    x -= 1
else:
    print("No")

print("Yes")
# Judge status: Accepted
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

button = [0] * N
button[0] = 1
next_button = 1
i = 0

while True:
  button[next_button - 1] = 2
  next_button = A[next_button - 1]
  if button[next_button - 1] == 2:
    print("-1")
    break
  elif next_button == 2:
    i += 1
    print(i)
    break
  else:
    button[next_button - 1] = 1
    i += 1
# Judge status: Wrong Answer
a,b,c,x,y = map(int,input().split())

first = 2 * max(x,y) + 1
total = 5000 * 10 ** 5 * 2

for i in range(0,x+1):
    for j in range(0,y+1):
        k = 2 * max(x-i,y-j)
        if first > k :
            first = k
            target = a * i + b * j + c * k
            if total > target:
                    total = target
            else:
                continue
        else:
            break
    
print(total)
# Judge status: Wrong Answer
H,A=input().split()
H,A=int(H),int(A)
if max(A,H)<=10000 and min(A,H)>=1:
    print((int(H)//int(A)+1))
# Judge status: Accepted
n,m=[int(i) for i in input().split()]



if n!=1 and m!=1:
    print(max(0,(n-2)*(m-2)))
elif n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(max(n,m)-2)
# Judge status: Wrong Answer
n,x=map(int,input().split())
a=[int(i) for i in input().split()][::-1]
diff = []
for i in range(n-1):
    diff.append(a[i+1]+a[i])

c=0
#print(diff)
for i in range(n-2):
    if diff[i]>x:
        temp = diff[i+1] - x
        c += temp
        diff[i] -= temp
        diff[i+1] -= temp
if diff[-1] >x:
    c += diff[-1] - x
    diff[-1] = x

print(c)
# Judge status: Accepted
a, b = [input() for i in range(2)]
print("YES" if a[0]==b[2] and a[1]==b[1] and a[2]==b[0] else "NO")
# Judge status: Accepted
n = int(input())
s = input()
e_cnt = 0
for i in range(n):
    if s[i] == "E":
        e_cnt += 1
ans = e_cnt
w_cnt = 0
for i in range(n):
    if s[i] == "E":
        e_cnt -= 1
        
    ans = min(w_cnt + e_cnt, ans)
    if s[i] == "W":
        w_cnt += 1

print(ans)
# Judge status: Wrong Answer
N = int(input())
A = [[0 for i in range(11)] for j in range(11)]
for i in range(1, N):
  A[int(str(i)[0])][int(str(i)[-1])] +=1

B = [[0 for i in range(11)] for j in range(11)]
for i in range(1, N):
  B[int(str(i)[0])][int(str(i)[-1])] +=1
  
ans = 0
for i in range(10):
  for j in range(10):
    ans += A[i][j] * B[j][i]
  
print(ans)
# Judge status: Accepted
def readInts():
  return [int(i) for i in input().split()]


S = input()

if S[-1] == 's':
  print(S + 'es')
else:
  print(S + 's')
# Judge status: Wrong Answer
'''
Created on 2020/07/04

@author: fanta
'''
import numpy as np

N = int(input())

sum = 0

start = 0
end = 0
startL = []
endL = []
v = np.array([])

for n in range(N):
    start = n+1

    end = N - N%start

    if (start == end):
        sum += start
    else:
        startL.append(start)
        endL.append(end)

np_startL = np.array(startL)
np_endL = np.array(endL)

v = (np_endL - np_startL) // np_startL + 1
sum += np.sum((np_endL + np_startL) * v // 2)

print(sum)
# Judge status: Accepted
a=int(input())
if 400<=a and a<=599:
    print(8)
if 600<=a and a<=799:
    print(7)
if 800<=a and a<=999:
    print(6)
if 1000<=a and a<=1199:
    print(5)
if 1200<=a and a<=1399:
    print(4)
if 1400<=a and a<=1599:
    print(3)
if 1600<=a and a<=1799:
    print(2)
if 1800<=a and a<=1999:
    print(1)
# Judge status: Accepted
S=input()
ans=0
l=["hoge"]
j=0
for i in range(len(S)):
    if S[j:i+1]==l[-1]:
        continue
    else:
        l.append(S[j:i+1])
        ans+=1
        j=i+1
    #print(l)
print(ans)
# Judge status: Accepted
if __name__ == '__main__':

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

    ans = 0
    if k >= a:
        k -= a
        ans += a
    else:
        ans += k
        print(ans)
        exit()
    
    if k >= b:
        k -= b
    else:
        print(ans)
        exit()
    
    if k >= c:
        ans += c * (-1)
    else:
        ans += k * (-1)

    print(ans)
# Judge status: Accepted
import math
A,B,N = map(int,input().split())
C = N - N%B
ans = A*(C-1) // B - A*math.floor((C-1)/B)
if B > N:
    ans = math.floor(A*N/B) - A*math.floor(N/B)
print(ans)
# Judge status: Accepted
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]
r.extend(p)
r.extend(q)
r.sort()
print(sum(r[-(X + Y):]))
# Judge status: Wrong Answer
n=int(input())
lis=list(map(int,input().split()))
t,f=0,0
for i in lis:
  if i%2==0:
    t+=1
  if i%4==0:
    f+=1
if t+f>=n-1:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N=int(input())
 
a=0
w=0
t=0
r=0
 
for i in range(N):
  s=input()
  if s=="AC":
    a+=1
  elif s=="WA":
    w+=1
  elif s=="TLE":
    t+=1
  else:
    r+=1

print("AC ×",a)
print("WA ×",w)
print("TLE ×",t)
print("RE ×",r)
# Judge status: Accepted
a = int(input())
b = input().split()
b = [int(j) for j in b]
x = round(sum(b) / a)
y = []
for i in range(a):
    y.append((x - b[i])**2)
print(sum(y))
# Judge status: Wrong Answer
from math import ceil

N = int(input())

l = [None] * 5

for i in range(5):
    l[i] = int(input())

print(5 + ceil(N/min(l)))
# Judge status: Wrong Answer
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
  h[min(ab[i][0]-1, ab[i][1]-1)] = 0
  if h[ab[i][0]-1] == h[ab[i][1]-1]: h[ab[i][0]-1] = h[ab[i][1]-1] = 0
h = [i for i in h if i != 0]
print(len(h))
# Judge status: Accepted
n,m = map(int,input().split())
H = list(map(int,input().split()))
L = [1]*n
for _ in range(m):
  a,b = map(int,input().split())
  if H[a-1] == H[b-1]:
    L[a-1] = 0
    L[b-1] = 0
  elif H[a-1] < H[b-1]:
    L[a-1] = 0
  elif H[a-1] > H[b-1]:
    L[b-1] = 0
print(sum(L))
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
k=int(input())
l=[]
l.append((k+1)*a +b+c)
l.append((k+1)*b +a+c)
l.append((k+1)*c +a+b)
print(l)
# Judge status: Accepted
#宿泊数N,金額を表す計算用宿泊日数K,K泊目の金額X,K+1泊目の金額
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

if N<K:
    a=N*X
    b=0
else:
    a=K*X
    b=(N - K) * Y

print(a+b)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))

S = 0
for i in range(N):
    S = S ^ a[i]

num = []
for i in range(N):
    num.append(S ^ a[i])

ans = " ".join(map(str, num))
print(ans)
# Judge status: Accepted
a = list(map(int, input().split()))

if a[0] >= 10:
  print(a[1])
else:
  print(a[1] + 100 * (10 - a[0]))
# Judge status: Wrong Answer
n = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(n):
    if p[i]!=i+1:
        c+=1
print(c)
if c>2:
    print("NO")
else:
    print("YES")
# Judge status: Wrong Answer
n = int(input())
a_L = list(map(int,input().split()))


if len(a_L) == 1:
    print(0)
    exit()

ans = 0
for i in range(0,len(a_L)-1):
    if a_L[i] > a_L[i+1]:
        ans += abs(a_L[i+1] - a_L[i])
        a_L[i+1] = a_L[i]

if a_L[-1] > a_L[-2]:
    ans += abs(a_L[-1]-a_L[-2])
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if (a+b) % 3 == 0 or a % 3 == 0 or b % 3 == 0:
  print("Possible")
else:
  print("Impossible")
# Judge status: Accepted
# B - AtCoder Beginner Contest 111

import bisect

N = int(input())
arr = [111, 222, 333, 444, 555, 666, 777, 888, 999]
ans_idx = bisect.bisect_left(arr, N)
print(arr[ans_idx])
# Judge status: Accepted
s = input()
if ("S" in s and not "N" in s) or ("N" in s and not "S" in s) or ("E" in s and not "W" in s) or ("W" in s and not "E" in s):
    print("No")
else:
    print("Yes")