CodeEff/ECCO huggingface dataset:
# Original solution
M, N = list(map(int, input().split()))
K = eval(input())

D = {}

for i in range(M+1):
    D[i, 0] = 0, 0
for j in range(N+1):
    D[0, j] = 0, 0

for i in range(1, M+1):
    a = input()
    for j in range(1, N+1):
        if a[j-1] == 'J':
            D[i, j] = (D[i-1, j][0] + D[i, j-1][0] - D[i-1, j-1][0] + 1,
                       D[i-1, j][1] + D[i, j-1][1] - D[i-1, j-1][1])
        elif a[j-1] == 'O':
            D[i, j] = (D[i-1, j][0] + D[i, j-1][0] - D[i-1, j-1][0],
                       D[i-1, j][1] + D[i, j-1][1] - D[i-1, j-1][1] + 1)
        else:
            D[i, j] = (D[i-1, j][0] + D[i, j-1][0] - D[i-1, j-1][0],
                       D[i-1, j][1] + D[i, j-1][1] - D[i-1, j-1][1])

for _ in range(K):
    b0, b1, b2, b3 = list(map(int, input().split()))
    nJ = D[b2, b3][0]-D[b0-1, b3][0]-D[b2, b1-1][0]+D[b0-1, b1-1][0]
    nO = D[b2, b3][1]-D[b0-1, b3][1]-D[b2, b1-1][1]+D[b0-1, b1-1][1]
    nI = (b2-b0+1)*(b3-b1+1)-nJ-nO
    print(nJ, nO, nI)

# Optimized solution
from array import array

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

D0 = [array('l', [0]) * (N+1) for _ in range(M+1)]
D1 = [array('l', [0]) * (N+1) for _ in range(M+1)]

for i in range(1, M+1):
    a = input()
    for j in range(1, N+1):
        D0[i][j] = D0[i-1][j] + D0[i][j-1] - D0[i-1][j-1] + (a[j-1] == 'J')
        D1[i][j] = D1[i-1][j] + D1[i][j-1] - D1[i-1][j-1] + (a[j-1] == 'O')

for _ in range(K):
    b0, b1, b2, b3 = list(map(int, input().split()))
    nJ = D0[b2][b3]-D0[b0-1][b3]-D0[b2][b1-1]+D0[b0-1][b1-1]
    nO = D1[b2][b3]-D1[b0-1][b3]-D1[b2][b1-1]+D1[b0-1][b1-1]
    nI = (b2-b0+1)*(b3-b1+1)-nJ-nO
    print(nJ, nO, nI)
# Original solution
n = eval(input())
code = input().split()
# DP(N, <parentheses nested>)
dp = [[0]*3 for i in range(n)]
dp[0] = [int(code[0]), -10**18, -10**18]
for i in range(1,n):
    op, a = code[2*i-1: 2*i+1]
    v = int(a)
    if op is "+":
        dp[i][0] = max(dp[i-1][0]+v, dp[i-1][1]-v, dp[i-1][2]+v)
        dp[i][1] = max(              dp[i-1][1]-v, dp[i-1][2]+v)
        dp[i][2] =                                 dp[i-1][2]+v
    else:
        dp[i][0] = max(dp[i-1][0]-v, dp[i-1][1]+v, dp[i-1][2]-v)
        dp[i][1] = max(dp[i-1][0]-v, dp[i-1][1]+v, dp[i-1][2]-v)
        dp[i][2] = max(              dp[i-1][1]+v, dp[i-1][2]-v)
print(max(dp[-1]))

# Optimized solution
n = eval(input())
code = input().split()
# DP(N, <parentheses nested>)
a = int(code[0]); b = c = -10**18
for op, v in zip(code[1::2], list(map(int,code[2::2]))):
    if op is "+":
        d = max(b-v, c+v)
        a,b,c = max(a+v, d), d, c+v
    else:
        d = max(b+v, c-v)
        a,b,c = max(a-v, d), max(a-v, d), d
print(max(a, b, c))
# Original solution
import itertools
while True:
    N = int(eval(input()))
    if not N:
        break
    D = [[] for _ in range(30)]
    for i in range(N):
        for x in map(int, input().split()[1:]):
            D[x - 1].append(i)
    C = [1 << i for i in range(N)]
    for d in range(30):
        for i, j in itertools.permutations(D[d], 2):
            C[i] = C[i] | C[j]
        if any(x == (1 << N) - 1 for x in C):
            print((d + 1))
            break
    else:
        print((-1))

# Optimized solution
import itertools
while True:
    N = int(eval(input()))
    if not N:
        break
    D = [[] for _ in range(30)]
    for i in range(N):
        for x in map(int, input().split()[1:]):
            D[x - 1].append(i)
    C = [1 << i for i in range(N)]
    for d in range(30):
        for i, j in itertools.combinations(D[d], 2):
            C[i] = C[j] = C[i] | C[j]
        if any(x == (1 << N) - 1 for x in C):
            print((d + 1))
            break
    else:
        print((-1))
# Original solution
MAX_N = 50
MAX_DAY = 30

def solve(n, f):
    dp = [[set() for j in range(n)] for i in range(MAX_DAY + 1)]
    for i in range(n):
        dp[0][i].add(i)

    for d in range(1, MAX_DAY + 1):

        # for line in dp[:5]:
        #     print(line)

        for i in range(n):
            dp[d][i] |= dp[d - 1][i]
            for j in range(n):
                if f[d][i] and f[d][j]:
                    dp[d][i] |= dp[d - 1][j]

            if len(dp[d][i]) == n:
                return d

    return -1

######################################

while True:
    n = int(eval(input()))
    if n == 0:
        exit()

    f = [[False] * n for i in range(MAX_DAY + 1)]
    for i in range(n):
        _, *li = list(map(int, input().split()))
        for x in li:
            f[x][i] = True

    # for line in f:
    #     print(line)

    print((solve(n, f)))

# Optimized solution
MAX_N = 50
MAX_DAY = 30

def solve(n, f):
    dp = [{i} for i in range(n)]

    for d in range(1, MAX_DAY + 1):
        for i in range(n):
            for j in range(n):
                if f[d][i] and f[d][j]:
                    dp[i] |= dp[j]

            if len(dp[i]) == n:
                return d

    return -1

######################################

while True:
    n = int(eval(input()))
    if n == 0:
        exit()

    f = [[False] * n for i in range(MAX_DAY + 1)]
    for i in range(n):
        _, *li = list(map(int, input().split()))
        for x in li:
            f[x][i] = True

    print((solve(n, f)))
# Original solution
ref = "SCHD"
first = 0
while 1:
	try:
		n = eval(input())
		if first: print()
		first = 1
	except:
		break
	P = [list(map(int,input().split())) for i in range(4)]
	H = list(map(int,input().split()))
	for _ in range(n):
		hand = input().replace("A","1").replace("T","10").replace("J","11").replace("Q","12").replace("K","13").split()
		num  = [int(i[:-1]) for i in hand]
		suit = [ref.index(i[-1]) for i in hand]
		ans  = sum(P[suit[i]][num[i]-1] for i in range(5))
		if len(set(suit)) == 1:
			if sorted(num) == [1,10,11,12,13]:
				ans *= H[8]
			elif sorted([i - min(num) for i in num]) == [0,1,2,3,4]:
				ans *= H[7]
			else:
				ans *= H[4]
		elif sorted([i - min(num) for i in num]) == [0,1,2,3,4] or sorted(num) == [1,10,11,12,13]:
			ans *= H[3]
		elif max(num.count(i) for i in set(num)) == 4:
			ans *= H[6]
		elif max(num.count(i) for i in set(num)) == 3:
			if len(set(num)) == 2:
				ans *= H[5]
			else:
				ans *= H[2]
		elif max(num.count(i) for i in set(num)) == 2:
			if len(set(num)) == 3:
				ans *= H[1]
			else:
				ans *= H[0]
		else:
			ans = 0
		print(ans)

# Optimized solution
ref = "SCHD"
first = 0
while 1:
	try:
		n = eval(input())
		if first: print()
		first = 1
	except:
		break
	P = [list(map(int,input().split())) for i in range(4)]
	H = list(map(int,input().split()))
	for _ in range(n):
		hand = input().replace("A","1").replace("T","10").replace("J","11").replace("Q","12").replace("K","13").split()
		num  = [int(i[:-1]) for i in hand]
		suit = [ref.index(i[-1]) for i in hand]
		ans  = sum(P[suit[i]][num[i]-1] for i in range(5))
		snum = sorted([i - min(num) for i in num])
		same = max(num.count(i) for i in set(num))
		if len(set(suit)) == 1:
			if snum == [0,9,10,11,12]:
				ans *= H[8]
			elif snum == [0,1,2,3,4]:
				ans *= H[7]
			else:
				ans *= H[4]
		elif snum == [0,1,2,3,4] or snum == [0,9,10,11,12]:
			ans *= H[3]
		elif same == 4:
			ans *= H[6]
		elif same == 3:
			if len(set(num)) == 2:
				ans *= H[5]
			else:
				ans *= H[2]
		elif same == 2:
			if len(set(num)) == 3:
				ans *= H[1]
			else:
				ans *= H[0]
		else:
			ans = 0
		print(ans)
# Original solution
A, B, C, D, E, F = list(map(int, input().split(' ')))
water = []
for i in range(31):
    if A*i >= F:
        break
    for j in range(16):
        if 100 * (A*i + B*j) < F:
            water.append(100*(A*i+B*j))
        else:
            break
water = sorted(list(set(water)))

sugar = []
for i in range(max(water)//100*E//C + 1):
    for j in range(max(water)//100*E//D + 1):
        temp_sugar = C*i + D*j
        if temp_sugar + water[1] <= F:
            sugar.append(temp_sugar)
        else:
            break
sugar = sorted(list(set(sugar)))

max_conc = 0
ans_W = 100*A
ans_sugar = 0
for W in water:
    if W == 0:
        continue
    for S in sugar:
        if S+W <= F and S <= W*E//100:
            if max_conc < S/(W+S):
                max_conc = S/(S+W)
                ans_W = W
                ans_sugar = S
        else:
            break
print(('{0} {1}'.format(ans_W+ans_sugar, ans_sugar)))


# Optimized solution
A, B, C, D, E, F = list(map(int, input().split(' ')))

max_sugar = 0
max_water = 100*A
max_conc = 0.0
A_limit = F // (100*A)
for i in range(A_limit + 1):
    B_limit = (F-100*A*i) // (100*B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A*i+B*j), F-100*(A*i+B*j))

        sugar_ = 0
        for c in range(sugar_limit//C + 1):
            d = (sugar_limit-c*C)//D
            temp_sugar = c*C + d*D
            sugar_ = max(sugar_, temp_sugar)
        temp_conc = sugar_/(sugar_+100*(A*i+B*j))
        if temp_conc > max_conc:
            max_conc = temp_conc
            max_water = 100*(A*i + B*j)
            max_sugar = sugar_
print(('{0} {1}'.format(max_water+max_sugar, max_sugar)))
# Original solution
N, A, B = list(map(int, input().split()))

x = N // (A + B)
ans = A * x
ans = ans + min(N - (A+B) * x, A)
print(ans)

# Optimized solution
N, A, B = list(map(int, input().split()))

st = N // (A+B)
plus = min(N%(A+B), A)

ans = A * st + plus
print(ans)
# Original solution
n, a, b = list(map(int, input().split()))

c = 0


for i in range(0, n//(a+b)):
    c = a * (n//(a+b))

if n%(a+b) > a:
    c += a
else:
    c += n%(a+b)
    
print(c)

# Optimized solution
n, a, b = list(map(int, input().split()))

cycles = n//(a+b)
count = 0
count += a*cycles
rest = n - (a+b)*cycles
if rest > a:
    count += a
else:
    count += rest
print(count)
# Original solution
N, A, B = list(map(int, input().split(' ')))
 
blue = 0
if N!=0 and A!=0:
    for i in range(int(N/(A+B))+1):
        if i==int(N/(A+B)):
            if N%(A+B) <= A:
                blue += N%(A+B)
            else:
                blue += A 
        else:
            blue += A

print(blue)

# Optimized solution
N, A, B = list(map(int, input().split(' ')))
 
blue = 0
if N!=0 and A!=0:    
    blue = A *int(N/(A+B))
    if N%(A+B) <= A:
        blue += N%(A+B)
    else:
        blue += A 
print(blue)
# Original solution
n,b,r=list(map(int,input().split()));print(((n//(b+r))*b+min(b,n%(b+r))))

# Optimized solution
n,b,r=list(map(int,input().split()));c=b+r;print(((n//c)*b+min(b,n%c)))
# Original solution
N, A, B = list(map(int, input().split()))

syou = N // (A + B)
mod = N % (A + B)

ans = A * syou

if (mod <= A):
    ans += mod
else:
    ans += A

print(ans)

# Optimized solution
N, A, B = list(map(int, input().split()))

syou = N // (A + B)
mod = N % (A + B)

ans = A * syou

ans += min(A, mod)

print(ans)
# Original solution
n,a,b = list(map(int, input().strip().split()))
t = n // (a+b)
s = n % (a+b)
if s > a:
    print((t*a+a))
else:
    print((t*a+s))

# Optimized solution
n, a, b = list(map(int, input().split()))
ans = (n//(a+b)) * a
ans += n % (a+b) if ((n % (a+b)) <= a) else a
print(ans)
# Original solution
n, a, b = list(map(int, input().split()))
c = a + b
print((n // c * a + min(n % c, a)))


# Optimized solution
n, a, b = list(map(int, input().split()))
b += a
print((n // b * a + min(n % b, a)))
# Original solution
n,a,b = list(map(int, input().split(" ")))

Aball = ""
for i in range(a):
    Aball+="b"
Bball = ""
for i in range(b):
    Bball+="a"

t = ""
while len(t) <= n:
    t+=Aball
    if len(t)>n:
        t = t[:n]
        break
    t+=Bball
    if len(t)>n:
        t = t[:n]
        break
count = t.count("b")
print(count)


# Optimized solution
n,a,b = list(map(int, input().split(" ")))

count = a*(n//(a+b))

add = n%(a+b)
if add < a:
    count+=add
else:
    count+=a
print(count)
# Original solution
n, a, b = list(map(int, input().split()))
l = list('')
while len(l) <= n:
    for i in range(a):
        l.append('blue')
    for i in range(b):
        l.append('red')
count = 0
for i in range(n):
    if l[i] == 'blue':
        count += 1
print(count)

# Optimized solution
n, a, b = list(map(int, input().split()))
mod = int(n % (a + b))
cycle = n // (a + b)
if mod == 0:
    print((a * cycle))
elif mod > a:
    print((a * cycle + a))
else: 
    print((a * cycle + mod))
# Original solution
N, A, B = list(map(int, input().split()))
list=[]
m=0

def add(i,j):
  while(i<A):
    list.append("b")
    i+=1

  while(j<B):
    list.append("r")
    j+=1

while(m<N):
    i=0
    j=0
    add(i,j)
    m+=A
    m+=B

l=list[0:N]
r=l.count("b")
print(r)

# Optimized solution
N, A, B = list(map(int, input().split()))

if(A==0 & B==0):
  print("0")

else:
  r=N//(A+B)
  s=N%(A+B)
  if(A<s):
    s=A
  if(A!=0):
    t=(A*r)+s
  else:
    t=0
  print(t)
# Original solution
N, b, r = list(map(int, input().split()))
str = ''
loop, cnt, bcnt = 0, 0, 0
while(cnt <= N):
  if loop%2 == 0:
    cnt += b
    bcnt += b
    if N - cnt < 0:
      bcnt += (N-cnt)
  elif loop%2 == 1:
    cnt += r
  loop += 1

print(bcnt)

# Optimized solution
N, b, r = list(map(int, input().split()))
if b==0 and r==0:
  print((0))
  exit()
  
c = N//(b+r)
if N%(b+r) == 0:
  print((b*c))
else:
  if N%(b+r) <= b:
    print((c*b + N%(b+r)))
  else:
    print((b*c + b))
# Original solution
# -*- coding: utf-8 -*-

N, A, B = input().split() 
balls = []
bBalls = []
rBalls = []

for i in range(int(A)):
    rBalls.append("b")

for i in range(int(B)):
    rBalls.append("r")

answer = 0
isBreak = False
for i in range(10**100):
   balls = bBalls + rBalls + balls
   if( len(balls) > int(N) ) :
       for c in range(int(N)):
           if(balls[c] == "b") :
               answer = answer +1
               isBreak = True
       isBreak = True
   if( isBreak ) :
       break

print(answer)


# Optimized solution
# -*- coding: utf-8 -*-

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

x = (N // (A + B)) * A 
mod = N % (A + B)
if mod <= A :
    z = mod
else :
    z = A

print((x + z))
# Original solution
n, a, b = list(map(int, input().split()))

acnt = 0
bcnt = 0
while True:
    acnt += a
    if acnt + bcnt >= n:
        acnt -= (acnt + bcnt) - n
        break
    bcnt += b
    if acnt + bcnt >= n:
        break
print(acnt)


# Optimized solution
n, a, b = list(map(int, input().split()))
amari = n % (a+b)
sho = n // (a+b)
if n <= a:
    print(n)
elif amari == 0:
    print((a*sho))
elif amari < a:
    print((a*sho + amari))
else:
    print((a*sho + a))
# Original solution
n, a, b = list(map(int, input().split()))
amari = n % (a+b)
sho = n // (a+b)
if n <= a:
    print(n)
elif amari == 0:
    print((a*sho))
elif amari < a:
    print((a*sho + amari))
else:
    print((a*sho + a))


# Optimized solution
n, a, b = list(map(int, input().split()))
amari = n % (a + b)
sho = n // (a + b)
if n <= a:
    print(n)
else:
    print((a * sho + min(a, amari)))
# Original solution
n, a, b = list(map(int, input().split()))
ans = []
while (True):
    for _ in range(a):
        ans.append('b')
    if len(ans) >= n:
        break
    for _ in range(b):
        ans.append('r')
    if len(ans) >= n:
        break
print((ans[:n].count('b')))


# Optimized solution
n, a, b = list(map(int, input().split()))
ans = (n//(a+b)) * a
if n % (a+b) > a:
    print((ans + a))
else:
    print((ans + n % (a+b)))
# Original solution
# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = list(map(int, input().split()))
rmult = 0
bmult = 0
total = 0
it = 1
ended = ''
while n > total:
    total += a
    bmult += 1
    ended = 'b'
    if n > total:
        total += b
        rmult += 1
        ended = 'r'
if ended == 'b':
    numofb = a * bmult - (total - n)
else:
    numofb = a * bmult
print(numofb)


# Optimized solution
# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = list(map(int, input().split()))
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
    temp = a * x + b * x
    x += 1
temp = a * x + b * x
if temp - b >= n:
    temp = temp - b
    endsWithA = True
else:
    endsWithA = False
if endsWithA:
    print((a * x - (temp - n)))
else:
    print((a * x))
# Original solution
# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = list(map(int, input().split()))
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
    temp = a * x + b * x
    x += 1
temp = a * x + b * x
if temp - b >= n:
    temp = temp - b
    endsWithA = True
else:
    endsWithA = False
if endsWithA:
    print((a * x - (temp - n)))
else:
    print((a * x))


# Optimized solution
n, a, b = list(map(int, input().split()))
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
    temp = a * x + b * x
    x += 1
temp = a * x + b * x
if temp - b >= n:
    temp = temp - b
    print((a * x - (temp - n)))
else:
    print((a * x))
# Original solution
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
boll_a = ''
boll_b = ''
count = ''
for j in range(0, a):
  boll_a += 'b'
for k in range(0, b):
  boll_b += 'r'
for i in range(0, n):
  count += boll_a
  count += boll_b
  if len(count) >= n: break
c = 0
for i in count[:n]:
  if i == 'b':
    c += 1
print(c)

# Optimized solution
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
l = ''
boll_a = ''
boll_b = ''
for j in range(0, a):
  boll_a += 'b'
for k in range(0, b):
  boll_b += 'r'
while n >= len(l):
  l += boll_a
  l += boll_b

print((l[:n].count('b')))
# Original solution
N,A,B=list(map(int,input().split()))

count=0

count_blue=0

while count<N-(A+B):
    count_blue+=A
    count+=A+B

if N-count<A:
    count_blue+=N-count
    
else:
    count_blue+=A
    
print(count_blue)
    

# Optimized solution
N,A,B=list(map(int,input().split()))

x=N//(A+B)

y=N%(A+B)

if y<A:
    print((A*x+y))
    
else:
    print((A*x+A))
# Original solution
N,A,B= input().split()
ans=0
for i in range(int(N)):
    if i%(int(A)+int(B))<int(A):
        ans+=1
print(ans)


# Optimized solution
N, A, B = [int(x) for x in input().strip().split()]
p = N // (A + B) * A
q = N % (A + B)
if q > A:
    q = A
print((p + q))
# Original solution
N, A, B = [int(x) for x in input().strip().split()]
p = N // (A + B) * A
q = N % (A + B)
if q > A:
    q = A
print((p + q))


# Optimized solution
"""
    Author: _YL_
"""
# b:blue, r:red
n, b, r = list(map(int, input().split()))

if b == 0:
    print("0")
elif r == 0:
    print(n)
else:
    remainder = n % (b+r)
    if remainder > b:
        remainder = b

    print((n//(b+r)*b+remainder))
# Original solution
N, A, B = list(map(int, input().split()))
result = 0
current = "b"

while(N > 0):
  if current == "b":
    if N - A > 0:
      result += A
      N = N - A
    else:
      result += N
      N = 0
    current = "r"
  else:
    if N - B > 0:
      N = N - B
    else:
      N = 0
    current = "b"
print(result)

# Optimized solution
N, A, B = list(map(int, input().split()))
result = 0

x = N // (A+B) 
result = A * x

N = N - ((A + B) * x)
if N < A:
  result += N
else:
  result += A
print(result)
# Original solution
N, A, B = list(map(int, input().split()))
lst = []
i = 0
while i < N:
    for j in range(A):
        lst.append("b")
        i += 1
    for k in range(B):
        lst.append("r")
        i += 1
# print("lst:", lst)
lst = lst[:N]
# print("lst:", lst)
print((lst.count('b')))

# Optimized solution
# coding: utf-8
N, A, B = list(map(int, input().split()))
# print("N:", N, "A:", A, "B:", B) 
if A == 0:
    print((0))
elif B == 0 or N <= A:
    print(N)
else:
    num = int(N / (A + B)) * A + min(A, N % (A + B))
    print(num)
# Original solution

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

x = n // (a+b)
y = n % (a+b)

if y <= a:
    print(((x*a) + y))
else:
    print(((x*a) + a))


# Optimized solution

n,a,b = list(map(int,input().split()))
num = 0
num = n // (a+b)

if n % (a+b) <= a:
    print(((num*a)+ (n % (a+b))))
else:
    print(((num*a)+a))
# Original solution
n,a,b=list(map(int,input().split()))
count=0

while n>0:
  for i in range(a):
    count+=1
    n-=1
    if n==0:
      break
  for i in range(b):
    n-=1
    if n==0:
      break

if a==0:
  print((0))
else:
  print(count)

# Optimized solution
n,a,b=list(map(int,input().split()))

ab=a+b
num=n//ab
n-=ab*num

if n>=a:
  ans=a
  
else:
  ans=n
  
print((ans+num*a))
# Original solution
a,b,c=list(map(int,input().split()))
n = a // (b+c)
m = a - (b+c)*n
res = n*b
for i in range(m):
  if i < b:
    res += 1
print(res)

# Optimized solution
a,b,c=list(map(int,input().split()))
n = a // (b+c)
m = a - (b+c)*n
res = n*b
if m < b:
  res += m
else:
  res += b
print(res)
# Original solution
N, A ,B =list(map(int,input().split()))
blue =0
while N >0:
    blue += min(A,N)
    N -= min(A,N)
    N = max(N-B,0)
print(blue)

# Optimized solution
N, A ,B =list(map(int,input().split()))

print((N//(A+B)*A+min(N%(A+B),A)))
# Original solution
N, A, B = list(map(int, input().split()))

ans = 0

while N > 0:
    red = min(N, A)
    ans += red
    N -= red
    blue = min(N, B)
    N -= blue
print(ans)


# Optimized solution
N, A, B = list(map(int, input().split()))

rep = N//(A+B)
ans = A*rep
diff = N - (A+B)*rep
ans += min(diff, A)
print(ans)
# Original solution
#Input
N,A,B= list(map(int, input().split()))

#Process
cnt = 0
Ans = 0
flag_AB = True 
while cnt < N:
    if(flag_AB):
        flag_AB = False
        if(cnt + A < N):
            Ans = Ans + A
        else:
            Ans = Ans + A - (cnt + A - N)
        cnt = cnt + A
    else:
        flag_AB = True
        cnt = cnt + B

#Output
print(Ans)

# Optimized solution
#Input
N,A,B= list(map(int, input().split()))

#Process
nokori = 0
na = int(N / (A + B))
if((A+B)*na + A > N):
    nokori = N % (A + B)
else:
    nokori = A
Ans = A * na + nokori

#Output
print(Ans)
# Original solution
n,a,b=list(map(int,input().split()))
k=[]
ans=0
count=(n//(a+b))
bb=[]
aa=[]
for j in range(a):
    k.append('b')
for t in range(b):
    k.append('r')
kk=k
for i in range(count):
    for y in range(len(k)):
        kk.append(k[y])
print((kk[:n].count('b')))

# Optimized solution
n,a,b=list(map(int,input().split()))
t=n//(a+b)
j=n%(a+b)
ans=0
q=t*a
if(j<=a):
    p=j
else:
    p=a
ans=p+q
print(ans)
# Original solution
n,a,b=list(map(int,input().split()))

c=n//(a+b)
d=n%(a+b)

ans=c*a+min(d,a)
print(ans)

# Optimized solution
n,a,b=list(map(int,input().split()))
c=a+b
ans=n//c*a
ans+=min(a,n%c)

print(ans)
# Original solution

n, a, b = list(map(int, input().split()))
l = []
while len(l) <= n:
    for _ in range(a):
    	l.append("b")
    for _ in range(b):
        l.append("r")

print((l[:n].count("b")))


# Optimized solution
n, a, b = list(map(int, input().split()))

l = a + b
set_cnt = n // l
rest = n % l
if rest >= a:
    ans = set_cnt * a + a
else:
    ans = set_cnt * a + rest

print(ans)
# Original solution
# A = [list(map(int, input().split())) for _ in range(3)]
# n = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
n, a, b = list(map(int, input().split()))
total = a+b
diff = n-((n//total)*total)
omake = n//total*a
if a <= diff:
    print((a+omake))
else:
    print((diff+omake))


# Optimized solution
# A = [list(map(int, input().split())) for _ in range(3)]
# n = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
n, a, b = list(map(int, input().split()))
total = a+b
diff = n % total
blue_in = n//total*a
if a <= diff:
    print((a+blue_in))
else:
    print((diff+blue_in))
# Original solution
a,b,c=list(map(int,input().split()))
d=0
e=0
ok=False

total=int(a/(b+c))
sa=a-(b+c)*total
if total==0:
    if a>=b:
        print(b)
    else:
        print(a)
else:
    if sa>=b:
        print((b+b*total))
    else:
        print((sa+b*total))

# Optimized solution
n,a,b=list(map(int,input().split()))
print(((n//(a+b))*a+max(0,min(a,(n-((n//(a+b))*(a+b)))))))
# Original solution
n, a, b = list(map(int, input().split()))
total = 0
out = 0
if a == 0:
    pass
else:
    while True:
        total += a
        out += a
        if total >= n:
            out -= (total - n)
            break
        total += b
        if total >= n:
            break
print(out)

# Optimized solution
n, a, b = list(map(int, input().split()))
q = n // (a + b)
mod = n % (a + b)
if mod > a:
    remain = a
else:
    remain = mod
    
print((q * a + remain))