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

#!/usr/bin/python

import sys
import copy
from pprint import pprint

def solve(h, w, a):
    direct = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    count = 0
    a_tmp = copy.deepcopy(a)
    flag = True
    while True:
        s_count = 0
        for i in xrange(h):
            for j in xrange(w):
                if a[i][j] == "#":
                    s_count += 1
                    a_tmp[i][j] = "#"
                    for x, y in direct:
                        #print x, y
                        #print i+x, j+y
                        if 0 <= i + x < h and 0 <= j + y < w:
                            a_tmp[i+x][j+y] = "#"

        #print count
        #pprint(a)
        if s_count == h*w:
            return count
        a = copy.deepcopy(a_tmp)
        count += 1

if __name__ == '__main__':

    h, w = map(int, sys.stdin.readline().strip().split(" "))
    a = []
    for i in xrange(h):
       a.append([])
       line = sys.stdin.readline().strip()
       for j in xrange(w):
           a[i].append(line[j])
    #pprint(a)
    #sys.exit(1)
    ans = solve(h, w, a)
    print ans

### FIXED CODE ###

import sys
from pprint import pprint

from collections import deque

h, w = map(int, sys.stdin.readline().strip().split(" "))
field = []
for _ in range(h):
    field.append(list(sys.stdin.readline().strip()))

# pprint(field)

q = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            q.append((0, i, j))

while q:
    count, y, x = q.popleft()
    for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
        if 0 <= y+dy < h and 0 <= x+dx < w:
            # print(y+dy, x+dx, field[y+dy][x+dx])
            if field[y+dy][x+dx] == "#":
                continue
            else:
                field[y+dy][x+dx] = "#"
                q.append((count+1, y+dy, x+dx))

# pprint(field)
print(count)
### BUGGY CODE ###

H, W, D=map(int, input().split())
pos={}
for i in range(H):
    A=list(map(int, input().split()))
    for j in range(W):
        pos[A[j]]=(i, j)
Q=int(input())
for i in range(Q):
    p=0
    L, R=list(map(int, input().split()))
    for j in range((R-L)//D):
        p+=abs(pos[L+D*j][0]-pos[L+D*(j+1)][0])+abs(pos[L+D*j][1]-pos[L+D*(j+1)][1])
    print(p)


### FIXED CODE ###

H, W, D=map(int, input().split())
pos={}
for i in range(H):
    A=list(map(int, input().split()))
    for j in range(W):
        pos[A[j]]=(i, j)
p=[0]*(H*W+1)
for i in range(D+1,H*W+1):
    p[i]=p[i-D]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1])
Q=int(input())
for _ in range(Q):
    L, R=map(int, input().split())
    print(p[R]-p[L])
### BUGGY CODE ###

import math
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
MOD = 10 ** 9 + 7

ans = 0

def com(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

start = com(N - 1, K - 1)
x = N - 1

for i in range(N):
  if N - 1 - i >= K - 1:
    if ((i > 0) and (N - 1 - i > 0)):
      #print(start, x - i -K)
      start = start * (x - i - K + 2) // (x - i + 1)
      #print(start)
    ans += (A[- i - 1] - A[i]) * start
    ans = ans % MOD
    #print(ans, start,x - i)
    
print(ans % MOD)

### FIXED CODE ###

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
MOD = 10 ** 9 + 7

ans = 0

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

N2 = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N2 + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

#print(cmb(n, r, p))
for i in range(len(A)):
  if N - 1 - i >= K - 1:
    ans += (A[- i - 1] - A[i]) * cmb(N - 1 - i, K - 1, MOD)
    ans = ans % MOD
    
    
print(ans % MOD)
### BUGGY CODE ###

def solve():
    from sys import stdin
    from itertools import accumulate
    
    file_input = stdin
    
    N = int(file_input.readline())
    
    img = []
    acc_row = []
    
    for line in file_input:
        line = list(map(int, line.split()))
        img.append(line)
        acc_row.append(list(accumulate(line)) + [0])
    
    def acc_list(col):
        return list(accumulate(col)) + [0]
    acc_col = list(map(acc_list, zip(*img)))
    
    ans = 0
    for i, tpl_1 in enumerate(zip(img, acc_row)):
        img_row_i, acc_row_i = tpl_1
        for j, tpl_2 in enumerate(zip(img[i:], acc_row[i:]), start=i):
            img_row_j, acc_row_j = tpl_2
            
            single_row = acc_row_i[j] - acc_row_i[i - 1]
            if single_row > ans:
                ans = single_row
            
            if i == j:
                continue
            
            col = acc_col[0]
            col_max = col[j] - col[i - 1]
            
            for k, acc_col_k in enumerate(acc_col[1:], start=1):
                col = acc_col_k[j] - acc_col_k[i - 1]
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + img_row_i[k] + img_row_j[k]
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()


### FIXED CODE ###

from sys import stdin
from itertools import accumulate

def solve():
    file_input = stdin
    
    N = int(file_input.readline())
    G = tuple(tuple(map(int, line.split())) for line in file_input)
    G1 = tuple(t[1:] for t in G)
    
    # accumulated rows
    ar = ((0,) + tuple(accumulate(line)) for line in G)
    
    # accumulated columns
    ac = ((0,) + tuple(accumulate(line)) for line in zip(*G))
    ac_1 = next(ac)
    ac = tuple(zip(*ac))
    
    ans = 0
    for i, t1 in enumerate(zip(G1, ar, ac, ac_1)):
        G_i, ar_i, ac_i, ac_1i = t1
        ar_ii = ar_i[i]
        for j, t2 in enumerate(zip(G1[i:], ar_i[i+1:], ac[i+1:], ac_1[i+1:]), start=i):
            G_j, ar_ij, ac_j, ac_1j = t2
            single_row = ar_ij - ar_ii
            if single_row > ans:
                ans = single_row
                
            if i == j:
                continue
            
            col_max = ac_1j - ac_1i
            
            for ac_jk, ac_ik, G_ik, G_jk in zip(ac_j, ac_i, G_i, G_j):
                col = ac_jk - ac_ik
                
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + G_ik + G_jk
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()
### BUGGY CODE ###

import math
K = int(input())
ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      ans += math.gcd(math.gcd(a, b), c)
print(ans)

### FIXED CODE ###

import math
# from itertools import product
from functools import reduce

def main():
#     def gcd(*numbers): return reduce(math.gcd, numbers)
    K = int(input())
    ans = 0
#     valiation = list(itertools.product(range(1, K+1), repeat=3))
#     for v in valiation:
#         ans += gcd(v)
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                ans += math.gcd(math.gcd(i, j), k)
    print(ans)
        
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

import math
def cmb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)    

### FIXED CODE ###

N = int(input())
S = [''.join(sorted(list(input()))) for _ in range(N)]
 
from collections import Counter
a=Counter(S)
 
ans = 0
 
for i in a.values():
    if i>1:
        ans += i*(i-1)/2
 
print(int(ans))
### BUGGY CODE ###

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

from functools import reduce
import fractions

def gcd(num_list):
    return reduce(fractions.gcd, num_list)

max_kys = 0

for i in range(N):
    B = A.copy()
    del B[i]
    max_kys = max(max_kys, gcd(B))

print(max_kys)

### FIXED CODE ###

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

index = list(range(N))
L = index.copy()

L[0] = 0
for i in index[:-1]:
    #print(i)
    L[i+1] = gcd(L[i], A[i])

R = index.copy()
R.append(0)
for i in reversed(index):
    #print(i)
    R[i] = gcd(R[i+1], A[i])

# confirm
#print(L)
#print(R)

M = []
for j in range(len(L)):
    m = gcd(L[j], R[j+1])
    #print(m)
    M.append(m)

# Confirm
#print(M)

# Answer
print(max(M))
### BUGGY CODE ###


def resolve():
    INF = 10 ** 18
    N, M = map(int, input().split())

    Cost = [0] * M
    Box_key = [0] * M
    for i in range(M):
        a, b = map(int, input().split())
        Cost[i] = a
        C = list(map(int, input().split()))
        Box_key[i] = sum(1 << (c - 1) for c in C)

    # dp[ i ][ S ] := 最初の i 個の鍵からいくつか選んで、
    # 開いた宝箱の集合が S で表されるような場合についての、最小コスト
    dp = [[INF] * (1 << N) for _ in range(M + 1)]
    dp[0][0] = 0

    for i in range(M):
        for j in range(1 << N):
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
            dp[i + 1][j | Box_key[i]] = min(dp[i + 1][j | Box_key[i]], dp[i][j] + Cost[i])

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

N, M = map(int, input().split())
N2 = 2**N
INF = float("inf")
X = [INF]*N2
X[0] = 0

for i in range(M):
  a, b = map(int, input().split())
  C = list(map(int, input().split()))
  
  k = sum(1<<(c-1) for c in C)
    
  for j in range(N2):
    if X[j|k] > X[j] + a:
      X[j|k] = X[j] + a

ans = X[-1]      
if ans >= INF:
  ans = -1
print(ans)
### BUGGY CODE ###

import math
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

score=0
for j in range(n):
  i=0
  while i < j:
    score += a[i]*a[j]
    i += 1
print(score%mod)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))
### BUGGY CODE ###

N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

#dp[i][j]は、品数i,重さjのときの価値
dp =[[0 for i in range(W+1)] for j in range(N+1)] 
#表で表す

for i in range(N):#これは品数.i番目の品のオンオフ
    for j in range(W+1):#これは許容される重さの合計
        #選ぶ場合
        if j - w[i]>=0:
            dp[i+1][j]=max(dp[i][j],(dp[i][j-w[i]]+v[i]))
        #選ばない場合と比較
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])

print(dp[N][W])

### FIXED CODE ###

N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

#dp[i][j]は、品数i,重さjのときの価値
dp =[[0 for i in range(W+1)] for j in range(N+1)] 
#表で表す

for i in range(N):#これは品数.i番目の品のオンオフ
    for j in range(W+1):#これは許容される重さの合計
        #選ぶ場合
        if j - w[i]>=0:
            dp[i+1][j]=max(dp[i][j],(dp[i][j-w[i]]+v[i]))
        #選ばない場合と比較
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])

print(dp[N][W])
### BUGGY CODE ###

n = int(input())
l = [str(input()) for _ in range(n)]
# l = set(l)

m = [-1]*n
ans = 0

for i in range(n-1):
  if m[i] >= 0:
    continue
  else:
    si = l[i]
    m[i] = i
    temp  = 0
    for j in range(i+1, n):
      if m[j] >= 0:
        continue
      else:
        sj = l[j]
        if sorted(si) == sorted(sj): 
          temp += 1
          m[j] = i
          #print(i, temp)
  ans += (temp+1)*temp/2

print(int(ans))




### FIXED CODE ###

n = int(input())
l = [str(sorted(str(input()))) for _ in range(n)]

d = {}

for i in range(n):
  s = l[i]
  # print(s)
  if s in d:
    d[s] += 1
  else:
    d[s] = 1

ans = 0
for x in d.values():
  ans += x*(x-1)/2
print(int(ans))
### BUGGY CODE ###

k=int(input())
ans=0
import math
for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      p=math.gcd(i,j)
      ans+=math.gcd(p,k)
print(ans)

### FIXED CODE ###

n=int(input())+1
import math
ans=0
for i in range(1,n):
    ans+=n-i
    for j in range(i+1,n):
        p=math.gcd(n-i,n-j)
        ans+=p*6
        for k in range(j+1,n):
            ans+=math.gcd(p,n-k)*6
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque

h, w = map(int, input().split())
grid = [None for _ in range(h)]
poss = [[set() for x in range(w)] for y in range(h)]
tmp = [map(int, input().split()) for _ in range(h * 2)]
for i, (l1, l2) in enumerate(zip(tmp, tmp[h:])):
	grid[i] = [abs(x - y) for x, y in zip(l1, l2)]
q = deque([(0, 0)])
poss[0][0].add(-grid[0][0])
poss[0][0].add(grid[0][0])
while q:
	cx, cy = q.popleft()
	for dx, dy in ((1, 0), (0, 1)):
		nx = cx + dx
		ny = cy + dy
		if not (0 <= nx <= w - 1 and 0 <= ny <= h - 1):
			continue
		m = grid[ny][nx]
		poss[ny][nx] |= set(l + m for l in poss[cy][cx])
		poss[ny][nx] |= set(l - m for l in poss[cy][cx])
		q.append((nx, ny))
print(min(abs(x) for x in poss[-1][-1]))


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

h, w = map(int, input().split())
a = [map(int, input().split()) for _ in range(h)]
b = [map(int, input().split()) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [[0] * w for _ in range(h)]
poss[0][0] |= 1 << 6400 + g[0][0]
poss[0][0] |= 1 << 6400 - g[0][0]
for i in range(h):
	for j in range(w - 1):
		poss[i][j + 1] |= poss[i][j] << g[i][j + 1]
		poss[i][j + 1] |= poss[i][j] >> g[i][j + 1]
	if i != h - 1:
		for j in range(w):
			poss[i + 1][j] |= poss[i][j] << g[i + 1][j]
			poss[i + 1][j] |= poss[i][j] >> g[i + 1][j]
res = poss[-1][-1]
for i in range(6400):
	if res & (1 << 6400 + i) or res & (1 << 6400 - i):
		print(i)
		exit()
### BUGGY CODE ###

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

from collections import defaultdict

# union find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N)
REL = defaultdict(set)

for _ in range(M):
    a, b = map(int, input().split())
    # REL[a].add(b)
    # REL[b].add(a)
    a -= 1
    b -= 1
    if a > b:
        c = b
        b = a
        a = c

    uf.union(a, b)

mm = 0
for root in uf.roots():
    mm = max(mm, len(uf.members(root)))

ic = 0
for m in range(N):
    if uf.members(m) == 0:
        ic += 1

if mm < ic:
    mm += 1

print(mm)

### FIXED CODE ###

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

from collections import defaultdict

# union find
class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n
 
    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        c = b
        b = a
        a = c

    uf.union(a, b)

# member = defaultdict(int)
r = min(uf.table)
if r != -1:
    mm = abs(r)
    # ic = 0
    # for n in uf.table:
    #     if n == -1:
    #         ic += 1

    # if ic%mm != 0:
    #     mm += 1
else:
    mm = 1

print(mm)
### BUGGY CODE ###

n = int(input())
INF = 10 ** 9
info = [list(input().split()) for i in range(2 * n)]

ind = {}
for i in range(2 * n):
    info[i] = (info[i][0], int(info[i][1]))
    ind[info[i]] = i

ru_b = [[0] * (2 * n + 1) for i in range(n + 1)]
ru_w = [[0] * (2 * n + 1) for i in range(n + 1)]
for i in range(n + 1):
    for j in range(2 * n):
        col, num = info[j]
        if col == "B" and num > i:
            ru_b[i][j + 1] += 1
        if col == "W" and num > i:
            ru_w[i][j + 1] += 1
    for j in range(2 * n):
        ru_b[i][j + 1] += ru_b[i][j]
        ru_w[i][j + 1] += ru_w[i][j]    


dp = [[INF] * (n + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
    for j in range(n + 1):
        if i + 1 <= n and j <= n:
            bi = ind[("B", i + 1)]
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ru_b[i][bi] + ru_w[j][bi])
        if i <= n and j + 1 <= n:
            wi = ind[("W", j + 1)]
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + ru_w[j][wi] + ru_b[i][wi])

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

### FIXED CODE ###

import sys
input = sys.stdin.readline


n = int(input())
INF = 10 ** 9
info = [list(input().split()) for i in range(2 * n)]

ind = {}
for i in range(2 * n):
    if info[i][0] == "B":
        info[i] = (0, int(info[i][1]))
    else:
        info[i] = (1, int(info[i][1]))
    ind[info[i][0] * 10 ** 5 + info[i][1]] = i

ru_b = [[0] * (2 * n + 1) for i in range(n + 1)]
ru_w = [[0] * (2 * n + 1) for i in range(n + 1)]
for i in range(n + 1):
    for j in range(2 * n):
        col, num = info[j]
        if col == 0 and num > i:
            ru_b[i][j + 1] += 1
        elif col == 1 and num > i:
            ru_w[i][j + 1] += 1
    for j in range(2 * n):
        ru_b[i][j + 1] += ru_b[i][j]
        ru_w[i][j + 1] += ru_w[i][j]    


dp = [[INF] * (n + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
    for j in range(n + 1):
        if i + 1 <= n and j <= n:
            bi = ind[i + 1]
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ru_b[i][bi] + ru_w[j][bi])
        if i <= n and j + 1 <= n:
            wi = ind[10 ** 5 + j + 1]
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + ru_w[j][wi] + ru_b[i][wi])

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

n = int(input())
a = list(map(int, input().split()))
ans = [0]*n

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if a[i]%a[j] == 0:
            ans[i] = 1
            break

print(ans.count(0))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
aMax = a[-1]
ans = 0
dp = [1] * (aMax+1)

for i in range(n-1):
    p = a[i]
    if dp[p] == 1:
        for j in range(aMax//p+1):
            dp[p*j] = 0
        if a[i] != a[i+1]:
            ans += 1
if dp[aMax] == 1:
    ans += 1
print(ans)
### BUGGY CODE ###

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

def largest(a,b,c):
  if a <= b:
    if a<= c:
      return a
    else:
      return c
  else:
    if b<=c:
      return b
    else:
      return c
    
def absol(d):
  if d < 0:
    return -d
  else:
    return d
    
def dist(i,j):
  return largest(j-i, absol(x-i) + absol(y-j) + 1, absol(x-j) + absol(y-i) + 1)

listlist = [0]*(n-1)

for i in range(1,n):
  for j in range(i+1,n+1):
    distance = dist(i,j)
    listlist[distance-1] = listlist[distance-1] + 1
    
for k in range(0, n-1):
  print(listlist[k])
  

### FIXED CODE ###

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

def dist(i,j):
  return min(j-i, abs(x-i) + abs(y-j) + 1, abs(x-j) + abs(y-i) + 1)

listlist = [0]*(n-1)

for i in range(1,n):
  for j in range(i+1,n+1):
    distance = dist(i,j)
    listlist[distance-1] = listlist[distance-1] + 1
    
for k in listlist:
  print(k)
### BUGGY CODE ###

#


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    # これだとTLE
    counts = {}
    for i in a:
        if i in counts:
            counts[i] += 1
        else:
            counts[i] = 1
    delete_key = set()
    for k in counts:
        if counts[k] <= 1:
            delete_key.add(k)
    for k in delete_key:
        del counts[k]
    results = {}
    for i in a:
        if i in results:
            print(results[i])
            continue
        count = 0
        for k, v in counts.items():
            if k == i:
                v -= 1
            if v > 1:
                count += (v * (v - 1) // 2)
        print(count)
        results[i] = count


if __name__ == '__main__':
    main()


### FIXED CODE ###

#


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    counts = {}
    for i in a:
        if i in counts:
            counts[i] += 1
        else:
            counts[i] = 1
    # これだとTLE
    # results = {}
    # for i in a:
    #     if i in results:
    #         print(results[i])
    #         continue
    #     count = 0
    #     for k, v in counts.items():
    #         if k == i:
    #             v -= 1
    #         if v > 1:
    #             count += (v * (v - 1) // 2)
    #     print(count)
    #     results[i] = count
    total = 0
    comb = {}
    for k in counts:
        if counts[k] > 1:
            y = counts[k]
            x = (y * (y - 1)) // 2
            total += x
            comb[k] = x
        else:
            comb[k] = 0
    for i in a:
        print(total - (counts[i] - 1))


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

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

    leng = 0
    ans = 0

    while n >= leng:
        if a < (n - leng):
            ans += a
            leng += (a + b)
        else:
            ans += n - leng
            leng += (a + b)

    print(ans)



    # if a >= n:
    #     print(n)
    # else:
    #     print(a)


if __name__ == '__main__':
    main()

### FIXED CODE ###

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

    tmp = n // (a + b)

    if n - tmp * (a + b) > a:
        print(tmp * a + a)
    else:
        print(tmp * a + n - tmp * (a + b))

    # TLE
    # while n >= leng:
    #     if a < (n - leng):
    #         ans += a
    #         leng += (a + b)
    #     else:
    #         ans += n - leng
    #         leng += (a + b)

    # if a >= n:
    #     print(n)
    # else:
    #     print(a)


if __name__ == '__main__':
    main()