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

import itertools

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


ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        v1 = a_l[i]
        v2 = a_l[j]
        
        ans += v1 * v2
        ans = ans % (10 ** 9 + 7)

print(ans)

### FIXED CODE ###

n = int(input())
a_list = input().split()

a_list_reverse = a_list[::-1]
# print(a_list_reverse)

rusekiwa = [0] * (len(a_list_reverse) - 1)
sum_v = 0
for i in range(len(a_list_reverse) - 1):
    sum_v += int(a_list_reverse[i])
    rusekiwa[i] = sum_v
# print(rusekiwa)

ans = 0
for i in range(len(a_list) - 1):
    v = int(a_list[i]) * rusekiwa[-1 - (i)]
    # print(v)
    # v = v % (10 ** 9 + 7)
    ans += v
    ans = ans % (10 ** 9 + 7)

# ans = ans % (10 ** 9 + 7)
print(ans)
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
hL = deque(list(map(int, input().split())))
for i in range(n-1):
    for j in range(i+1, n) :
        if hL[i] >hL[j]:
            hL[i]-=1
            break
if list(hL) ==sorted(hL):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n = int(input())

L = np.array(list(map(int, input().split())))

for i in range(n-1, 0, -1):
    if L[i]-L[i-1] ==-1:
        L[i-1] -=1

if np.all(L ==sorted(L)):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
m = max(a)
n = 0
j = 1
while j <= m:
    c = a.count(j)
    if c%2 == 1:
        n += 1
        j += 1
    else:
        j += 1
print(n)


### FIXED CODE ###

N = int(input())
a = []
for i in range(N):
    a.append(input())
a.sort()
b = []
b.append(1)
j =1
k = 0
while j < N:
  if j == N:
    break
  elif a[j-1] == a[j]:
    b[k] += 1
    j += 1
  elif a[j-1] != a[j]:
    b.append(1)
    k += 1
    j += 1
ans = 0
for c in b:
  if c %2==1:
    ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
L = sorted(list(map(int, input().split())))

res = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[k] < L[i] + L[j]:
                res += 1
            else:
                break

print(res)


### FIXED CODE ###

import bisect

N = int(input())
L = sorted(list(map(int, input().split())))

res = 0
for i in range(N):
    for j in range(i+1, N):
        idx = bisect.bisect_left(L, L[i]+L[j])
        res += max(0, idx-j-1)

print(res)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def small_dp(N,X):
    if len(X) == 0:
        return N
    if len(X) == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if len(X) == 2:
        return max(X[0][1]*i + X[1][1]*((N-i*X[0][0])//X[1][0]) + (N-i*X[0][0])%X[1][0] for i in range(N//X[0][0]+1))
    if len(X) == 3:
        return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))
        
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    for C in ((A,B), (B,A)):

        *X, = filter(lambda c: int.__sub__(*c)<0, zip(*C))
        N = small_dp(N, X)
    res = N

    return str(res)

if __name__ == '__main__':
    print(solve())

### FIXED CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def small_dp(N,A,B):
    *X, = filter(lambda c: int.__sub__(*c)<0, zip(A,B))
    k = len(X)
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k == 3:
        if (N//X[1][0]+1)*(N//X[0][0]+1) <= 10**6 :
            return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))
        else:
            import numpy as np
            dp = np.zeros(N+1, dtype=int)
            for w in range(1,N+1):
                dp[w] = max(dp[w-X[i][0]]+X[i][1] if w>=X[i][0] else w for i in range(k))
            N = dp[-1]
            return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    res = small_dp(small_dp(N, A, B), B, A)

    return str(res)

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    count=0
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        X_=[]
        X_.append(x)
        for y in Y:
            X_Y_=[]
            X_Y_=X_.copy()
            X_Y_.append(y)
            for z in Z:
                X_Y_Z_=X_Y_.copy()
                X_Y_Z_.append(z) 
                wa_=sum(X_Y_Z_)
                wa.append(wa_)
    for j in wa:
        if j==S:
            count+=1
    print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        if S-(x+y)>=0 and S-(x+y)<=K: count+=1
print(count)
### BUGGY CODE ###

class Dict(object):

    m1 = 2 ** 15 - 1
    m2 = m1 - 1

    def __init__(self):
        self._dict = ["" for _ in range(self.m1)]

    def insert(self, k):
        i = 0

        while True:
            ix = self._h(k, i)
            if self._dict[ix] == "":
                self._dict[ix] = k
                return
            else:
                i += 1

    def find(self, k):
        i = 0

        while True:
            ix = self._h(k, i)
            if self._dict[ix] == k:
                return ix
            elif self._dict[ix] == "":
                return -1
            else:
                i += 1

    def _h(self, k, i):
        return (self._h1(k) + i * self._h2(k)) % self.m1

    def _h1(self, k):
        return k % self.m1

    def _h2(self, k):
        return k % self.m2 + 1


def to_int(s):
    _s = s[::]

    ret = 0
    i = 1
    for e in _s:
        if e == 'A':
            ret += 1 * i
        elif e == 'C':
            ret += 2 * i
        elif e == 'G':
            ret += 3 * i
        elif e == 'T':
            ret += 4 * i
        i *= 4

    return ret


if __name__ == '__main__':
    n = int(input())

    d = Dict()

    for _ in range(n):
        cmd, val = input().split()

        if cmd == "insert":
            d.insert(to_int(val))
        else:
            ans = "yes" if d.find(to_int(val)) != -1 else "no"
            print(ans)

### FIXED CODE ###

M = 1046527
L = 14
H = [""] * M
 
def getChar(ch):
    if ch == 'A':
        return 1
    elif ch == 'C':
        return 2
    elif ch == 'G':
        return 3
    elif ch == 'T':
        return 4
    else:
        return 0
 
def getKey(strings):
    Sum = 0
    p = 1
    for i in xrange(len(strings)):
        Sum += p * getChar(strings[i])
        p *= 5
 
    return Sum
 
def h1(key):
    return key % M
 
def h2(key):
    return 1 + (key % (M-1))
 
def find(strings):
    key = getKey(strings)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == strings:
            return 1
        elif len(H[h]) == 0:
            return 0
        else:
            i += 1
    return 0
 
def insert(strings):
    key = getKey(strings)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == strings:
            return 1
        elif len(H[h]) == 0:
            H[h] = strings
            return 0
        else:
            i += 1
    return 0
 
def main():
    n = input()
    for i in xrange(n):
        com = raw_input().split()
        if com[0][0] == 'i':
            insert(com[1])
        else:
            if find(com[1]):
                print 'yes'
            else:
                print 'no'
    return 0
 
main()
### BUGGY CODE ###

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

MOD = 10**9 + 7
A_mod = [a%MOD for a in A]

ans = 0

for i in range(1, N):
    ans = (ans + A_mod[i-1]%MOD * sum(A_mod[i:])%MOD)%MOD
    
print(ans)

### FIXED CODE ###

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

MOD = 10**9 + 7
A_mod = [a%MOD for a in A]

R = sum(A_mod)

ans = 0

for a in A_mod:
    R -= a
    ans = (ans + a%MOD * R%MOD)%MOD
    
print(ans)
### BUGGY CODE ###

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

s_r = []
s_g = []
s_b = []

srappend = s_r.append
sgappend = s_g.append
sbappend = s_b.append

for i in range(n):
  if s[i] == "R":
    srappend(i)
  elif s[i] == "G":
    sgappend(i)
  else:
    sbappend(i)

ans = 0
    
def conditions(a, b):
  if (a+b) % 2 == 0:
    x = (a+b) / 2
    y = 2*b - a
    z = 2*a - b
  else:
    x = -1
    y = 2*b - a
    z = 2*a - b
  return (x, y, z)
  
for item in s_r:
  for item2 in s_g:
    count = 0
    for i in conditions(item, item2):
      if i in s_b:
        count += 1
    ans += len(s_b) - count

print(ans)

### FIXED CODE ###

import collections

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

aaa = collections.Counter(s)
s_r = aaa["R"]
s_g = aaa["G"]
s_b = aaa["B"]

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = s[i]
      b = s[j]
      c = s[k]
      if noteq(a, b, c):
        ans -= 1
    
print(ans)
### BUGGY CODE ###

ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD=10**9+7

N,M=rl()
A=rl()
B=[0]*M
C=[0]*M
for i in range(M):
    B[i],C[i]=rl()

for b,c in zip(B,C):
    A.extend([c]*b)

A.sort(reverse=True)
print(sum(A[:N]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD=10**9+7

N,M=rl()
A=rl()
B=[0]*M
C=[0]*M
for i in range(M):
    B[i],C[i]=rl()


D = []
for a in A:
    D.append([a,1])
for b,c in zip(B,C):
    D.append([c,b])

D.sort(reverse=True)

ans = 0
cnt = N
for val,num in D:
    if cnt >= num:
        cnt -= num
        ans += val*num
    else:
        ans += val*cnt
        break
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(4100000)

N = int(input())
a = list(map(int, input().split()))
b = []
if N > 10 ** 5:
  for i in range(N, 10 ** 5, -1):
    if a[i - 1] == 1:
      b.append(i)
for i in range(min(10 ** 5, N), 0, -1):
  j = i * 2
  s = a[i - 1]
  while j <= N:
    if j in b:
      s += 1
    j += i
  if s % 2 == 1:
  	b.append(i)
print(len(b))
print(*b)


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
b = []
arr = [-1] * N
for i in range(N, 0, -1):
  s = 0
  j = i * 2
  while j <= N:
    s += arr[j - 1]
    j += i
  if s % 2 != a[i - 1]:
    arr[i - 1] = 1
    b.append(i)
  else:
    arr[i - 1] = 0
print(len(b))
print(*b)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    for i in range(n):
        if a[i]==b:
            a[i]=c
    print(sum(a))

### FIXED CODE ###

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

count=[0]*(10**5+1)

for i in a:
    count[i]+=1

for i in range(q):
    b,c=map(int,input().split())
    if count[b]!=0:
        sum+=(c-b)*count[b]
        count[c]+=count[b]
        count[b]=0
    print(sum)
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
for i in range(N):
    A2 = A.copy()
    A2[i] = 0
    print(max(A2))

### FIXED CODE ###

import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()
### BUGGY CODE ###

import math

N = int(input())

ans = 0
for i in range(1, N + 1):
  for j in range(1, N + 1):
    for k in range(1, N + 1):
      ans += math.gcd(math.gcd(i, j), k)
print(ans)

### FIXED CODE ###

import math

N = int(input())

ans = 0
for i in range(1, N + 1):
  for j in range(1, N + 1):
    for k in range(1, N + 1):
      ans += math.gcd(math.gcd(i, j), k)
print(ans)
### BUGGY CODE ###

tmp = list(map(int, input().split()))
h = tmp[0]
w = tmp[1] 

s = ['None'] * (h + 1)
for i in range(h):
  s[i] = input()
  s[i] = s[i] + '#'
s[h] = '#' * w

ans = 0

sta = -1
cnt = 0
pt = [[0] * w for i in range(h)]
for i in range(h):
  for j in range(w+1):
    if s[i][j] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[i][k] = cnt
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

for i in range(w):
  for j in range(h+1):
    if s[j][i] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[k][i] += cnt - 1
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

ans = 0
for i in range(h):
  for j in range(w):
    if ans < pt[i][j]:
      ans = pt[i][j]
print(ans)


### FIXED CODE ###

tmp = list(map(int, input().split()))
h = tmp[0]
w = tmp[1] 

s = ['None'] * (h + 1)
for i in range(h):
  s[i] = input()
  s[i] = s[i] + '#'
s[h] = '#' * w

ans = 0

sta = -1
cnt = 0
pt = [[0] * w for i in range(h)]
for i in range(h):
  for j in range(w+1):
    if s[i][j] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[i][k] = cnt
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

for i in range(w):
  for j in range(h+1):
    if s[j][i] == '#':
      if sta != -1:
        for k in range(sta, j):
          pt[k][i] += cnt - 1
          if pt[k][i] > ans:
            ans = pt[k][i]
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

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

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

import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

l = np.zeros((n,n),dtype=int)

for i in range(n-1):
    l[i][i+1] = 1
    l[i+1][i] = 1

l[x-1][y-1] = 1
l[y-1][x-1] = 1

a = shortest_path(l)
# print(a)
b = np.triu(a)
# print(b)
c = b.reshape(1,n**2)
# print(c[0])
d = list(map(int,c[0]))

e = [ i for i in d if i!=0 ]
print(n)
for i in range(2,n):
    print(e.count(i))

### FIXED CODE ###

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

l = [0]*n

x -= 1
y -= 1

for i in range(n):
    for j in range(i+1,n):
        a = j - i
        if i<=x:
            b1 = x - i
        else:
            b1 = i - x
        if j<=y:
            b2 = y - j
        else:
            b2 = j - y
        b = b1 + b2 + 1
        l[min(a,b)] += 1

for i in range(1,n):
    print(l[i])
### BUGGY CODE ###

N,M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

A = sorted(A,reverse=True)
#print(A)

for i in range(M):
    A[0] //= 2
    A = sorted(A,reverse=True)

ans = 0
for i in A:
    ans += i

print(ans)




### FIXED CODE ###

N,M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

A = sorted(A,reverse=True)
#print(A)
X = M
for i in range(M):
    A[0] //= 2
    X -= 1
    count = 0
    for j in range(min(N-1,M)):
        if A[j] < A[j+1]:
            x = A[j]
            A[j] = A[j+1]
            A[j+1] = x
            count += 1
        else:
            break
            
    if count >= X:
        for j in range(X):
            A[j] //= 2
        break
    else:
        for j in range(count):
            A[j] //= 2
        X -= count
        A = sorted(A,reverse=True)
        
        
ans = 0
for i in A:
    ans += i

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

n=int(input())
arr=list(map(int, input().split()))
mul=1
done=False
for i in range(len(arr)):
  mul*=arr[i]
if mul>int(1e18):
  print("-1")
else:
  print(mul)

### FIXED CODE ###

n=int(input())
arr=list(map(int, input().split()))
if 0 in arr:
  print("0")
else:
  done=False
  mul=1
  for i in range(len(arr)):
    if mul*arr[i]<=int(1e18):
      mul*=arr[i]
    else:
      print("-1")
      done=True
      break
  if not done:
    print(mul)
### BUGGY CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()
c = nl()

for i in range(n):
  p[i]-=1

ans = -10**(18)
for si in range(n):
  x = si
  s = []
  tot = 0
  while(True):
    x = p[x]
    s.append(c[x])
    tot += c[x]
    if x == si:
      break
  l = len(s)
  t = 0
  for i in range(l):
    t += s[i]
    if i+1>k:
      break
    now = t
    if tot > 0:
      e = (k-(i+1))//l
      now += tot*e
    ans = max(ans,now)

print(ans)

### FIXED CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()
c = nl()

for i in range(n):
  p[i]-=1

ans = -10**(18)
for si in range(n):
  x = si
  s = []
  tot = 0
  while(True):
    x = p[x]
    s.append(c[x])
    tot += c[x]
    if x == si:
      break
  l = len(s)
  t = 0
  for i in range(l):
    t += s[i]
    if i+1>k:
      break
    now = t
    if tot > 0:
      e = (k-(i+1))//l
      now += tot*e
    ans = max(ans,now)

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

import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


def factorize(n, primes):
    import collections
    if n < 2:
        return dict()
    counter = collections.Counter()
    for p in primes:
        while n % p == 0:
            counter[p] += 1
            n //= p
        if n == 1 or p > n:
            break
    if n != 1:
        counter[n] = 1
    return counter


sieve = eratosthenes(10**3)
primes = [i for i, b in enumerate(sieve) if b]

MOD = 10**9 + 7

n = ri()
ls = ril()
if n == 1:
    print(1)
    exit()

factorizations = []
for x in ls:
    factorizations.append(factorize(x, primes))

lcm = collections.Counter()
for counter in factorizations:
    for p, k in counter.items():
        lcm[p] = max(lcm[p], k)

res = 0
for counter in factorizations:
    s = 1
    for p, k in lcm.items():
        s *= p**(k - counter[p])
        s %= MOD
    res += s
    res %= MOD
print(res)

### FIXED CODE ###

import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def gcd(a, b):
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


MOD = 10**9 + 7

n = ri()
ls = ril()
if n == 1:
    print(1)
    exit()

x = ls[0]
for i in range(1, n):
    x = lcm(x, ls[i])
ds = [x // y for y in ls]
print(sum(ds) % MOD)
### BUGGY CODE ###

N,M = map(int,input().split())

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

L2Rdic = {i:[] for i in range(N+1)}
R2Ldic = {i:[] for i in range(N+1)}

flag=True

for _ in range(M):
    L,R,D=map(int,input().split())

    if Dlist[L][R]==0:
        Dlist[L][R]=D
        L2Rdic[L].append(R)
        R2Ldic[R].append(L)
    elif Dlist[L][R]!=D:
        flag=False

    for r in L2Rdic[R]:
        if Dlist[L][r]==0:
            Dlist[L][r]=D+Dlist[R][r]
            L2Rdic[L].append(r)
            R2Ldic[r].append(L)
        elif Dlist[L][r]!=D+Dlist[R][r]:
            flag=False

    for l in R2Ldic[L]:
        if Dlist[l][R]==0:
            Dlist[l][R]=Dlist[l][L]+D
            L2Rdic[l].append(R)
            R2Ldic[R].append(l)
        elif Dlist[l][R]!=Dlist[l][L]+D:
            flag=False

    if flag==False:
        print('No')
        exit()
print('Yes')


### FIXED CODE ###

N,M = map(int,input().split())

L2R = {i:[] for i in range(N+1)}
R2L = {i:[] for i in range(N+1)}

for _ in range(M):
    L,R,D=map(int,input().split())
    L2R[L].append((R,D,L))
    R2L[R].append((L,-D,R))

x = [0 for i in range(N+1)]
f = [True for i in range(N+1)]

for i in range(1,N+1):
    if f[i]:
        f[i]=False
        x[i]=i
        que=L2R[i]+R2L[i]
        while len(que)>0:
            tmp = []
            for end,d,begin in que:
                if f[end]:
                    f[end]=False
                    x[end]=d+x[begin]
                    tmp+=L2R[end]+R2L[end]
                elif x[end]!=d+x[begin]:
                    print('No')
                    exit()
            que=tmp
print('Yes')
### BUGGY CODE ###

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

### FIXED CODE ###

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

print(count)
### BUGGY CODE ###

q = 1000003
N = int(input())
queries = [list(map(int, input().split())) for _ in range(N)]
for query in queries:
    prod = 1
    init = query[0]
    for i in range(query[2]):
        prod = prod * (init + i * query[1]) % q
    print(prod)


### FIXED CODE ###

from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools
 
setrecursionlimit(10**7)
 
def input():
  return stdin.readline().strip()
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]
 
MOD = 10**6 + 3
 
fact = [1] * MOD
for i in range(1, MOD):
  fact[i] = (fact[i-1] * i) % MOD
invfact = [0] * MOD; invfact[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(MOD-2, -1, -1):
  invfact[i] = invfact[i+1] * (i+1) % MOD
# print(invfact[:10])
 
def inv(n):
  return pow(n, MOD-2, MOD)
 
def solve(x, d, n):
  if x == 0:
    return 0
  if d == 0:
    return pow(x, n, MOD)
  k = x * inv(d) % MOD
  if n + k - 1 >= MOD:
    return 0
  return fact[n + k - 1] * invfact[k-1] % MOD * pow(d, n, MOD) % MOD
 
Q = read()
for _ in range(Q):
  x, d, n = reads()
  ans = solve(x, d, n)
  print(ans)
### BUGGY CODE ###

def check(A, B, mid):
    return (A * mid // B) - A * (mid // B)


def resolve():
    A, B, N = map(int, input().split())

    ans = 0
    max_int = min(N, B)
    for i in range(1, max_int + 1):
        tmp = check(A, B, i)
        ans = max(tmp, ans)

    print(ans)


resolve()

### FIXED CODE ###

def resolve():
    A, B, N = map(int, input().split())
    print(A * min(N, B - 1) // B)


resolve()