Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
a_list = []
max_v = -1
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]==max_v:
        max_ind.append(i)
del a_list[max_ind[-1]]
sec = max(a_list)
for i in range(N):
    if i in max_ind:
        print(sec)
    else:
        print(max_v)
        

### FIXED CODE ###

N = int(input())
a_list = []
max_v = -1
sec = -1
tmp = 0
drop = False
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        tmp = max_v
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]<max_v:
        if a_list[-1]>sec:
            drop = True
            sec = a_list[-1]
    else:
        max_ind.append(i)
if len(max_ind)>1:
    for i in range(N):
        print(max_v)
elif drop:
    for i in range(N):
        if i in max_ind:
            print(sec)
        else:
            print(max_v)
else:
    for i in range(N):
        if i in max_ind:
            print(tmp)
        else:
            print(max_v)
### BUGGY CODE ###

n,p=map(int,input().split())
a=[i for i in range(int(p**(1/n))+1)]
a[1]=0
b=int(p**0.5)
for j in a:
    if j>b:
        break
    elif j==0:
        continue
    for k in range(2*j,len(a),j):
        a[k]=0
c=[l for l in a if l!=0]
for m in range(len(c)):
    d=0
    while p%c[m]==0:
        p//=c[m]
        d+=1
    c[m]=[c[m],d]
e=1
for v in c:
    e*=v[0]**(v[1]//n)
print(e)

### FIXED CODE ###

n,p=map(int,input().split())
if n==1:
    print(p)
    quit()
a=[i for i in range(int(p**(1/n))+1)]
a[1]=0
b=int(p**0.5)
for j in a:
    if j>b:
        break
    elif j==0:
        continue
    for k in range(2*j,len(a),j):
        a[k]=0
c=[l for l in a if l!=0]
for m in range(len(c)):
    d=0
    while p%c[m]==0:
        p//=c[m]
        d+=1
    c[m]=[c[m],d]
e=1
for v in c:
    e*=v[0]**(v[1]//n)
print(e)
### BUGGY CODE ###

def main():
    n, k, q, *al = map(int, open(0).read().split())
    gl = [k for _ in range(n)]
    for a in al:
        gl = [
            g if i == a-1
            else g-1
            for i, g in enumerate(gl)
        ]

    res = '\n'.join(
        'No' if g <= 0
        else 'Yes'
        for g in gl
    )
    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, k, q, *al = map(int, open(0).read().split())
    gl = [0] * n
    for a in al:
        gl[a-1] += 1

    res = '\n'.join(
        'Yes' if g > q-k
        else 'No'
        for g in gl
    )
    print(res)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import fractions
N, M = list(map(int, input().split()))
S = input()
T = input()

L = int(N * M / fractions.gcd(N, M))
LN = int(L / N)
LM = int(L / M)

count = 0
dic1 = {LN*n:S[n] for n in range(N)}
dic2 = {LM*n:T[n] for n in range(M)}

for n in range(L):
    if (n in dic1) and (n in dic2) and dic1[n] != dic2[n]:
        count += 1
        break

if count == 0:
    print(L)
else:
    print('-1')


### FIXED CODE ###

import fractions
N, M = list(map(int, input().split()))
S = input()
T = input()

L = int(N * M / fractions.gcd(N, M))
LN = int(L / N)
LM = int(L / M)

count = 0
dic1 = {LN*n:S[n] for n in range(N)}
dic2 = {LM*n:T[n] for n in range(M)}

for k in dic1.keys():
    if k in dic2 and dic1[k] != dic2[k]:
        count += 1
        print(-1)
        break

if count == 0:
    print(L)
### BUGGY CODE ###

#multiple 
line = input()
n = len(line)
total = 0
for i in range(n-3):
    for j in range(i +3,n):
        if int(line[i:j+1])%2019 == 0:
            total +=1
            
print(total)

### FIXED CODE ###

# multiple
line = input()
ln = 0
d = 1
counts=[0]*2019
for i in range(1,len(line) + 1):
    ti1 = (ln +(int(line[-1*i])*d))%2019
    counts[ti1] += 1
    ln = ti1
    d *= 10
    d %= 2019
total = 0
counts[0] +=1
for i in range(len(counts)):
    total += counts[i]*(counts[i] - 1)/2
print(int(total))
### BUGGY CODE ###

def combination(n, r):
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result


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

NM = N * M
fa = [1] * (NM + 1)

for i in range(1, NM + 1):
    fa[i] = (fa[i - 1] * i) % mod

ans = 0
for i in range(1, N):
    ans += i * M * M * (N - i)
    ans %= mod

for i in range(1, M):
    ans += i * N * N *(M-i)
    ans %= mod

ans *= combination(NM-2, K-2)
ans %= mod
print(ans)


### FIXED CODE ###

class FactMod:

    def __init__(self, n, mod):
        self.mod = mod
        self.f = [1] * (n + 1)
        for i in range(1, n + 1):
            self.f[i] = self.f[i - 1] * i % mod

        self.inv = [pow(self.f[-1], mod - 2, mod)]
        for i in reversed(range(1, n + 1)):
            self.inv.append(self.inv[-1] * i % mod)
        self.inv.reverse()

    def fact(self, n):
        """
        :return: n!
        """
        return self.f[n]

    def comb(self, n, r):
        """
        :return: nCr
        """
        return self.f[n] * self.inv[n - r] * self.inv[r] % self.mod

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

NM = N * M
fa = [1] * (NM + 1)

for i in range(1, NM + 1):
    fa[i] = (fa[i - 1] * i) % mod

ans = 0
for i in range(1, N):
    ans += (i * M * M * (N - i)) % mod
    ans %= mod

for i in range(1, M):
    ans += (i * N * N *(M-i)) % mod
    ans %= mod

factmod = FactMod(NM-2, mod)
ans *= factmod.comb(NM-2, K-2)
ans %= mod
print(ans)
### BUGGY CODE ###

# Input N, Q
N, Q = [int(c) for c in input().split()]

# Input edges
edges = [[] for i in range(N)]
for i in range(N-1):
    u, v = [int(c)-1 for c in input().split()]
    edges[u].append(v)
    edges[v].append(u)

# Form tree
parent = [None for i in range(N)]
childs = [[] for i in range(N)]
def dfs(root):
    parent[root] = -1
    stack = [root]
    while stack:
        now = stack.pop()
        for nex in edges[now]:
            if parent[nex] is None:
                parent[nex] = now
                childs[now].append(nex)
                stack.append(nex)
dfs(0)

# Queries
incremented = [0 for i in range(N)]
for i in range(Q):
    v, add = [int(c) for c in input().split()]
    v -= 1
    incremented[v] += add

# Lower propagate
total = [0 for i in range(N)]
def propagate(root):
    global total
    stack = [root]
    while stack:
        now = stack.pop()
        total[now] += incremented[now]
        for child in childs[now]:
            total[child] += total[now]
            stack.append(child)
propagate(0)

# Print
print(" ".join(str(num) for num in total))
    


### FIXED CODE ###

def main():

    # Input N, Q
    N, Q = [int(c) for c in input().split()]

    # Input edges
    edges = [[] for i in range(N)]
    for i in range(N-1):
        u, v = [int(c)-1 for c in input().split()]
        edges[u].append(v)
        edges[v].append(u)

    # Form tree
    parent = [None for i in range(N)]
    childs = [[] for i in range(N)]
    def dfs(root):
        parent[root] = -1
        stack = [root]
        while stack:
            now = stack.pop()
            for nex in edges[now]:
                if parent[nex] is None:
                    parent[nex] = now
                    childs[now].append(nex)
                    stack.append(nex)
    dfs(0)

    # Queries
    incremented = [0 for i in range(N)]
    for i in range(Q):
        v, add = [int(c) for c in input().split()]
        v -= 1
        incremented[v] += add

    # Lower propagate
    total = [0 for i in range(N)]
    def propagate(root):
        stack = [root]
        while stack:
            now = stack.pop()
            total[now] += incremented[now]
            for child in childs[now]:
                total[child] += total[now]
                stack.append(child)
    propagate(0)

    # Print
    print(" ".join(str(num) for num in total))

main()
### BUGGY CODE ###

n, m = map(int, input().split())
a = [list(map(int,input().split())) for i in range(m)]
p = [[]for i in range(n)]
for i,arr in enumerate(a): p[arr[0]-1].append(arr[1])
for i in range(n): p[i].sort()
for i,j in a:
	high6 = str(i).zfill(6)
	low6 = str(p[i-1].index(j)+1).zfill(6)
	print(high6+low6)

### FIXED CODE ###

from sys import stdin
input = stdin.readline
n, m = map(int, input().split())

ans = sorted([list(map(int, input().split()))+[i] for i in range(m)], key=lambda x:x[1])

built = [1]*n
for i in range(m):
    ans[i][1] = built[ans[i][0]-1]
    built[ans[i][0]-1] += 1

for i in sorted(ans,key=lambda x:x[2]): print("%06d%06d" % (i[0],i[1]))
### BUGGY CODE ###

N = int(input())
nums = [int(e) for e in input().split()]

for i in range (1,N+1):
    c = 0
    for j in range(0,N-1):
        if nums[j] == i:
            c = c + 1
    print(c)

### FIXED CODE ###

import collections as col

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

List = col.Counter(List)
Count_List = [0]*n
for i in List:
    Count_List[i-1] = List[i]

for i in range(0,len(Count_List)):
    print(Count_List[i])
### BUGGY CODE ###

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

XH = sorted(XH)

for i in range(N):
    XH[i][1] = (XH[i][1] + A - 1) // A

adjust = [0 for _ in range(N + 1)]

ans = 0
done = 0

for i in range(N):
    done -= adjust[i]
    XH[i][1] -= done
    if XH[i][1] < 0: continue

    v = XH[i][0] + 2 * D
    ng = 0
    ok = N
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if XH[mid][0] > v: ok = mid
        else: ng = mid

    ans += XH[i][1]
    done += XH[i][1]
    adjust[ok] += XH[i][1]

print(ans)

### FIXED CODE ###

import sys
N, D, A = map(int, sys.stdin.readline().split())
XH = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

XH = sorted(XH)

for i in range(N):
    XH[i][1] = (XH[i][1] + A - 1) // A

adjust = [0 for _ in range(N + 1)]

def findi(v):
    ng = 0
    ok = N
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if XH[mid][0] > v: ok = mid
        else: ng = mid
    return ok

ans = 0
done = 0

for i in range(N):
    done -= adjust[i]
    XH[i][1] -= done
    if XH[i][1] < 0: continue

    ans += XH[i][1]
    index = findi(XH[i][0] + D * 2)
    done += XH[i][1]
    adjust[index] += XH[i][1]

print(ans)
### BUGGY CODE ###

a, b, c, d = map(int, input().split())
cnt = 0
for i in range(a,b+1):
   if i%c != 0 and i%d != 0:
      cnt += 1
print(cnt)

### FIXED CODE ###

a, b, c, d = map(int, input().split())
def gcd(a,b):
   while b != 0:
      a, b = b, a%b
   return a
def lcm(a,b):
   return int(a*b / gcd(a,b))
cnt = 0
quo_c = b//c - (a-1)//c
quo_d = b//d - (a-1)//d
quo_cd = b//lcm(c,d) - (a-1)//lcm(c,d)
print(b - (a-1) - quo_c - quo_d + quo_cd)
### BUGGY CODE ###

from sys import stdin

readline = stdin.readline


def ns():
    """
    入力を`[\\s]`を除いて文字列として取得
    """
    return readline().rstrip()


def ni():
    """
    入力を`int`に変換
    """
    return int(ns())


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *a = nf()
    for i in range(n):
        tmp = a[:]
        tmp.pop(i)
        print(max(tmp))


if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin

readline = stdin.readline


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *al = nf()
    s, f = sorted(al)[-2:]
    if s == f:
        for _ in range(n):
            print(f)
        return
    for a in al:
        if a == f:
            print(s)
            continue
        print(f)


if __name__ == "__main__":
    main()
### BUGGY CODE ###


N = int(input())


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

s=1
for i in A:
    s=s*i

if s>10**(18):
    print(-1)
else:
    print(s)

### FIXED CODE ###


N = int(input())


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

s=1

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

    if s > 10 ** (18):
        print(-1)
    else:
        print(s)
### BUGGY CODE ###

n = int(input())
s = list(input())

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B

for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if k < n:
      if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):
        tot -= 1

print(tot)

### FIXED CODE ###

n = int(input())
s = input()

arr = []
R = len(list(filter(lambda x:x == 'R', s)))
G = len(list(filter(lambda x:x == 'G', s)))
B = len(list(filter(lambda x:x == 'B', s)))
tot = R*G*B

for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if k >= n:
      continue
    if (s[i] != s[j]) and (s[i] != s[k]) and (s[j] != s[k]):
      tot -= 1

print(tot)
### BUGGY CODE ###

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


for i in range(n):
  for j in range(n):
    if a[j]==i+1:
      print(j+1)
      break

### FIXED CODE ###

import numpy as np
n=int(input())
a=list(map(int,input().split()))
  
x = np.argsort(a)
for i in range(n):
  print(x[i]+1)
### BUGGY CODE ###

K=int(input())
cnt=0
ans=0
while cnt<1000001:
  cnt+=1
  ans=(ans*10)+7
  if ans%K==0:
    print(cnt)
    break
else:
  print(-1)

### FIXED CODE ###

K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

def dfs(v,p=-1):
  for u in graph[v]:
    if u == p: continue
    ans[u] += ans[v]
    dfs(u,v)

N,Q = map(int,input().split())
graph = [[] for i in range(N+1)]
ans = [0 for i in range(N+1)]
for _ in range(N-1):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)

for _ in range(Q):
  p, x = map(int,input().split())
  ans[p] += x

dfs(1)
print(*ans[1:])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input=lambda :sys.stdin.readline()

def sol():

  N,Q = map(int,input().split())
  graph = [[] for i in range(N)]
  ans = [0 for i in range(N)]
  for _ in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

  for _ in range(Q):
    p, x = map(int,input().split())
    ans[p-1] += x 
 
  def dfs(v,p=-1):
    for u in graph[v]:
      if u == p: continue
      ans[u] += ans[v]
      dfs(u,v)
  dfs(0)
  print(*ans)

sol()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
H,W,K = map(int,input().split())
r1,c1,r2,c2 = map(lambda x:int(x)-1,input().split())
C = [input() for i in range(H)]

def solve():
    from collections import deque
    dxy = [(0,1),(1,0),(0,-1),(-1,0)]
    INF = float('inf')
    dists = [[INF]*W for _ in range(H)]
    dists[r1][c1] = 0
    q = deque([(r1,c1)])
    while q:
        y,x = q.popleft()
        if y==r2 and x==c2:
            print(dists[y][x])
            exit()
        for dx,dy in dxy:
            for i in range(1,K+1):
                nx,ny = x+dx*i,y+dy*i
                if not 0 <= nx < W: break
                if not 0 <= ny < H: break
                if C[ny][nx] == '@': break
                if dists[ny][nx] <= dists[y][x] + 1: continue
                if dists[ny][nx] <= dists[y][x] + 2: break # gori~~
                dists[ny][nx] = dists[y][x] + 1
                q.append((ny,nx))
    print(-1)
solve()

### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W,K = map(int,input().split())
r1,c1,r2,c2 = map(lambda x:int(x)-1,input().split())
C = [input() for i in range(H)]

def solve():
    from collections import deque
    dxy = [(0,1),(1,0),(0,-1),(-1,0)]
    INF = float('inf')
    dists = [[INF]*W for _ in range(H)]
    dists[r1][c1] = 0
    q = deque([(r1,c1)])
    while q:
        y,x = q.popleft()
        if y==r2 and x==c2:
            print(dists[y][x])
            exit()
        for dx,dy in dxy:
            for i in range(1,K+1):
                nx,ny = x+dx*i,y+dy*i
                if not 0 <= nx < W: break
                if not 0 <= ny < H: break
                if C[ny][nx] == '@': break
                if dists[ny][nx] <= dists[y][x]: break
                if dists[ny][nx] <= dists[y][x] + 1: continue
                dists[ny][nx] = dists[y][x] + 1
                q.append((ny,nx))
    print(-1)
solve()
### BUGGY CODE ###

n = int(input())

tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

stack=[1]
visitted=[]
ans=[0]*(n+1)

while stack:
    cur = stack.pop()
    visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        if w % 2 == 1:
            ans[v]=(ans[cur]+1)%2
        else:
            ans[v]=ans[cur]
        stack.append(v)

for i in ans[1:]:
    print(i)


### FIXED CODE ###

n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

#print(tree)
stack=[1]
visitted={}
ans=[0]*n

while stack:
    cur = stack.pop()
    pre=ans[cur-1]
    visitted.setdefault(cur,1)
    #visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        if w % 2 == 1:
            ans[v-1]=(pre+1)%2
        else:
            ans[v-1]=pre
        stack.append(v)

print(*ans, sep='\n')
### BUGGY CODE ###

def main():
    l, r = map(int, input().split())
    mi = 2019
    c = 0

    for i in range(l, r):
        a = (i*i) % 2019
        for _ in range(min(r-l-c, 2019)):
            a = (a+i) % 2019

            if a < mi:
                mi = a
                if a == 0:
                    break
        c += 1

    print(mi)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    l, r = map(int, input().split())
    mi = 2019
    c = 0

    for i in range(l, r):
        a = (i*i) % 2019
        for _ in range(min(r-l-c, 2019)):
            a = (a+i) % 2019

            if a < mi:
                mi = a
                if a == 0:
                    print(0)
                    return 
        c += 1

    print(mi)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

def main():
    X = int(input())
    a = 0
    b = 0
    if X != 1:
        for i in range(2, 10**9):
            if X % i == 0:
                a = i
                b = X // i
                break
    else:
        a = 1
        b = 1
    #print(a, b)
    for y in range(10**9):
        x = y + a
        if x**5 - y**5 == X:
            print(x, y)
            break
        x = y + b
        if x**5 - y**5 == X:
            print(x, y)
            break
        y *= -1
        x = y + a
        if x**5 - y**5 == X:
            print(x, y)
            break
        x = y + b
        if x**5 - y**5 == X:
            print(x, y)
            break
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    X = int(input())
    for A in range(-119, 119):
        flag = False
        for B in range(-119, 119):
            if A**5 - B**5 == X:
                print(A, B)
                flag = True
                break
        if flag:
            break
if __name__ == '__main__':
    main()
### BUGGY CODE ###

k,s=map(int,input().split())
c=0
for i in range(k+1):
  for j in range(k+1):
    for k in range(k+1):
      if i+j+k==s:
        c=c+1
print(c)

### FIXED CODE ###

k,s=map(int,input().split())
c=0
for i in range(k+1):
  for j in range(k+1):
    if 0<=s-i-j<=k:
      c=c+1
print(c)
### BUGGY CODE ###

N, K = map(int, input().split())
As = list(map(int, input().split()))
M = [[] for i in range(200001)]
for i, a in enumerate(As):
  M[a].append(i)
S = []
for i, a in enumerate(As):
  l = M[a]
  index = l.index(i)
  if index+1 == len(l):
    n = l[0]+N+1
  else:
    n = l[index+1]+1
  S.append((n//N, n%N))
#print(S)
count = 0
p = 0
while True:
  c, p = S[p]
  count += c
  if p == 0:
    break
#print(count)
K = K%count
#print(K)
s = []
for k in range(K):
  for a in As:
    i = -1
    for j in range(len(s)):
      if s[j] == a:
        i = j
    if i < 0:
      s.append(a)
    else:
      s = s[0:i]
print(" ".join(map(str, s)))


### FIXED CODE ###

N, K = map(int, input().split())
As = list(map(int, input().split()))
M = [[] for i in range(200001)]
for i, a in enumerate(As):
  M[a].append(i)
S = []
for i, a in enumerate(As):
  l = M[a]
  index = l.index(i)
  if index+1 == len(l):
    n = l[0]+N
  else:
    n = l[index+1]
  S.append(n+1-i)
#print(S)
p = 0
while True:
  p = p+S[p%N]
  if p%N == 0:
    break
count = p//N
#print(count)
K = K%count
#print(K)
p = 0
s = []
while p < N*K:
  q = p+S[p%N]
  if q > N*K:
    s.append(As[p%N])
    p = p+1
  else:
    p = q
print(" ".join(map(str, s)))
### BUGGY CODE ###

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

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

c=0

for i in range(n-1):
    while a[i]+a[i+1]>x:
        if a[i+1]>0:
            a[i+1]-=1
        else:
            a[i]-=1
        c+=1

print(c)


### FIXED CODE ###

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

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

c=0

for i in range(n-1):
    if a[i]+a[i+1]>x:
        c+=a[i]+a[i+1]-x
        if x-a[i]>=0:
            a[i+1]=x-a[i]
        else:
            a[i+1]=0
            a[i]=x

print(c)
### BUGGY CODE ###

a, b, n = map(int, input().split())
ans = 0
if n < b-1:
    ans = ((a*n)//b - a*(n//b))
else:
    for i in range(b-1, n+1, b):
        ans = max(ans, (a*i)//b - a*(i//b))
print(ans)
        

### FIXED CODE ###

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

c = int(a*n/b) - a*int(n/b)

if n < b:
    print(c)
else:
    c = int(a*(b-1)/b) - a*int((b-1)/b)
    print(c)
### BUGGY CODE ###

import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#１回のクエリで半分に空席がある場所を絞る
end = ri() - 1
print(0, flush=True)
S = input()[0]
if S == 'V':
    exit()
start = 0
cur = S
for _ in range(19):
    target = start + max(2, (end - start) // 4 * 2)
    print(target, flush=True)
    s = input()[0]
    if s == 'V':
        exit()
    if cur != s:
        end = target
    else:
        start = target
print(start + 1, flush=True)
s = input()[0]
if s == 'V':
    exit()
else:
    print(start + 2, flush=True):
    exit()
#24


### FIXED CODE ###

N = int(input())

def ask(n):
    print(n, flush=True)
    resp = input().rstrip()[0]
    if resp == 'V':
        exit()
    return resp

def condition(L,R,resp_L,resp_R):
    if (R-L)&1:
        return resp_L == resp_R
    else:
        return resp_L != resp_R

resp = ask(0)

L = 0
R = N
resp_L = resp
resp_R = resp
for _ in range(19):
    M = (L + R) // 2
    resp_M = ask(M)
    if condition(L,M,resp_L,resp_M):
        R,resp_R = M,resp_M
    else:
        L,resp_L = M,resp_M
### BUGGY CODE ###

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

for i in range(1,n+1):
    print(a.count(i))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
cnt = [0] * n
for i in a:
    cnt[i-1] += 1
for j in cnt:
    print(j)
### BUGGY CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
  b,c=map(int,input().split())
  a.extend([c]*min(b,10**5))
a.sort(reverse=True)
print(sum(a[:n]))


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
d=[]
ans=0
for i in range(n):
  d.append([a[i],1])
for i in range(m):
  b,c=map(int,input().split())
  d.append([c,b])
d.sort(reverse=True)
for i in range(n+m):
  if n==0:
    break
  ans+=d[i][0]*min(n,d[i][1])
  n-=min(n,d[i][1])
print(ans)