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

n = int(input())
s = str(input())
count = 0
i = 0
j = 0
k = 0
for i in range(0,n):
    if i > j  :
        break
    for j in range(i,n):
        if j > k :
            break
        for k in range(j,n):
            if i >= j or j >= k or i >= k :
                continue
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k] )and (j - i != k - j):
                count += 1
                #print(i,j,k)
print(count)

### FIXED CODE ###

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

R = s.count("R")
G = s.count("G")
B = s.count("B")

counter = R * G * B 
#j-i != k-j
# 1 2 3 ,1 3 5

for i in range(n-1):
    for j in range(i+1,(n+i+1)//2):
        if s[i] != s[j] and s[i] != s[2*j-i] and s[2*j -i] != s[j] :
            counter -= 1

print(counter)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(N):
    c = a[i]
    del a[i]
    a1 = sorted(a)
    for j in range(N-2):
        for k in range(j+1,N-1):
            if a1[j] == a1[k]:
                ans += 1
    print(ans)
    ans = 0
    a.insert(i,c)

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(ans))
### BUGGY CODE ###

num = (int)(input())
button = []
for i in range(num):
  button.append(list(map(int, input().split(" "))))
count = 0
for i in range(num - 1, -1, -1):
  #print(button)
  tasu = button[i][1] - (button[i][0] % button[i][1]) if button[i][0] % button[i][1] != 0 else 0
  for j in range(i, -1, -1):
    button[j][0] += tasu
  count += tasu
print(count)

### FIXED CODE ###

num = (int)(input())
button = []
for i in range(num):
  button.append(list(map(int, input().split(" "))))
count = 0
for i in range(num - 1, -1, -1):
  button[i][0] += count
  tasu = button[i][1] - (button[i][0] % button[i][1]) if button[i][0] % button[i][1] != 0 else 0
  #print(tasu, count)
  count += tasu
print(count)
### BUGGY CODE ###

N,M,K=map(int,input().split())
O=10**9+7
S=N+M
for i in range(K):S=S*(N*M-i)*pow(i+1,O-2,O)
print(S*K*~-K*-~O//6%O)

### FIXED CODE ###

N,M,K=map(int,input().split())
O,S,T=10**9+7,N+M,6
for i in range(K):S=S*(N*M-i)%O;T=T*-~i%O
print(S*K*~-K*pow(T,O-2,O)%O)
### BUGGY CODE ###

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

ans = 0
for i in range(a,b+1) :
    if i%x == 0 :
        ans += 1

print(ans)


### FIXED CODE ###

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

if a%x == 0 :
    first = a // x
else :
    first = ( a + x - a%x ) // x

if b%x == 0 :
    end = b // x
else :
    end = ( b - b%x ) // x

ans = end - first + 1

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

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


### FIXED CODE ###

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

check = {}
ans = 0

for i in range(N):
    x = i - A[i]
    y = A[i] + i
    ans += check.get(x, 0)
    check.setdefault(y, 0)
    check[y] += 1

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

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

n,q = map(int,readline().split())
AB = (tuple(int(x) for x in readline().split()) for _ in range(n-1))
PX = (tuple(int(x) for x in readline().split()) for _ in range(q))
Tree = [[] for _ in range(n+1)]
Counter = [0 for _ in range(n+1)]

for a,b in AB:
  Tree[a].append(b)
  Tree[b].append(a)
  
for p,x in PX:
  Counter[p] += x

P = [-1]*(n+1)

nodes = [1]
while nodes:
  parent = nodes.pop(0)
  for node_i in Tree[parent]:
    if P[parent]==node_i:
      continue
    P[node_i] = parent
    nodes.append(node_i)
    Counter[node_i] += Counter[parent]

print(*Counter[1:])

### FIXED CODE ###

n, q = map(int, input().split())
Tree = [[] for _ in range(n+1)]
Counter = [0 for _ in range(n+1)]
AB = (tuple(map(int, input().split())) for _ in range(n-1))
PX = (tuple(map(int, input().split())) for _ in range(q))

for a,b in AB:
  Tree[a].append(b)
  Tree[b].append(a)
  
for p,x in PX:
  Counter[p] += x

P = [-1]*(n+1)

nodes = [1]
while nodes:
  parent = nodes.pop()
  for node_i in Tree[parent]:
    if P[parent]==node_i:
      continue
    P[node_i] = parent
    nodes.append(node_i)
    Counter[node_i] += Counter[parent]

print(*Counter[1:])
### BUGGY CODE ###

import numpy as np
N = int(input())
L = np.array(sorted(list(map(int, input().split()))))

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a = L[i]
        b = L[j]
        idx = np.searchsorted(L, a + b, sorter=None)
        ans += idx - 1 - j
print(ans)


### FIXED CODE ###

from bisect import bisect_left

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a = L[i]
        b = L[j]
        idx = bisect_left(L, a + b)
        ans += idx - 1 - j
print(ans)
### BUGGY CODE ###

import sys
input=lambda: sys.stdin.readline().rstrip()

from scipy.sparse.csgraph import floyd_warshall
n=int(input())
table=[]
for i in range(n):
  table.append([int(i) for i in input().split()])
d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)

Chk=True
for i in range(n):
  for j in range(n):
    if table[i][j]==int(d[i][j]):
      continue
    else:
      Chk=False
ans=0
for i in range(n):
  for j in range(i+1,n):
    C=True
    for k in range(n):
      if k==i or k==j:
        continue
      else:
        if table[i][k]+table[k][j]==table[i][j]:
          C=False
    if C:
      ans+=table[i][j]
print(ans if Chk else -1)

### FIXED CODE ###

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
table=[]
for i in range(n):
  table.append([int(i) for i in input().split()])
Chk=True
for k in range(n):
  for i in range(n):
    for j in range(n):
      if table[i][k]+table[k][j]<table[i][j]:
        Chk=False
        table[i][j]=table[i][k]+table[k][j]

ans=0
for i in range(n):
  for j in range(i+1,n):
    C=True
    for k in range(n):
      if k==i or k==j:
        continue
      else:
        if table[i][k]+table[k][j]==table[i][j]:
          C=False
    if C:
      ans+=table[i][j]
print(ans if Chk else -1)
### BUGGY CODE ###

##C - Sum of product of pairs
N = int(input())
A = list(map(int,input().split()))
import itertools
B = list(itertools.combinations(A,2))
ans = 0
for i in B:
    ans += i[0]*i[1]
print(ans % (10**9+7))

### FIXED CODE ###

##C - Sum of product of pairs
##累積和
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
ans = 0
for i in range(N-1):
    ans += A[i]*(S - A[i])
    S -= A[i]
print(ans % (10**9+7))
### BUGGY CODE ###

from collections import deque
import sys


H, W = [int(_) for _ in input().split()]

M = []
queues = []
for i in range(H):
    A = input()
    M.append(list(A))
    for j in range(W):
        if A[j] == '#':
            queues.append(deque([[j, i, 0]]))

depth_now = 0
depth = 0
while True:
    for q in queues:
        while len(q) != 0 and q[0][2] == depth_now:
            p = q.popleft()
            x = p[0]
            y = p[1]
            depth = p[2]
            if x - 1 >= 0 and M[y][x-1] == '.':
                q.append([x-1, y, depth+1])
                M[y][x-1] = '#'
            if x + 1 < W and M[y][x+1] == '.':
                q.append([x+1, y, depth+1])
                M[y][x+1] = '#'
            if y - 1 >= 0 and M[y-1][x] == '.':
                q.append([x, y-1, depth+1])
                M[y-1][x] = '#'
            if y + 1 < H and M[y+1][x] == '.':
                q.append([x, y+1, depth+1])
                M[y+1][x] = '#'
    queues = [q for q in queues if len(q) != 0]
    if len(queues) == 0:
        print(depth_now)
        break
    depth_now += 1


### FIXED CODE ###

from collections import deque
import sys


H, W = [int(_) for _ in input().split()]

M = []
q = deque([])
for i in range(H):
    A = input()
    M.append(list(A))
    for j in range(W):
        if A[j] == '#':
            q.append([j, i, 0])

depth_now = 0
depth = 0
count = 0
while len(q) > 0:
    p = q.popleft()
    x = p[0]
    y = p[1]
    depth = p[2]
    if x - 1 >= 0 and M[y][x-1] == '.':
        q.append([x-1, y, depth+1])
        M[y][x-1] = '#'
    if x + 1 < W and M[y][x+1] == '.':
        q.append([x+1, y, depth+1])
        M[y][x+1] = '#'
    if y - 1 >= 0 and M[y-1][x] == '.':
        q.append([x, y-1, depth+1])
        M[y-1][x] = '#'
    if y + 1 < H and M[y+1][x] == '.':
        q.append([x, y+1, depth+1])
        M[y+1][x] = '#'
print(depth)
### BUGGY CODE ###

input()
a=[]
for i in input().split():
	a.append(int(i))

maxp = 0
for i in range(len(a)):
	for j in range(len(a))[i+1:]:
		if a[j]-a[i]>maxp:
			maxp=a[j]-a[i]

c=0
for i in range(len(a)):
	for j in range(len(a))[i+1:]:
		if a[j]-a[i]==maxp:
			c+=1
print(c)

### FIXED CODE ###

input()
a=[]
for i in input().split():
	a.append(int(i))

maxp = 0
minp = 10000000000000
maxval=0
c=0
for i in range(len(a)):
	if a[i]<minp:
		minp=a[i]
	val=a[i]-minp
	if val>maxval:
		maxval=val
		c=1
	elif val==maxval:
		c+=1

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

import sys
inf = float("inf")
# sys.setrecursionlimit(1000000)

from bisect import bisect_left,bisect_right
# import numpy as np

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
Arr = get_array()
Arr.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        new = Arr[i]+Arr[j]
        ans+=bisect_left(Arr[j+1 : ], new)
print(ans)

### FIXED CODE ###

import sys
inf = float("inf")
from bisect import bisect_left,bisect_right

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
Arr = get_array()
Arr.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        new = Arr[i]+Arr[j]
        ans+=bisect_left(Arr[j+1:], new)
print(ans)
### BUGGY CODE ###

def main():
    R, G, B, N = map(int, input().split())

    ans = 0
    for i in range(N+1):
        for j in range(N+1):
            tmp = N - i * R - j * G
            if tmp % B == 0 and tmp >= 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    R, G, B, N = map(int, input().split())

    ans = 0
    for i in range(N+1):
        for j in range(N+1):
            tmp = N - i * R - j * G
            if tmp % B == 0 and tmp >= 0:
                ans += 1
    print(ans)


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

import sys

sys.setrecursionlimit(10 ** 6)

class Node(object):
    def __init__(self):
        self.value = 0
        self.children_id = []

    def set_child(self, child_id):
        self.children_id.append(child_id)

    def add_number(self, n):
        self.value += n
        for child_id in self.children_id:
            nodes[child_id].add_number(n)

    def get_value(self):
        return self.value

N, Q = map(int, sys.stdin.readline().rstrip().split())

nodes = []
for i in range(N + 1):
    nodes.append(Node())

for j in range(N - 1):
    parent, child = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].set_child(child)

for _ in range(Q):
    parent, number = map(int, sys.stdin.readline().rstrip().split())
    nodes[parent].add_number(number)

res = []
for k in range(1, N + 1):
    res.append(nodes[k].get_value())

print(*res, sep=' ')


### FIXED CODE ###

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

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

branches = []
for j in range(N - 1):
    parent, child = map(int, input().split())
    branches.append([parent, child])

for _ in range(Q):
    parent, number = map(int, input().split())
    nodes[parent] += number

branches.sort()

for branch in branches:
    parent = branch[0]
    child = branch[1]
    nodes[child] += nodes[parent]

print(*nodes[1:], sep=' ')
### BUGGY CODE ###

n, k = map(int,input().split())
p = list(map(int, input().split()))
l = []
for i in range(0,n-k+1):
    l.append((sum(p[i:i+k])+k)/2)
print(max(l))

### FIXED CODE ###

n, k = map(int,input().split())
p = list(map(int, input().split()))
a = sum(p[0:k])
l = [a]
for i in range(1,n-k+1):
    a = a - p[i-1] + p[k-1+i]
    l.append(a)
print((max(l)+k)/2)
### BUGGY CODE ###

s = input()
count = 0

l = [int(s[i:]) % 2019 for i in range(len(s))]
d = {}

for i in l:
  d[i] = d.get(i, 0) + 1
  
for i in d:
  count += d[i]*(d[i]-1)//2

count += l.count(0)

print(count)

### FIXED CODE ###

import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

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

import numpy as np
N,a,b = np.array(input().split()).astype(int)
mod = 10**9+7
import math
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x
        x = x*x%mod
        n = n >> 1 #ビットシフト
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n + 1):
        val = (val*i)%mod
    return val
def cmb(N, r):
    A = fact(N-r+1, N)
    B = math.factorial(r)
    A = (A*power(B, mod-2))%mod
    return A
print((power(2, N)-1-cmb(N, a)-cmb(N, b))%mod)

### FIXED CODE ###

import numpy as np
N,a,b = np.array(input().split()).astype(int)
mod = 10**9+7
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x%mod
        x = (x*x)%mod
        n = n >> 1 #ビットシフト
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n+1):
        val = val*i % mod
    return val
    
def cmb1(N, r):
    A = fact(N-r+1, N)%mod
    B = fact(1, r)%mod
    return A, B, (A*power(B, mod-2))%mod
def cmb2(a, b, A, B):
    A = fact(N-a+1, N-b)*A%mod
    B = fact(b+1, a)*B%mod
    return (A*power(B, mod-2))%mod
if(a>N//2):
    a = N-a
if(b>N//2):
    b = N-b
tmp = max(a,b)
b = min(a,b)
a = tmp
A, B, K1 = cmb1(N, b)
K2 = cmb2(a, b, A, B)
print((power(2, N)-1-K1-K2)%mod)
### BUGGY CODE ###

n,m = map(int,input().split())
a = []
b = []
l = []
ans = 0
count = 0

for i in range(n):
	a_dash,b_dash = map(int,input().split())
	a.append(a_dash)
	b.append(b_dash)

c = zip(a,b)
c = sorted(c)
a,b = zip(*c)
a = list(a)
b = list(b)

for i in reversed(range(m)):
	l_dash = [ b[j] for j in range(count,count+a.count(m-i)) if a[j]+i==m ]
	l.extend(l_dash)
	count += len(l_dash)
	if len(l) != 0:
		ans += max(l)
		l.pop(l.index(max(l)))

print(ans)

### FIXED CODE ###

import sys
import heapq

s = sys.stdin.readlines()
n,m = map(int,s[0].split())
a = []
b = []
l = []
ans = 0
count = 0

for i in range(1,n+1):
	a_dash,b_dash = map(int,s[i].split())
	a.append(-a_dash)
	b.append(-b_dash)

c = zip(a,b)
c = sorted(c,reverse=True)
a,b = zip(*c)
a_length = len(a)

for i in reversed(range(m)):
	for j in range(count,a_length):
		if -a[j] + i == m:
			heapq.heappush(l,b[j])
			count += 1
		else:
			break
	if len(l) != 0:
		maximum = heapq.heappop(l)
		ans += maximum

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

import numpy as np


n = int(input())
a = [int(_) for _ in input().split()]
M = max(a)
p = len(format(M, 'b'))
l = [[0 for _ in range(n)] for _ in range(p)]
ans = 0
for i in range(n):
    a_s = format(a[i], '0' + str(p) + 'b')
    for c in range(p):
        l[c][i] = int(a_s[c])
arr = np.array(l)
for i in range(p):
    c1 = np.count_nonzero(arr[i])
    ans += (2**(p - i - 1)) * c1 * (n - c1)
    ans %= (10**9 + 7)
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    M = max(a)
    p = len(format(M, 'b'))
    l = [0 for _ in range(p)]
    ans = 0
    for i in range(n):
        a_s = format(a[i], '0' + str(p) + 'b')
        for c in range(p):
            if a_s[c] == '1':
                l[c] += 1
    for i in range(p):
        c1 = l[i]
        ans += (2**(p - i - 1)) * c1 * (n - c1)
        ans %= (10**9 + 7)
    print(ans)

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

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

    sum = 0
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            sum += (A[i] * A[j])
            sum = sum % (10 ** 9 + 7)

    print(sum)


if __name__ == "__main__":
    main()


### FIXED CODE ###

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

    B = sum(A)
    answer = 0
    for i in range(0, N):
        answer += A[i] * (B - A[i])
        B -= A[i]

    answer %= (10 ** 9 + 7)

    print(answer)


if __name__ == "__main__":
    main()

# A1*A2 + A1*A3 + ... + A1*AN = A1 * (A2 + A3 + ... + AN)
# +
# A2*A3 + A2*A4 + ... +| A2*AN = A2 * (A3 + A4 + ... + AN)
### BUGGY CODE ###

import collections

lst = []
cnt = 0
n = int(input())
for i in range(n):
  s = input()
  c = collections.Counter(s)
  if c in lst:
    cnt += lst.count(c)
  lst.append(c)
print(cnt)

### FIXED CODE ###

n = int(input())

dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if not s in dic:
    dic[s] = 1
  else:
    dic[s] += 1

res = 0
for v in dic.values():
  if v >= 2:
    res += v*(v-1)
print(res//2)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

count = 0
for r in range(0,N+1,R):
    for g in range(0,N+1,G):
        b = (N - r - g) / B
        if b >= 0 and b.is_integer():
            count += 1
print(count)

### FIXED CODE ###

R, G, B, N = map(int, input().split())

box = sorted([R,G,B],reverse=True)

count = 0
for x in range(0,N+1,box[0]):
    for y in range(0,N+1 - x ,box[1]):
        z = (N - x - y) / box[2]
        if z >= 0 and z.is_integer():
            count += 1
print(count)
### BUGGY CODE ###

import numpy as np

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

counter = np.bincount(A)

ans = []
for i in range(len(A)):
    counter_i = counter.copy()
    counter_i[A[i]] -=1
    sum_i = sum(counter_i * (counter_i -1) //2)
    ans.append(sum_i)
    
for i in range(len(ans)):
    print(ans[i])

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.array(read().split(), np.int64)
counter = np.bincount(A)
 
total = (counter * (counter - 1)).sum() // 2
answer = (total - (counter - 1))[A]
 
print('\n'.join(answer.astype(str)))
### BUGGY CODE ###

from collections import deque

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

adj = [[] for i in range(n)]

adj[x-1].append(y-1)
adj[y-1].append(x-1)

for i in range(n-1):
    adj[i].append(i+1)
    adj[i+1].append(i)

ans = [0]*(n-1)
for i in range(n):
    q = deque([])
    q.append(i)

    dist = [-1]*n
    dist[i] = 0

    while len(q) > 0:
        v = q.popleft()
    
        for nv in adj[v]:
            if dist[nv] != -1:
                continue
        
            dist[nv] = dist[v] + 1
            q.append(nv)
    for i in dist:
        if i != 0:
            ans[i-1] += 1

for i in ans:
    print(i//2)

### FIXED CODE ###

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

ans=[0]*n

for i in range(1,n):
    for j in range(i+1,n+1):
        d=min(abs(j-i),abs(x-i)+1+abs(j-y))
        ans[d]+=1


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

AB = input().split(' ')
A = int(AB[0])
B = int(AB[1])

def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    cf.insert(0,1)
    return cf

def check_cf(x1,x2):
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            return False
    return True
candidate = cf(A,B)
decided_list = [candidate[0]]

for i in range(1,len(candidate)):
    flag = True
    for s in range(i):
        if not check_cf(candidate[i],candidate[s]):
            flag = False
            break
    if flag:
        decided_list.append(candidate[i])
print(len(decided_list))

### FIXED CODE ###

AB = input().split(' ')
A = int(AB[0])
B = int(AB[1])
'''
def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
                cf.append(i)
    return cf
 
def check_cf(x1,x2):
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            return False
    return True
candidate = cf(A,B)
'''
'''
decided_list = [candidate[0]]
 
for i in range(1,len(candidate)):
    flag = True
    for s in range(2,candidate[i]):
        if candidate[i]%s == 0:
            flag = False
            break
    if flag:
        decided_list.append(candidate[i])
'''
#print(candidate)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

def gcd(num1: int, num2: int) -> int:
    if num2 == 0:
        return num1
    else:
        return gcd(num2,num1%num2)
max_gcd = gcd(A,B)
result = factorization(max_gcd)
#print(result)
if len(result) == 1 and result[0][0] == 1:
    print(1)
else:
    print(len(result)+1)
### BUGGY CODE ###

N=int(input())
A=[int(input()) for _ in range(N)]
for i in range(N):
    if sorted(A)[-1]==A[i]:
        print(sorted(A)[-2])
    else:
        print(sorted(A)[-1])

### FIXED CODE ###

N=int(input())
A=[int(input()) for _ in range(N)]
AS=sorted(A)
# for i in range(N):
#     if AS[-1]==A[i]:
#         print(AS[-2])
#     else:
#         print(AS[-1])
for i in range(N):
    print(AS[-2] if AS[-1]==A[i] else AS[-1])
### BUGGY CODE ###

# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v2(A, B, N)
    print(M)




### FIXED CODE ###

# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


def resolve_v3(A, B, N):
    maxM = calcM(A, B, N)

    k, r = divmod(N, B)
    if k and B * k -1 <= N:
        # k * B - 1で調査
        maxM = max(maxM, calcM(A, B, k * B - 1))
    # if r == 0:
    #     maxM = max(maxM, calcM(A, B, N - 1))

    maxM = calcM(A, B, min(N, B - 1))


    return maxM

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v3(A, B, N)
    print(M)