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

n = int(input())
board = [input() for i in range(n)]

def check(a, b):
    for i in range(n):
        for j in range(n):
            if board[(i-a)%n][(j-b)%n] != board[(j-a)%n][(i-b)%n]:
                return False
    return True

ans = 0
for i in range(n):
    if check(i,0):
        ans += n-i
    if check(0,i) and i >0:
        ans += n-i
print(ans)

### FIXED CODE ###

# 解説AC
n = int(input())
board = [input() for i in range(n)]

def check(a, b):
    for i in range(n):
        for j in range(n):
            if board[(i-a)%n][(j-b)%n] != board[(j-a)%n][(i-b)%n]:
                return False
    return True

ans = 0
for i in range(n):
    if check(i,0):
        ans += n-i
    if check(0,i) and i >0:
        ans += n-i
print(ans)
### BUGGY CODE ###

class SegmentTree():
    def __init__(self, S):
        # S:英小文字からなる配列
        tmp = len(S)
        cnt = 0
        while tmp // 2 > 0:
            tmp //= 2
            cnt += 1
        self.size = cnt + 1
        # sizeはSの長さ<=2**nをみたす最小のn
        self.array = [set()] * (2**(self.size + 1) - 1)
        for i, c in enumerate(S):
            self.array[i + 2**self.size - 1] = {c}
        for i in range(2**self.size - 1)[::-1]:
            self.array[i] = self.array[2 * i + 1] | self.array[2 * i + 2]

    def subquery(self, l, r, k, i, j):
        # 区間[i,j)の中で区間[l,r)の文字列の集合を返す
        if j <= l or r <= i:
            return set()
        elif l <= i and j <= r:
            return self.array[k]
        else:
            l_set = self.subquery(l, r, 2 * k + 1, i, (i + j) // 2)
            r_set = self.subquery(l, r, 2 * k + 2, (i + j) // 2, j)
            return l_set | r_set

    def query(self, l, r):
        # [l,r)に含まれる文字の種類数
        return len(self.subquery(l, r, 0, 0, 2**self.size))

    def update(self, i, c):
        tmp = i + 2**self.size - 1
        self.array[tmp] = {c}
        while tmp > 0:
            tmp = (tmp - 1) // 2
            self.array[tmp] = self.array[2 * tmp + 1] | self.array[2 * tmp + 2]


N = int(input())
S = list(input())
Q = int(input())
tree = SegmentTree(S)
for q in range(Q):
    t, i, c = input().split()
    if t == '1':
        i = int(i) - 1
        tree.update(i, c)
    else:
        l, r = int(i) - 1, int(c)
        print(tree.query(l, r))

### FIXED CODE ###

import sys
input = sys.stdin.readline


class SegmentTree():
    def __init__(self, S):
        self.size = 19
        self.array = [set()] * (2**(self.size + 1) - 1)
        for i, c in enumerate(S):
            self.array[i + 2**self.size - 1] = {c}
        for i in range(2**self.size - 1)[::-1]:
            self.array[i] = self.array[2 * i + 1] | self.array[2 * i + 2]

    def subquery(self, l, r, k, i, j):
        # 区間[i,j)の中で区間[l,r)の文字列の集合を返す
        if j <= l or r <= i:
            return set()
        elif l <= i and j <= r:
            return self.array[k]
        else:
            l_set = self.subquery(l, r, 2 * k + 1, i, (i + j) // 2)
            r_set = self.subquery(l, r, 2 * k + 2, (i + j) // 2, j)
            return l_set | r_set

    def query(self, l, r):
        # [l,r)に含まれる文字の種類数
        return len(self.subquery(l, r, 0, 0, 2**self.size))

    def update(self, i, c):
        tmp = i + 2**self.size - 1
        self.array[tmp] = {c}
        while tmp > 0:
            tmp = (tmp - 1) // 2
            self.array[tmp] = self.array[2 * tmp + 1] | self.array[2 * tmp + 2]


def main():
    N = int(input())
    S = [ord(_) - 97 for _ in list(input())]
    Q = int(input())
    tree = SegmentTree(S)
    for q in range(Q):
        t, i, c = input().split()
        if t == '1':
            i = int(i) - 1
            tree.update(i, ord(c) - 97)
        else:
            l, r = int(i) - 1, int(c)
            print(tree.query(l, r))


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

n = input()
sum = 0 
l = len(n)
for i in range(l):
    sum += int(n)%10
    n = n[:-1]
if sum%9 == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = input()
sum = 0 
for i in n:
    sum += int(i)
if sum%9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import itertools
import bisect
n=int(input())
count = 0
a=sorted(list(map(int, input().split(" "))))
for i in range(2,n):
  for j, k in itertools.combinations(a[:i], 2):
    if j + k > a[i]:
      count += 1
print(count)

### FIXED CODE ###

n = int(input())
import bisect
a = sorted(list(map(int, input().split(" "))))
ans = 0
for i in range(1, n-1):
  b = a[:i]
  c = a[i + 1:]
  #print(b, c)
  for j in b:
    ans += bisect.bisect(c, a[i]+j-0.1)
    #print(bisect.bisect(c, a[i]+j-0.1))
print(ans)
### BUGGY CODE ###

import bisect
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))

        A.sort()
        for _ in range(M):
            v = A[-1] // 2
            A.pop()
            bisect.insort(A, v)

        print(sum(A))


# Run main
if __name__ == '__main__':
    AtCoder().main()


### FIXED CODE ###

import bisect
import heapq
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        hq = []
        for c in input().split():
            heapq.heappush(hq, -1 * int(c))

        for _ in range(M):
            heapq.heappush(hq, int(heapq.heappop(hq) / 2))

        print(-1 * sum(hq))


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

import sys
sys.setrecursionlimit(10**6)

def solve(N, M, A, cur, remain):
  if cur == N:
    return 0
  else:
    a = A[cur]
    tmp = 10**10
    for i in range(remain+1):
      tmp = min(tmp, solve(N, M, A, cur+1, remain-i)+a//(2**i))
    return tmp
n, m = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, m, a, 0, m))



### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(lambda x:[-int(x),int(x)], input().split()))
heapq.heapify(A)

for m in range(M):
  x = heapq.heappop(A)
  x[1] //= 2
  x[0] = -x[1]
  heapq.heappush(A, x)
ans = 0
for a in A:
  ans += a[1]
print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
a = list(map(int,input().split()))
t = []
for i in range(N-K+1):
    s = 1
    for j in range(0,K):
        s = s * a[K+i-j-1]
    t.append(s)
    if i != 0:
        if t[i-1]<t[i]:
            print("Yes")
        else:
            print("No")

### FIXED CODE ###

N,K = map(int,input().split())
a = list(map(int,input().split()))
for i in range(1,N-K+1):
    if a[K+i-1]>a[i-1]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import itertools
import random
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
        b = b + 1
    if n > 1:
        fct.append((n,1))
    return fct
def solve():
    random.seed(0)
    n = ni()
    A = lma()
    d=collections.Counter()
    r = random.random()
    if n==10**6:
        if 0.5<r<0.7:
            print("pairwise coprime")
            exit()

    for i in range(n):
        a = A[i]
        fct = factorize(a)
        for fc,cnt in fct:
            d[fc]+=1
            if d[fc]==n:
                break

    f1=True # pp or sp
    f2=True # sp or other
    for num,cnt in d.items():
        if cnt==n:
            f2=False #other
            break
        else:
            if cnt==1:
                pass
            else:
                f1=False
    if f2==False:
        print("not coprime")
        exit()
    elif f1 and f2:
        print("pairwise coprime")
    elif f1==False:
        print("setwise coprime")
solve()


### FIXED CODE ###

ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
gcd=math.gcd

def is_primes(n):
    primes = [1]*n
    primes[0] =0
    primes[1] =0
    for i in range(2,int(n**0.5)+2):
        if primes[i] ==1:
            for j in range(2*i,n,i):
                primes[j] = 0
    return primes
def factorize(n,primes):
    fct = [(1,1)]
    for b in primes:#primes ::sorted
        if b**2 > n:
            break
        cnt =0
        while n % b == 0:
            n //= b
            cnt +=1
        if cnt >=1:
            fct.append((b,cnt))
    if n > 1:
        fct.append((n,1))
    return fct

n =ni()
A = lma()
mx= 10**6+10
prms = is_primes(mx)
prms2=[i for i in range(mx) if prms[i]]
#print(prms2)
d=collections.Counter()
for a in A:
    fct = factorize(a,prms2)
    #print(fct)
    for fc,cnt in fct:
        if fc==1:continue
        d[fc]+=1

f1=True # pp or sp
f2=True # sp or not p
for num,cnt in d.items():
    if cnt==n:
        f2=False #numが全体で共通の約数になる not coprime
        break
    else:
        if cnt==1:## 素
            pass
        else:
            f1=False

if f2==False:
    print("not coprime")
elif f1:
    print("pairwise coprime")
else:
    print("setwise coprime")
### BUGGY CODE ###

import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    deleted = [False for _ in range(n-1)]
    for ab in sorted(ab_list, key = itemgetter(1)):
        if True in set(deleted[ab[0]-1:ab[1]-1]):
            continue
        else:
            deleted[ab[1]-2] = True
    print(len([b for b in deleted if b is True]))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ab_list = [tuple(map(int, input().split())) for _ in range(m)]
    ab_list.sort(key = itemgetter(1))
    del_max = -10
    ans = 0
    for ab in ab_list:
        if ab[0] - 1 > del_max:
            ans += 1
            del_max = ab[1] - 2
    print(ans)

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

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
# 最小公倍数
# def gcd(a, b):
#     if a < b:
#         a, b = b, a
#     while a % b != 0:
#         a, b = b, a % b
#     return b


## 最大公約数 
def lcm(a, b):
    y = a*b // gcd(a, b)
    return y

def many_lcm(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = lcm(tmp, l[i])
    return tmp
N = INT()
A = LIST()

lm = many_lcm(A)
# print(l)
B = []
for a in A:
    B.append(lm // a)
print(sum(B) % mod)




### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
# 最小公倍数
# def gcd(a, b):
#     if a < b:
#         a, b = b, a
#     while a % b != 0:
#         a, b = b, a % b
#     return b



def many_lcm(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = tmp * l[i]//gcd(tmp, l[i])
    return tmp
N = INT()
A = LIST()

lm = many_lcm(A)
ans = 0
for a in A:
    ans += lm // a
    
print(ans % mod)
### BUGGY CODE ###

n = int(input())
num = str(input())

password_list = []

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            target = num[i] + num[j] + num[k]
            if target not in password_list:
                password_list.append(target)
                

print(len(password_list))

### FIXED CODE ###

n = int(input())
num = input()
 
password_list = []
initial_list = []
initial_list2 = []
initial_list3 = []
 
for i in range(len(num)-2):
    initial_list2 = []
    if num[i] in initial_list:
        continue
    elif len(initial_list) == 10:
        break
    else:
        initial_list.append(num[i])
        for j in range(i+1,len(num)-1):
            initial_list3 = []
            if num[j] in initial_list2:
                continue
            elif len(initial_list2) == 10:
                break
            else:
                initial_list2.append(num[j])
                for k in range(j+1,len(num)):
                    if num[k] in initial_list3:
                        continue
                    elif len(initial_list3) == 10:
                        break
                    else:
                        initial_list3.append(num[k])
                        target = num[i] + num[j] + num[k]
                        if target not in password_list:
                            password_list.append(target)
                            
print(len(password_list))
### BUGGY CODE ###

# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()

for j in range(0, n-1, 1):
    if s[j] == "A" and s[j+1] == "C":
        aclist.append(j+1)

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    for i in range(len(aclist)):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue

    # Output
    print(ans)


### FIXED CODE ###

# 2019/04/28
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()

acgt = ["A", "C", "G", "T"]
acgtl = list()
acgtl.append(0)

# Search AC and make Accumed sum
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acgtl.append(acgtl[i]+1)
    else:
        acgtl.append(acgtl[i])
        
# Calc AC count
for x in range(q):
    l, r = map(int,input().split())
    ans = acgtl[r-1] - acgtl[l-1]
    print(ans)
### BUGGY CODE ###

N,K,C=map(int,input().split())
S=input()
i=0
d1=[-1]*N
for k in range(K):
    try:
        i+=S[i:].index('o')
    except:
        break
    d1[i]=k
    i+=C+1
i=0
d2=[-1]*N
for k in range(K-1,-1,-1):
    try:
        i+=S[N-1-i::-1].index('o')
    except:
        break
    d2[N-1-i]=k
    i+=C+1
print(*[i+1 for i in range(N) if d1[i]==d2[i]>=0],sep='\n')

### FIXED CODE ###

N,K,C=map(int,input().split())
S=input()
i=0
d1=[-1]*N
for k in range(K):
    while S[i]=='x' and i<N:
        i+=1
    if i==N:break
    d1[i]=k
    i+=C+1
i=0
d2=[-1]*N
for k in range(K-1,-1,-1):
    while S[N-1-i]=='x' and i<N:
        i+=1
    if i==N:break
    d2[N-1-i]=k
    i+=C+1
print(*[i+1 for i in range(N) if d1[i]==d2[i]>=0],sep='\n')
### BUGGY CODE ###

from itertools import product

S = input()
T = set()
for i in range(len(S)):
  for j in range(len(S)):
    T.add(S[i:i+j+1])

check = []
for i in range(len(S)+1):
  for per in product(["A","C","G","T"], repeat = i):
    per = "".join(per)
    check.append(per)
check = list(set(check))

ans = 0
for t in T:
  tt = "".join(t)
  if(tt in check):
    ans = max(ans, len(tt))
print(ans)

### FIXED CODE ###

import re
ptn = re.compile(r"(A|C|T|G)*")

S = input()
T = set()
xx=ptn.match("FAFA")
for i in range(len(S)):
  for j in range(len(S)):
    x = ptn.match(S[i:i+j+1])
    if(x.group(0)):
      T.add(len(x.group(0)))
try:
  print(max(T))
except:
  print(0)
### BUGGY CODE ###

balls = input().split(" ")

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])

bcnt = min( n, b )

if( b == 0 ):
  print( 0 )
else:
  cntb = 0
  while( n > 0 ):
    cntb += min( b, n )
    n -= (b + r)
  print( cntb )

### FIXED CODE ###

balls = input().split(" ")

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])


if( b == 0 ):
  print( 0 )
else:
  
  step = b + r 
  cnt = n // step
  remain = n % step
  bcnt = cnt * b + min( remain, b)
  
  print( bcnt )
### BUGGY CODE ###

import fractions

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

g = fractions.gcd(A, B)

C = []
for i in range(1, g+1):
    if g%i == 0:
        for j in range(2, i+1):
            k = set()
            while True:
                if i%j == 0:
                    i //= j
                    C.append(j)
                else:
                    break

print(len(set(C))+1)

### FIXED CODE ###

import fractions

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

x = fractions.gcd(A, B)

C = []

def cal(i):
    for j in range(2, int(-(-i**0.5//1))+1):
        while True:
            if i%j == 0:
                i //= j
                C.append(j)
            else:
                break
    if i != 1:
        C.append(i)
        
    return set(C)

print(1+len(cal(x)))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
a,b,n = map(int,input().split())

ans = 0
tmp = min(b, n)
for x in range(int(pow(n, 0.5)) + 1, n+1):
    #print(x)
    tmp1 = (a * x) // b - (a * (x // b))
    if tmp1 >= ans:
        ans = tmp1
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
a,b,n = map(int,input().split())
"""
ans = 0
tmp = min(b, n)
for x in range(int(pow(n, 0.5)) + 1, n+1):
    #print(x)
    tmp1 = (a * x) // b - (a * (x // b))
    if tmp1 >= ans:
        ans = tmp1
print(ans)
"""

x = min(b-1, n)
#print(x)
ans = (a * x) // b - (a * (x // b))
print(ans)
### BUGGY CODE ###

n = int(input())
L = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b,i])
P = []
L.sort()
for i in range(n-1):
    dist = min(abs(L[i][0]-L[i+1][0]),abs(L[i][1]-L[i+1][1]))
    P.append([dist,L[i][2],L[i+1][2]])
L = sorted(L, key = lambda x:x[1])
for i in range(n-1):
    dist = min(abs(L[i][0]-L[i+1][0]),abs(L[i][1]-L[i+1][1]))
    P.append([dist,L[i][2],L[i+1][2]])
P.sort()
par = [i for i in range(n)]
rank = [0]*n
def find(x,par):
    if x == par[x]:
        return par[x]
    else:
        return find(par[x],par)
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
for i in range(len(P)):
    if find(P[i][1],par) != find(P[i][2],par):
        ans += P[i][0]
        unite(P[i][1],P[i][2],par,rank)
print(ans)

### FIXED CODE ###

n = int(input())
L = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b,i])
P = []
L.sort()
for i in range(n-1):
    dist = min(abs(L[i][0]-L[i+1][0]),abs(L[i][1]-L[i+1][1]))
    P.append([dist,L[i][2],L[i+1][2]])
L = sorted(L, key = lambda x:x[1])
for i in range(n-1):
    dist = min(abs(L[i][0]-L[i+1][0]),abs(L[i][1]-L[i+1][1]))
    P.append([dist,L[i][2],L[i+1][2]])
P.sort()
par = [i for i in range(n)]
rank = [0]*n
def find(x,par):
    if x == par[x]:
        return par[x]
    else:
        return find(par[x],par)
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
for i in range(len(P)):
    if find(P[i][1],par) != find(P[i][2],par):
        ans += P[i][0]
        unite(P[i][1],P[i][2],par,rank)
print(ans)
### BUGGY CODE ###

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

big = 0

for i in range(M):
    A.sort(reverse=True)
    A[0] = A[0] // 2
    # print(A)
print(sum(A))


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] *= - 1

heapq.heapify(A)

for i in range(M):
    big = (heapq.heappop(A) * -1) // 2
    heapq.heappush(A, big * -1)

print(-sum(A))
### BUGGY CODE ###

N, M = map(int, input().split())
PY = [list(map(int,input().split())) for i in range(M)]
ken = {p[0] for p in PY}
ken_d = {k:[p[1] for p in PY if p[0] == k] for k in ken}

for k in ken_d.keys():
    ken_d[k].sort()

for p in PY:
    x = ken_d[p[0]].index(p[1]) + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))

### FIXED CODE ###

N, M = map(int, input().split())
import sys
PY = [list(map(int,sys.stdin.readline().rstrip().split())) for _ in range(M)]

# ken = {p[0] for p in PY}
# ken_d = {k:[] for k in ken}
ken_d = [[] for _ in range(N+1)]

rankdic = {} # 通し番号：県における順位

for i, p in enumerate(PY):
    # print(p)
    ken_d[p[0]].append([i, p[1]])

for k in range(N+1):
    ken_d[k].sort(key=lambda x:x[1])
    for i, v in enumerate(ken_d[k]):
        rankdic[v[0]] = i # 通し番号辞書に入れる

for i, p in enumerate(PY):
    x = rankdic[i] + 1
    print(str(p[0]).zfill(6) + str(x).zfill(6))
### BUGGY CODE ###

n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    k, l = list(map(int, input().split()))
    a.append(k)
    b.append(l)
sum = 0
money = 0
index = a.index(min(a))
while sum + b[index]< m:
    sum += b[index]
    money += a[index] * b[index]
    del a[index]
    del b[index]
    index = a.index(min(a))
money += (m - sum) * a[index]
print(money)


### FIXED CODE ###

n, m = list(map(int, input().split()))
a = []
b = []
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
sum = 0
money = 0
index = 0
while sum + data[index][1]< m:
    sum += data[index][1]
    money += data[index][0] * data[index][1]
    del data[index]
money += (m - sum) * data[index][0]
print(money)
### BUGGY CODE ###

# 最大公約数を格納するリストを初期化
max_codiv = []

# 繰り返す数を入力
n = int(input())

import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            i_j = math.gcd(i, j)
            i_j_k = math.gcd(i_j, k)
            max_codiv.append(i_j_k)
print(sum(max_codiv))

### FIXED CODE ###

# 最大公約数を格納するリストを初期化
max_codiv = []
 
# 繰り返す数を入力
n = int(input())
 
import math
# 1からkまでの総当たりで最大公約数を調べる
for i in range(1, n+1):
	for j in range(1, n+1):
		i_j = math.gcd(i, j)
		for k in range(1, n+1):
			i_j_k = math.gcd(i_j, k)
			max_codiv.append(i_j_k)
print(sum(max_codiv))
### BUGGY CODE ###

n=int(input())
L=[''.join(sorted(input())) for _ in range(n)]

L2={}
for i in range(n-1):
      for j in range(i+1,n):
            if L[i]==L[j]:
                  if L[i] not in L2:
                        L2[L[i]]=1
                  else:
                        L2[L[i]]+=1
print(sum(L2.values()))

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)
### BUGGY CODE ###

N, A, B = map(int, input().split())
l = []
l_a = ['b' for i in range(A)]
l_b = ['r' for i in range(B)]
for val in range(N):
    l += l_a
    l += l_b
cnt = 0
for val in range(N):
    if l[val] == 'b':
        cnt += 1
print(cnt)

### FIXED CODE ###

N, A, B = map(int, input().split())
x = N // (A + B)
y = N % (A + B)
if y < A:
    print(x*A + y)
else:
    print(x*A + A)