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

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

cnt = 1
buf = []
while True:
    x = cnt * b - 1
    if n < x:
        break
    calc = int(a * x / b) - a * (int(x / b))
    buf.append(calc)
    cnt += 1
    
buf.append(int(a * n / b) - a * (int(n / b)))

ans = max(buf)
print(ans)

### FIXED CODE ###

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

cnt = 1
buf = []
if n < b:
    buf.append(int(a * n / b) - a * (int(n / b)))
else:
    buf.append(int(a * (b - 1) / b) - a * (int((b - 1) / b)))
    

while True:
    if n / b > 10 ** 6:
        break
    x = cnt * b - 1
    if n < x :
        break
    calc = int(a * x / b) - a * (int(x / b))
    if calc > max(buf):
        buf.append(calc)
    cnt += 1
    
if n / b > 10 ** 6 and n >= b:
    buf.append(int(a * (b - 1) / b) - a * (int((b - 1) / b)))

ans = max(buf)
print(ans)
### BUGGY CODE ###

import re
s = str(input())

total = len(s)

while True:
    s_new = re.sub('01|10', '', s)
    if s_new == s:
        break
    s = s_new

print(total - len(s))

### FIXED CODE ###

s = str(input())

total = len(s)

zero = s.count('0')
one = s.count('1')

print(total - abs(zero-one))
### BUGGY CODE ###

import numpy as np
N=int(input())
s=input()
ans = np.array([0]*N)
for n,i in enumerate(s):
    if i=="W":
        ans += np.array([0]*(n+1)+[1]*(N-n-1))
    else:
        ans += np.array([1]*(n+1)+[0]*(N-n-1))
print(min(ans))


### FIXED CODE ###

N=int(input())
s=input()
tmp = 0
for i in s[1:]:
    if i == "E":
        tmp += 1
ans = tmp
for i in range(1,N):
    if s[i] =="W" and s[i-1]=="W":
        tmp += 1
    elif s[i]=="E" and s[i-1]=="E":
        tmp -=1
    ans = min(ans,tmp)
print(ans)
### BUGGY CODE ###

S = input()
Q = int(input())

for i in range(Q):
	query = input().split()
	if query[0] == '1':
		S = S[::-1]
	else:
		if query[1] == '1':
			S = query[2] + S
		else:
			S = S + query[2]
print(S)

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

rev = False
for i in range(Q):
	query = input().split()
	if query[0] == '1':
		rev = not rev
	else:
		if (query[1] == '1' and rev == False) \
		or (query[1] == '2' and rev == True):
			S.appendleft(query[2])
		else:
			S.append(query[2])

if rev:
	S.reverse()

print("".join(S))
### BUGGY CODE ###

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

ball = [0] * N


if a[-1] == 1:
        ball[-1] = 1

for i in reversed(range(N - 1)):
        tmp = 0
        for j in range(i + 1, N):
                if (j + 1) % (i + 1) == 0:
                        tmp += a[j]
        if tmp % 2 != a[i]:
                ball[i] = 1

print(sum(ball))
for i in range(N):
        if ball[i] == 1:
                print(i+1, end = " ")

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
 
ball = [0] * N
 
 
if a[-1] == 1:
        ball[-1] = 1
 
for i in reversed(range(N-1)):
        tmp = 0
        if i != 0:
                for j in range(i + (i + 1), N, i + 1):
                        #print("i j ", i , j)
                        if (j + 1) % (i + 1) == 0:
                                tmp += ball[j]
        else:
                tmp = sum(ball[1:])
        #print(i+1, tmp, a[i])
        if tmp % 2 != a[i]:
                ball[i] = 1
 
#print(ball)
 
print(sum(ball))
for i in range(N):
        if ball[i] == 1:
                print(i+1, end = " ")
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
def maxHeapify(A, i, n):
    l = i * 2 + 1
    r = i * 2 + 2
    if l < n and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r < n and A[r] > A[largest]:
        largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest, n)
def insert(S, k):
    S.append(k)
    n = len(S)
    i = n - 1
    while i > 0 and S[i] > S[(i - 1) // 2]:
        S[i], S[(i - 1) // 2] = S[(i - 1) // 2], S[i]
        i = (i - 1) // 2
def extractMax(S):
    if len(S) == 1:
        return S.pop()
    ans = S[0]
    S[0] = S.pop()
    maxHeapify(S, 0, len(S))
    return ans
A = []
while True:
    s = readline()
    if s[2] == "d":
        break
    elif s[2] == "t":
        print(extractMax(A))
    else:
       insert(A, int(s[7:]))



### FIXED CODE ###

import sys
from heapq import heapify, heappush, heappop
hq = []
S = []
for s in sys.stdin:
    if s[2] == "s":
        heappush(hq, -int(s[7:]))
    elif s[2] == "t":
        S.append(-heappop(hq))
    else:
        break
print("\n".join(map(str, S)))
### BUGGY CODE ###

import itertools
N, K= map(int,input().split())
p = list(map(int, input().split()))
ans = 1000000
for i in itertools.combinations(p, K):
    s = sum(i)
    ans = min(ans, s)
print(ans)


### FIXED CODE ###

import itertools
N, K= map(int,input().split())
p = list(map(int, input().split()))
p.sort()
ans = sum(p[:K])
print(ans)
### BUGGY CODE ###

N=int(input())
l=[]
for i in range(N):
    S=input()
    if S not in l:
        l.append(S)
print(len(l))

### FIXED CODE ###

N=int(input())
s=[input() for i in range(N)]
S=set(s)
print(len(S))
### BUGGY CODE ###

N, M = [int(x) for x in input().strip().split(" ")]

vs = set()
def dfs_w(v, d, t):
    # dfs while版 
    r = -1
    stack = [v]
    path = []
    while True:
        if len(stack) == 0:
            break
        v = stack.pop()
        if v < 0:
            path.pop()
        else:
            path.append(v)
            vs.add(v)
            for u in d[v]:
                if u == t:
                    #print(r,path)
                    if r != -1:
                        r = min(len(path)//3, r)
                    else:
                        r = len(path)//3
                    #continue
                if u in vs:
                    continue
                stack += [-v, u]
    return r

from collections import deque
def bfs(v,d,t,N):
    queue=deque([v])
    dist = [0] * (N+1)
    while True:
        if len(queue) == 0:
            break
        v = queue.popleft()
        vs.add(v)
        for u in d[v]:
            if u in vs:
                continue
            dist[u] = dist[v] + 1
            if u == t:
                return dist[u]//3
            queue.append(u)
    return -1

d = [set() for _ in range(3*N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a].add(N+b)
    d[N+a].add(2*N+b)
    d[2*N+a].add(b)

s, t = [int(x) for x in input().strip().split(" ")]
print(bfs(s, d, t, 3*N+1))

### FIXED CODE ###

N, M = [int(x) for x in input().strip().split(" ")]
from collections import deque
vs = set()
def bfs(v,d,t,N):
    queue=deque([v])
    dist = [0] * (N+1)
    while True:
        if len(queue) == 0:
            break
        v = queue.popleft()
        for u in d[v]:
            if u in vs:
                continue
            vs.add(u)
            dist[u] = dist[v] + 1
            if u == t:
                return dist[u]//3
            queue.append(u)
    return -1

d = [set() for _ in range(3*N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a].add(N+b)
    d[N+a].add(2*N+b)
    d[2*N+a].add(b)

s, t = [int(x) for x in input().strip().split(" ")]
print(bfs(s, d, t, 3*N+1))
### BUGGY CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
s=SI()
t=SI()
a=len(s)
b=len(t)
dp=[[[0,[]] for j in range(a+1)] for i in range(b+1)]
for i in range(1,b+1):
    for j in range(1,a+1):
        if s[j-1]==t[i-1]:
            dp[i][j][0]=dp[i-1][j-1][0]+1
            for x in dp[i-1][j-1][1]:
                dp[i][j][1].append(x)
            dp[i][j][1].append(j-1)
        else:
            if dp[i-1][j][0]>=dp[i][j-1][0]:
                dp[i][j][1]=dp[i-1][j][1]
            else:
                dp[i][j][1]=dp[i][j-1][1]
            dp[i][j][0]=max(dp[i-1][j][0],dp[i][j-1][0])
for z in dp[-1][-1][1]:
    print(s[z],end="")

#print(dp[-1][-1])
#print(dp)




            

    
    



### FIXED CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
s=SI()
t=SI()
a=len(s)
b=len(t)
dp=[[0]*(a+1) for i in range(b+1)]
for i in range(1,b+1):
    for j in range(1,a+1):
        if s[j-1]==t[i-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=[]
i,j=b,a
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        ans.append(s[j-1])
        i -= 1
        j -= 1
#print(ans)
for x in list(reversed(ans)):
    print(x,end="")
### BUGGY CODE ###

S = input()

ans = 0
_MOD = {0:1}

for i in range(len(S)):
    j = int(S[i:]) % 2019
    if j in _MOD:
        _MOD[j] = _MOD[j] + 1
    else:
        _MOD[j] = 1
        
for i in _MOD:
    ans += (_MOD[i] * (_MOD[i] - 1)) // 2

print(ans)

### FIXED CODE ###

S = input()[::-1]


_MOD = {0: 1}
amari = 0
a = 1
ans = 0

for i in S:
    amari = (amari + int(i) * a) % 2019
    a = (a * 10) % 2019  #表示桁 1あたりの余
    if amari in _MOD:
        _MOD[amari] = _MOD[amari] + 1
    else:
        _MOD[amari] = 1
    
for amari in _MOD:
    m = _MOD[amari]
    ans += (m * (m - 1)) // 2

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

import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
plist = []
p = 0
for i in range(100):
    if (is_prime(i+1)):
        plist.append(i+1)
        p += 1
clist = [0]*p
n = int(input())
o = 1
for i in range(n):
    o *= i+1
a = 1
b = 1
c = 0
ans = 1
while True:
    if a**2 > o:
        break
    elif o%a**2 != 0:
        b+=1
        a = b
        continue
    for i in range(p):
        while a%plist[i] == 0:
            a /= plist[i]
            clist[i] += 1
    for i in range(p):
        ans *= 2*clist[i] + 1
    if ans == 75:
        c+=1
    b+=1
    a = b
    ans = 1
    clist = [0]*p
print(c)


### FIXED CODE ###

n = int(input())
f = [0]*(n+1)
for i in range(2,n+1):
    a = i
    for j in range(2,i+1):
        while a % j == 0:
            f[j] += 1
            a //= j
def number(m):
    c = 0
    for i in range(n):
        if f[i] >= m - 1:
            c += 1
    return c
print(number(75) + number(25)*(number(3) - 1) + number(15)*(number(5) - 1) 
+ number(5)*(number(5) - 1)*(number(3) - 2)//2)
### BUGGY CODE ###

# disjoint setかと思いきやDFS
# したらTLEになったので根本的にやり方が間違ってるということ
# よくよく考えたらdfsなのでそこにたどり着いたときが最短距離だわ ムダに探索してた


import sys

sys.setrecursionlimit(10000000)

n = int(input())
graph = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append([b, c])
    graph[b].append([a, c])

q, k = map(int, input().split())
k = k - 1
# kからスタートしてぜんぶたどる
ans_list = [0 for _ in range(n)]


def dfs(node, weight):
    for data in graph[node]:
        if not used[data[0]]:
            used[data[0]] = True
            dfs(data[0], weight + data[1])
    ans_list[node] = weight


used = [False for _ in range(n)]
used[k] = True
dfs(k, 0)

for _ in range(q):
    a, b = map(lambda x: int(x) - 1, input().split())
    print(ans_list[a] + ans_list[b])


### FIXED CODE ###

# disjoint setかと思いきやDFS
# したらTLEになったので根本的にやり方が間違ってるということ
# よくよく考えたらdfsなのでそこにたどり着いたときが最短距離だわ ムダに探索してた


import sys

sys.setrecursionlimit(10000000)

n = int(input())
graph = [[] for _ in range(n)]

for _ in range(n - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append([b, c])
    graph[b].append([a, c])

q, k = map(int, input().split())
k = k - 1
# kからスタートしてぜんぶたどる
ans_list = [0 for _ in range(n)]


def dfs(node, weight):
    for data in graph[node]:
        if not used[data[0]]:
            used[data[0]] = True
            dfs(data[0], weight + data[1])
    ans_list[node] = weight


used = [False for _ in range(n)]
used[k] = True
dfs(k, 0)

for _ in range(q):
    a, b = map(lambda x: int(x) - 1, input().split())
    print(ans_list[a] + ans_list[b])
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

isprime = None

def sieve(n):
    global isprime

    if n < 2:
        isprime = [False] * (n + 1)
        return

    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True

    from math import sqrt, ceil

    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(2, ceil(n / i)):
                isprime[i * j] = False

def main():
    global isprime

    sieve(100000)

    _ = sys.stdin.readline()

    for l, r in (map(int, line.split()) for line in sys.stdin.readlines()):
        cnt = 0
        for i in range(l, r + 1):
            if isprime[i] == isprime[(i + 1) // 2] == True:
                cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

isprime = None

def sieve(n):
    global isprime

    if n < 2:
        isprime = [False] * (n + 1)
        return

    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True

    from math import sqrt, ceil

    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(i + i, n + 1, i):
                isprime[j] = False

def main():
    global isprime

    sieve(100000)

    _ = sys.stdin.readline()

    csums = [0] * 100001
    for i in range(3, 100001):
        csums[i] += csums[i - 1]
        if isprime[i] == True and isprime[(i + 1) // 2] == True:
            csums[i] += 1

    for l, r in (map(int, line.split()) for line in sys.stdin.readlines()):
        print(csums[r] - csums[l - 1])

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

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

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

# 1 - pi
ans = 0
for i in range(len(p)-k + 1):
    exp = 0
    for idx in range(i, i+k):
        exp += (p[idx] + 1) / 2
    ans = max(ans, exp)

print('{:.12f}'.format(ans))


### FIXED CODE ###

import sys
import numpy as np

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))
# 1 - pi
# print(p)
p_cumsum = np.cumsum(p)
# print(p_cumsum)
ans = p_cumsum[k-1]

for i in range(0, n - k):
    # print(i, i + k)
    cum = p_cumsum[i + k] - p_cumsum[i]
    ans = max(ans, cum)


print('{:.12f}'.format(ans))
### BUGGY CODE ###

import sys
s = input()
num = int(input())
for i in range(num):
  a = list(input().split())
  start = int(a[0])
  if start == 2:
    ns = int(a[1])
    if ns == 1:
      s = a[2] + s
    else:
      s = s + a[2]
  else:
    s = s[::-1]
print(s)

### FIXED CODE ###

from collections import deque
s = deque(input())
num = int(input())
cnt = 0
for i in range(num):
  a = input().split()

  if a[0] == '2':
    if (int(a[1])+cnt)%2==1:
      s.appendleft(a[2])
    else:
      s.append(a[2])
  else:
    cnt += 1
if cnt%2 == 1:    
	s.reverse()
print("".join(s))
### BUGGY CODE ###

a,b = map(int,input().split())
cnt = 0
if a >= b:
  A = b
else:
  A = a
pn=[2]
for L in range(3,A):
    chk=True
    for L2 in pn:
        if L%L2 == 0:chk=False
    if chk==True:pn.append(L)
pn.append(1)

for i in pn:
  if a%i ==0 and b%i == 0:
    cnt += 1

print(cnt)

### FIXED CODE ###

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

def make_divisors(n):
	divisors = set()
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.add(i)
			if i != n // i:
				divisors.add(n//i)
	return divisors
	
A = make_divisors(a)
B = make_divisors(b)
S = A & B
#Sから素数だけを抽出してカウント
import math

def is_prime(n):
	if n == 1: return False
	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False
	return True
cnt = 1
for i in S:
	if is_prime(i) == True:
		cnt += 1

print(cnt)
### BUGGY CODE ###

H,N = map(int,input().split())
Magic =[]
A =[]
E =[]
for i in range(N):
    a,b = map(int,input().split())
    Magic.append((a,b))
    A.append(a)
    E.append(a/b)
MAX_A = H+max(A)
E_MIN = min(E)
WORST = int(MAX_A/E_MIN) +2
#print(Magic)
#print(MAX_A)
#print(WORST)
DP = [[WORST] * (MAX_A+1) for i in range(N)]
for i in range(N):
    if i == 0:
        for j in range(1,MAX_A//Magic[0][0]+1):
            DP[0][j*Magic[0][0]] = Magic[0][1]*j
    else:
        for j in range(1,(MAX_A+1)):
#            KARI = []
            DP[i][j]=DP[i-1][j]
            if j % Magic[i][0] == 0:
                DP[i][j]=min(DP[i][j],((j//Magic[i][0]) * Magic[i][1]))
            r = j // Magic[i][0]
            for k in range(r):
                DP[i][j]=min(DP[i][j],(DP[i-1][j-k*Magic[i][0]]+k*Magic[i][1]))
print(min(DP[N-1][H:MAX_A]))


### FIXED CODE ###

H,N = map(int,input().split())
Magic =[]
A =[]
E =[]
for i in range(N):
    a,b = map(int,input().split())
    Magic.append((a,b))
    A.append(a)
    E.append(a/b)
MAX_A = H+max(A)
E_MIN = min(E)
WORST = int(MAX_A/E_MIN) +2
#print(Magic)
#print(MAX_A)
#print(WORST)
DP = [[WORST] * (MAX_A+1) for i in range(N)]
for i in range(N):
    if i == 0:
        for j in range(1,MAX_A//Magic[0][0]+1):
            DP[0][j*Magic[0][0]] = Magic[0][1]*j
    else:
        for j in range(Magic[i][0]-1):
            DP[i][j] = DP[i-1][j]
        DP[i][Magic[i][0]] = min(DP[i-1][Magic[i][0]],Magic[i][1])
        for j in range(Magic[i][0]+1,(MAX_A+1)):
            DP[i][j]=min(DP[i-1][j],DP[i-1][j-Magic[i][0]]+Magic[i][1],DP[i][j-Magic[i][0]]+Magic[i][1])
            if j % Magic[i][0] == 0:
                DP[i][j]=min(DP[i][j],((j//Magic[i][0]) * Magic[i][1]))
print(min(DP[N-1][H:MAX_A]))
### BUGGY CODE ###

import sys
import collections

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

    arr = []
    for x in range(M):
        L, R = list(map(int, input().split()))

        for y in range(L, R+1):
            arr.append(y)

    arrcnt = collections.Counter(arr).values()
    print(sum(i == M for i in arrcnt))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
import collections

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

    L = [0] * M
    R = [0] * M
    for i in range(M):
        L[i], R[i] = list(map(int, input().split()))

    ans = (int(min(R)) - int(max(L)) + 1)
    if ans < 0:
        print('0')
    else:
        print(ans)

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

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()
res=[]

for i in range(1,n+1):
    res.append(a.index(i)+1)
print(*res)

### FIXED CODE ###

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()
res=[0]*n

for i in range(n):
    res[a[i]-1]=i+1
print(*res)
### BUGGY CODE ###

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

countdic = {}
mod = 2019

for i in range(1,n+1):
    num = s%(10**i)
    remainder = num%mod
    if remainder in countdic:
        countdic[remainder] += 1
    if remainder not in countdic:
        countdic[remainder] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

if 0 in countdic:
    ans += countdic[0]

print(ans)

### FIXED CODE ###

s = list(map(int, list(input())))
n = len(s)

countdic = {}
mod = 2019

num = 0
d = 1
for i in range(1,n+1):
    num += s[n-i]*d
    num %= mod
    if num in countdic:
        countdic[num] += 1
    if num not in countdic:
        countdic[num] = 1
    d = (10*d)%mod

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

if 0 in countdic:
    ans += countdic[0]

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

list_ab = []
n = int(input())
for i in range(n):
    list_ab.append(list(map(int, input().split())))

j = n - 1
count = 0
while j >= 0:
    if list_ab[j][0] % list_ab[j][1] == 0:
        j -= 1
    else:
        ad = list_ab[j][1] * (list_ab[j][0] // list_ab[j][1] + 1) - list_ab[j][0]
        count += ad
        for i in range(j+1):
            list_ab[i][0] += ad
        j -= 1
print(count)


### FIXED CODE ###

list_ab = []
n = int(input())
for i in range(n):
    list_ab.append(list(map(int, input().split())))

j = n - 1
ad = 0
while j >= 0:
    list_ab[j][0] += ad
    if list_ab[j][0] % list_ab[j][1] == 0:
        j -= 1
    else:
        ad += list_ab[j][1] * (list_ab[j][0] // list_ab[j][1] + 1) - list_ab[j][0]
        j -= 1
print(ad)
### BUGGY CODE ###

def comp(v,w):
    if v[0]<w[0] or (v[0]==w[0] and v[1]<w[1]):
        return True
    else:
        return False


def mergesort(list0):
    n=len(list0)
    if n<=1:
        return list0
    else:
        a=mergesort(list0[0:n//2])
        b=mergesort(list0[n//2:n])
        return merge(a,b)


def merge(list1,list2):
    a=0
    b=0
    s=[]
    for c in range(len(list1)+len(list2)):
        if b>=len(list2) or (a<len(list1) and comp(list1[a],list2[b])):
            s.append(list1[a])
            a=a+1
        else:
            s.append(list2[b])
            b=b+1
    return s


h,w,m=map(int,input().split())
g=[]
e1=[[0,t] for t in range(h)]
e2=[[0,t] for t in range(w)]
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1][0]+=1
    e2[b-1][0]+=1
f1=mergesort(e1)
f2=mergesort(e2)
p=f1[-1][0]
q=f2[-1][0]
x=[]
y=[]
for c in range(h-1,-1,-1):
    if p>f1[c][0]:
        break
    x.append(f1[c][1])
for c in range(w-1,-1,-1):
    if q>f2[c][0]:
        break
    y.append(f2[c][1])
r=1
if len(x)*len(y)>m:
    r=0
else:
    for i in x:
        for j in y:
            if not ([i,j] in g):
                r=0
                break
        else:
            continue
        break
print(p+q-r)

### FIXED CODE ###

h,w,m=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[1 if e1[c]==p1 else 0 for c in range(h)]
y=[1 if e2[c]==p2 else 0 for c in range(w)]
r=sum(x)*sum(y)
for i in g:
    if x[i[0]]==1 and y[i[1]]==1:
        r-=1
if r==0:
    print(p1+p2-1)
else:
    print(p1+p2)
### BUGGY CODE ###

s = int(input())

for i in range(1, int(s**0.5)+1):
    if s % i == 0:
        if i <= 10e9 and s % i <= 10e9:
            x2 = i
            y3 = s//i
print("0 0 {} 0 0 {}".format(x2, y3))

### FIXED CODE ###

s = int(input())

e = 10**9
if s == e**2:
    print(0, 0, e, 1, 0, e)
else:
    y = s//e + 1
    x = y*e - s
    print(0, 0, e, 1, x, y)
### BUGGY CODE ###

import collections 
N=int(input())
S=[collections.Counter(list(input())) for i in range(N)]

count = 0
for i in range(len(S)):
    for j in range(i+1, len(S)):
        if S[i] == S[j]:
            count += 1
print(count)


### FIXED CODE ###

N=int(input())
S=["".join(sorted(input())) for i in range(N)]

dic = {}
for s in S:
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1

count = 0
for k in dic.keys():
    c = dic[k]
    count += (c * (c - 1)) // 2
print(count)