Problem:
 Score : 200 points    Problem Statement Takahashi has many red balls and blue balls. Now, he will place them in a row.  Initially, there is no ball placed.  Takahashi, who is very patient, will do the following operation 10^{100} times:   Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.   How many blue balls will be there among the first N balls in the row of balls made this way?      Constraints  1 \leq N \leq 10^{18}  A, B \geq 0  0 < A + B \leq 10^{18}  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A  B       Output Print the number of blue balls that will be there among the first N balls in the row of balls.        Sample Input 1 8 3 4      Sample Output 1 4  Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb , among which there are four blue balls.       Sample Input 2 8 0 4      Sample Output 2 0  He placed only red balls from the beginning.       Sample Input 3 6 2 4      Sample Output 3 2  Among bbrrrr , there are two blue balls.

Solution (Python):
n, a, b = (int(i) for i in input().split())
q, mod = divmod(ｎ, a+b)
print(a * q + min(mod, a))

Solution (Python):
import math
N, A, B = map(int, input().split())
T = A+B
ans = (N//T)*A + min(N%T, A)
print(ans)

Solution (Python):
N, A, B = map(int,input().split())

q, mod = divmod(N, A + B)

if  A == 0 :
    print(0)

elif q < 1 and N <= A:
    print(N)
    
elif q < 1 and N > A:
    print(A)
    
elif q >= 1:
    if mod == 0 :
        print(q*A)
    elif mod <= A :
        print(q*A+mod)
    elif mod > A :
        print(q*A+A)

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

if n<=a:
    print(n)
    exit()

if n<=a+b:
    print(a)
    exit()

if a==0:
    print(0)
    exit()

if b==0:
    print(n)
    exit()

temp1=n//(a+b)

print(temp1*a+min(a,n%(a+b)))

Solution (Python):
n, a, b = map(int, input().split())
ans = divmod(n, a + b)
m = a if a < ans[1] else ans[1]
print(ans[0] * a + m)

Solution (Python):

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

if n <= a+b:
    if n >= a:
        print(a)
    elif n < a:
        print(n)
elif n > a+b:
    taba = n//(a+b)
    if n-taba*(a+b) >= a:
        print(taba*a+a)
    elif n-taba*(a+b) < a:
        print(taba*a+n-taba*(a+b))

Solution (Python):
N,A,B=input().split()
n=int(N)
a=int(A)
b=int(B)
m=int(n%(a+b))
l=int((n-m)/(a+b))
if m>a:
  y=a
else:
  y=m
x=a*l+y
x=int(x)
print(x)

Solution (Python):
n, b, r = map(int, input().split())

if b == 0:
    print(0)
elif r == 0:
    print(n)
else:
    k = n // (b + r)
    q = n % (b + r)
    print(b * k + min(q, b))

Solution (Python):
N,A,B = map(int,input().split())
if A == 0:
    print(A)
    exit()
n = N // (A + B)
nn = N % (A + B)
if n != 0 and nn <= A:
    print(int(A*n + nn))
elif n != 0 and nn > A:
    print(int(A*(n+1)))
elif n == 0 and N >= A:
    print(A)
elif n == 0 and N < A:
    print(N)

Solution (Python):
NAB = input().split()

N = int(NAB[0])
A = int(NAB[1])
B = int(NAB[2])

kaisuu = N // (A+B)
amari = N % (A+B)

if kaisuu >= 10**100:
  solution = A ** (10**100)
else:
  if amari <= A:
  	solution = A * kaisuu + amari
  else:
    solution = A * kaisuu + A

print(solution)

Solution (Python):
n, a, b = map(int, input().split())
ans = 0
ans += n // (a + b) * a      
ans += min(n % (a + b), a)   
print(ans)

Solution (Python):


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

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

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

print(res1 + res2)

Solution (Python):
N,A,B=(int(x) for x in input().split())

q = N // (A+B)
mod = N % (A+B)
if mod <= A:
    s = (q * A) + mod
    print(s)
else:
    s = (q * A) + A
    print(s)

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):

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

a = int(N/(A+B))
b = N%(A+B)

if N%(A+B) <= A:
    print(a*A + b)
else:
    print(a*A+A)

Solution (Python):
a,b,c = map(int,input().split())
d = 0
l = a // (b+c)
k = a % (b+c)
if b == 0:
    print('0')
    
elif b + c >= a:
    if b < a:
        print(b)
    elif b > a:
        print(a)
    
elif b + c < a:
    if a % (b + c) == 0:
        print(int(l))
    elif a % (b + c) != 0:
        if b > k:
            print(int(l*b + k))
        elif b < k:
            print(int(l*b + b))

Solution (Python):
N,a,b=(int(x) for x in input().split())

num_char = (int(N /(a+b)))
num_joyo = (N %(a+b))
result = 0

if num_joyo <= a:
    result = num_char*a + (num_joyo)
else:
    result = num_char*a + a
    
print(result)

Solution (Python):
import sys
input = sys.stdin.readline

N, A, B = list(map(int, input().split()))
ans = 0
abset = N // (A+B)

ans += A * abset

if N % (A+B) != 0:
    if A > N - (A+B)*abset:
        ans += N - (A+B)*abset
    else:
        ans += A

print(ans)

Solution (Python):
N, A, B = map(int, input().split())

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

if mod<A:
    print(roop*A+mod)
else:
    print(roop*A+A)

Solution (Python):
n,a,b=map(int,input().split())
g=a+b
m=(n//g)-1
v=n%g
if v<=a:
	print(a+m*a+v)
else:
	print(a+m*a+a)

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):
nums = list(map(int, input().split()))
n = nums[0]
a = nums[1]
b = nums[2]

if a == 0:
    print(0)
elif b == 0:
    print(n)
else:
   c = n // (a+b) * a
   mod = n % (a+b)
   if mod > a :
       mod = a
   print(c + mod)

Solution (Python):
n, a, b = map(int, input().split())
amari = n % (a+b)
if amari > a :
    amari = a
print((n // (a+b)) * a + amari )

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):
n, a, b = map(int, input().split())
pr = a+b
t = n//pr
k = n%pr
n =  a if k >a else k
print(t*a + n)

Solution (Python):
def count(b, total, N):
  r = N%total
  if r < b:
    return r
  else:
    return b

data = input()
N, b, r = [int(i) for i in data.split()]

total = b + r

ball = int(N/total) * b + count(b, total, N)
print(ball)

Solution (Python):
input_line = [int(i) for i in input().split()]
n = input_line[0]
a = input_line[1]
b = input_line[2]

x, y = divmod(n, a + b)
i, j = divmod(y, a + 1)

if i > 0:
	print(a * x + a)
else:
    print(a * x + j)

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

if a == 0:
  print(0)
  exit()
elif b == 0:
  print(n)
  exit()

t = a + b

print(a * (n //t) + min(n%t,a))

Solution (Python):
N, A, B = map(int, input().split())

C = N // (A + B)
D = N % (A + B)

R = C * A + min(A, D)
print(R)

Solution (Python):
import numpy as np
import math
s = input().split()
N = int(s[0])
A = int(s[1])
B = int(s[2])

x = int(N/(A+B))
if N-x*(A+B)>=A:
  print(x*A+A)
else:
  print(x*A+N-x*(A+B))

Solution (Python):

import math
def main():
    N,A,B = map(int,input().split())
    ans0 = N//(A+B)
    ans1 = A*ans0
    ans2 = (N-(A+B)*ans0)
    if ans2 <= 0:
        ans2 = 0
    if ans2 < A:
        ans1 += ans2
    elif ans2 >= A:
        ans1 += A

    print(ans1)

if __name__ == '__main__':
    main()

Solution (Python):
n,a,b=map(int,input().split())
c=a+b
if n<=c:
    if n<=a:
        ans=n
    else:
        ans=a
else:
    x=n//c
    y=x*a
    z=x*c
    t=n-z
    if t<=a:
        ans=y+t
    else:
        ans=y+a
print(ans)

Solution (Python):
N, A, B = 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)

Solution (Python):
n, a, b = map(int, input().split())
div, rest =divmod(n, (a + b))

ans = a * div
if rest >= a:
    ans += a
else:
    ans += rest
print(ans)

Solution (Python):
import math
N,A,B = map(int,input().split())
x = A+B
y = N-x*math.floor(N/x)
ans = 0
ans += A*(math.floor(N/x))
if y >= A:
  ans += A
else:
  ans += y
print(ans)

Solution (Python):
n,a,b=map(int, input().split())
c=int(n/(a+b))
if n-c*(a+b)>=a:
    ans=a*(c+1)
else:
    ans=c*a+n-c*(a+b)

print(ans)

Solution (Python):
N, A, B = map(int, input().split())

q, mod = divmod(N, A+B)


if A == 0:
    print(0)
else:
    if mod > A:
        print(q * A + A)
    else:
        print(q * A + mod)

Solution (Python):

n,a,b  = map(int, input().split())
if n%(a+b) <= a:
    print(a*(n//(a + b)) + n%(a+b))
else:
    print(a*(n//(a + b)) + a)

Solution (Python):
n,a,b=map(int,input().split())
ans=0
if a==0:
    ans=0
elif b==0:
    ans=n
else:
    ans=a*(int(n/(a+b)))
    n=n%(a+b)
    while True:
        if n==0:
            break
        if n-a<0:
            ans+=n
            break
        else:
            ans+=a
            break

print(ans)

Solution (Python):
N,A,B =map(int,input().split())
a = N//(A+B)
b = N - a*(A+B)
if b > A:
    print(A*a + A)
else:
    print(A*a + b)

Solution (Python):
N, A, B = map(int, input().split())
if A == 0:
  print(0)
  exit()
if B == 0:
  print(N)
  exit()
t = int(N / (A + B))
diff = N - t * (A + B)
if diff > A:
  print(A * t + A)
else:
  print(A * t + diff)

Solution (Python):
N,A,B=list(map(int,(input().split())))
ans=0
cntr=(N//(A+B))
ans+=cntr*A
if(N-cntr*(A+B)>=A):
    ans+=A
else:
    ans+=N-cntr*(A+B)
print(ans)

Solution (Python):
def main():
    N,A,B = map(int, input().split())
    if A == 0:
        print(0)
        return
    
    count=0

    sho1 = N // (A+B)
    amari1 = N % (A+B)
        
    sho2=amari1 // A
    amari2=amari1 % A
    
    if sho1 ==0:
        if sho2 == 0:
            count += amari2
        
        else:
            count += A
    else:
        count += sho1*A
        
        if sho2 == 0:
            count += amari2
        
        else:
            count += A
            

    print(count)
    
    
main()

Solution (Python):
n, b, r = map(int, input().split())

cnt_blk = n // (b+r)
res_b = cnt_blk*b
num = cnt_blk*(b+r) + b

if num > n:
  res_b += b - (num - n)
else:
  res_b += b
      
print(res_b)

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):
n=list(map(int,input().split()))
a=int(n[0]/(n[1]+n[2]))
b=int(n[0]%(n[1]+n[2]))
if b>n[1]:
    print(a*n[1]+n[1])
else:
    print(a*n[1]+b)

Solution (Python):
nums = [int(e) for e in input().split()]
n = nums[0]
a = nums[1]
b = nums[2]

sum1 = a + b
iter1 = n // sum1
amari = n % sum1
if amari >= a:
	print(iter1 * a + (a))
else:
  print(iter1 * a + (amari))

Solution (Python):
NAB = list(map(int,input().split()))
a = NAB[0] % (NAB[1] + NAB[2])
b = int(NAB[0] / (NAB[1] + NAB[2]))
if a <= NAB[1]:
	print(a + NAB[1] * b)
else:
  print(NAB[1] + NAB[1] * b)

Solution (Python):
n,b,r=map(int,input().split())
c=n//(b+r)
d=n%(b+r)
if d<=b:
    print(n-c*r)
else:
    print((c+1)*b)

Solution (Python):
import sys

n, a, b = map(int, sys.stdin.readline().split())

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

print(x*a + y)

Solution (Python):
N, A, B = map(int, input().split())

if N == 0:
  print(0)
  exit()

cnt = N // (A + B)
rem = N % (A + B)

ans = 0

if rem >= A:
  ans = A * (cnt + 1)
else:
  ans = A * cnt + rem

print(ans)

Solution (Python):
N,A,B=map(int,input().split())
if A==0:
    print(0)
elif A+B>=N:
    print(min(N,A))
else:
    print((N//(A+B))*A+min(N%(A+B),min(A,N-A-B)))

Solution (Python):
N, A, B = map(int, input().split())

if A == 0:
    print(0)
    exit()

x = int(N / (A+B))
y = N % (A+B)
z = 0
if y < A:
    z = y
else:
    z = A

blue = 0
if x < 10**100:
    blue = (x * A) + z
else:
    blue = 10*100*A + z
print(blue)

Solution (Python):


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

s = n % (a+b)
print(n // (a+b) * a + min(a,s))

Solution (Python):
N,A,B = (int(i) for i in input().split())

M = A+B

if A == 0:
  ans = 0
else:
  ans = ((N // M) * A)
  if N%M >= A:
    ans += A
  else:
    ans += N%M

print(ans)

Solution (Python):

n, a,b=map(int, input().split()) 
X = n//(a+b)
Y = n%(a+b)
if Y > a:
    print(X*a + a)
else:
    print(X*a + Y)

Solution (Python):
import sys

read = sys.stdin.readline
T = read()
a, b, c = map(int, T.split())

temp = a // (b+c)
answer = temp * b
temp2 = a % (b+c)

if temp2 >= b:
    answer += b
else:
    answer += temp2

print(answer)

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

t1 = n // (a+b)
t2 = n % (a+b)

if t2 <= a:
  ans = t1 * a + t2
else:
  ans = t1 * a + a

if n < a + b:
  if n < a:
    ans = n
  else:
    ans = a

if a == 0:
  ans = 0
elif b == 0:
  ans = n
print(ans)

Solution (Python):
N, A, B = [int(y) for y in input().split(' ')]
count = N // (A+B)
residue = N % (A+B)
 
if A == 0:
  print(0)
elif residue > A:
  print(count*A + A)
elif residue > 0:
  print(count*A + residue)
else:
  print(count*A)

Solution (Python):

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

import sys
AB = A+B
maxnum = pow(10,100)
if A == 0:
    print(0)
    sys.exit()
if N <= A:
    print(N)
    sys.exit()
waru,amari = divmod(N,AB)


if amari > A:
    amari = A
answer = waru * A + amari
print(answer)

Solution (Python):
def input_int_list():
    return [int(thing) for thing in input().split(" ")]
N,A,B=input_int_list()
r=N//(A+B)
if A==0:
    print(0)
    exit()
    
if N-r*(A+B)<=A:
    ans=N-B*r
else:
    ans=A*(r+1)

print(ans)

Solution (Python):
[N,A,B] = list(map(int,input().split()))
D = N//(A+B)
E = N%(A+B)
print(D*A+min(E,A))

Solution (Python):
n,a,b = map(int,input().split())
ans = 0

if a == 0:
  ans = 0
elif b == 0:
  ans = n
else:
  m = n // (a+b)
  r = n % (a+b)
  ans = a * m + min(a,r)

print(ans)

Solution (Python):
N,A,B = map(int,input().split())
count = 0
a = N//(A+B)

count += a*A

b = N%(A+B)
if b > A:
  count +=A
else:
  count +=b
print(count)

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):



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


C=A+B
D=N//C
E=N-D*C
z=0

z+=A*D

if E>=A:
    z+=A
else:
    z+=E

print(z)

Solution (Python):
n, blue, red = list(map(int, input().split()))

if blue == 0:
    print(0)
    exit()

if n <= blue:
    print(n)
    exit()

if n <= blue + red:
    print(blue)
    exit()

q = n // (blue + red)
r = n % (blue + red)

cnt = q * blue

while True:
    if r >= blue:
        cnt += blue
        r -= blue
        if r <= red:
            break
        elif r > red:
            r -= red
    else:
        cnt += r
        break

print(cnt)

Solution (Python):
import math

N,A,B=map(int,input().split())
total=(10 ** 100) + 1

firstCnt=math.floor(N/(A+B))

for i in range(firstCnt,total):
  if N <= i*A + i*B :
    if N >= i*A + (i-1)*B :
      ans=i*A
      break
    else :
      ans=i*A - (i*A+(i-1)*B - N)
      break
print(ans)

Solution (Python):
inputarray = input().split(' ')
N = int(inputarray[0])
A = int(inputarray[1])
B = int(inputarray[2])
blue = 'b'
red = 'r'
amari = N % (A+B)
if A >= amari: 
    countnum = N // (A+B) * A +amari
else:
    countnum = N // (A+B) * A +A
print(countnum)

Solution (Python):
N,A,B = (int(x) for x in input().split())
S =  N % (A+B) - A
Acount = N % (A+B)
Ansn = int(N / (A + B)) * A
if S <= 0:
    print(Ansn + Acount)
else:
    print(Ansn + A)

Solution (Python):
n, a, b = 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)

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

k = n//(a+b)
p = n%(a+b)

print(k*a + min(p,a))

Solution (Python):
a,b,c = list(map(int,input().split()))

s = b + c

counter = a//s
ans = b*counter
if a - (s * counter) <= b:
  ans += a - (s * counter)
else:
  ans += b

print(ans)

Solution (Python):
s = input()
n, a, b = s.split(' ')
n = int(n)
a = int(a)
b = int(b)

na = n // (a+b) * a
if n % (a+b) >= a:
  na += a
else:
  na += (n % (a + b))
  
print(na)

Solution (Python):
n, a, b = list(map(int, input().split()))
c, d = divmod(n, (a+b))
if d <= a:
    print(c*a+d)
else:
    print(c*a+a)

Solution (Python):

import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N,A,B = LMIIS()
    one = A+B
    
    if N%one <= A:
        remain = N%one
    else:
        remain = A
    print(N//one*A+remain)


if __name__ == '__main__':
    main()

Solution (Python):
N,A,B = map(int, input().split())
b = 0
ans = 0

if A == 0:
  ans = 0
elif N < A:
  ans = N
elif N < A+B:
  ans = A
else:
  x = N // (A+B)
  y = N % (A+B)
  ans = A * x + min(y, A)

print(ans)

Solution (Python):
N,A,B=list(map(lambda i:int(i),input().split()))

answer =0

if A==0:
    answer = 0
elif B==0:
    answer = N
else:
    tail=0
    if N%(A+B) > A:
        tail = A
    else:
        tail = N%(A+B)
    answer = A * (N//(A+B)) + tail

print(answer)

Solution (Python):
N, A, B = map(int, input().split())

AB = A+B
C = N // AB
n = N - AB * C

if n > A:
    print(C * A + A)
else:
    print(C * A + A - (A - n))

Solution (Python):
import math

N, A, B = map(int, input().split())
print(A * math.floor(N / (A + B)) + min(A, N % (A + B)))

Solution (Python):
N, A, B = map(int,input().split())
q = N // (A + B)
r = N % (A + B)
if r <= A:
    print(q * A + r)
else:
    print((q + 1) * A)

Solution (Python):
N,A,B = map(int, input().split())
L = []
b = 0
ans = 0

if A == 0:
  ans = 0
elif N < A:
  ans = N
elif N < A+B:
  ans = A
else:
  x = N // (A+B)
  y = N % (A+B)
  ans = A * x + min(y, A)

print(ans)

Solution (Python):
n, a, b = map(int, input().split())
cnt = 0
ans = 0
l = (a+b)
if n//l <= 10**100:
    ans += a * (n//l)
    cnt += (n//l)*l
    if n - cnt >= a:
        ans += a
    else:
        ans += max(n - cnt, 0)
else:
    ans += a * 10**100
    cnt += 10**100

print(ans)

Solution (Python):


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


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

if (mod >= A):  
    ans = (q * A) + A
    print(ans)

elif (mod < A):
    ans = (q*A) + mod
    print(ans)

Solution (Python):
import math
n, a, b =map(int,input().split())
x=a+b

quotient=math.floor(n/x)

rmd=n%x
if rmd==0:
  blue=quotient*a
  print(blue)
elif rmd<=a:
  blue=quotient*a+rmd
  print(blue)
else:
  blue=quotient*a+a
  print(blue)

Solution (Python):
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)

Solution (Python):
n,a,b = map(int,input().split())
s = a+b
c = n % s
d = n // s

if c <= a:
  print( a*d + c )

else:
  print( a*d + a )

Solution (Python):
N,B,R=map(int,input().split())
if B==0:
  print(0)
  exit()
ans=B*(N//(R+B))
if N%(R+B)>=B:
  print(ans+B)
else:
  print(ans+N%(R+B))

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

q = int(n/(a+b))
r = n - (a+b)*(q)
ans = q*a
ans += min([a,r])
print(ans)

Solution (Python):
n, a, b = [int(x) for x in input().split()]

if a == 0 and b == 0:
    print("0")
elif a >= n:
    print(n)
else:
    x = n // (a + b)
    if x == 0:
        print(a)
    else:
        if (n - ((a + b) * x)) >= a:
            print(a * x + a)
        else:
            print((a * x + (n - (a + b) * x)))

Solution (Python):
import math
n,a,b = map(int,input().split())
if a==0:print(0)
else:
    r=n//(a+b)
    extra = n-(r*(a+b))
    print(r*a+min(extra,a))

Solution (Python):
N, A, B = map(int, input().split())

division = N // (A + B)
count = division * A

count += N - division * (A + B) if A > N - division * (A + B) else A
print(count)

Solution (Python):
lst = [int(i) for i in input().split()]
ball = lst[0]
blue = lst[1]
red = lst[2]

red_blue = int(ball / (red + blue))
shokichi = red_blue * blue
amari = ball - (red_blue * (red + blue))

if amari < blue:
    nokori = amari
elif amari > blue:
    nokori = blue
else:
    nokori = 0

if blue == 0:
    print(0)
else:
    print(shokichi + nokori)

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

c=a+b
if a==0:
    print(0)
if c!=0 and a!=0:
    d=n//c
    num=a*d
    if n%c<=a:
        print(num+n%c)
    elif n%c>a:
        print(num+a)

Solution (Python):
N, A, B = map(int, input().split())

X = (N // (A + B)) * A
Y =  N % (A + B)

if Y < A:
    Z = Y
else:
    Z = A

print(X + Z)

Solution (Python):
import math

N, A, B = map(int, input().split())
tmp = 10**100
a = A * (N //(A+B))
b = (N %(A+B))
if b > A:
    print(a + A)
else: 
    print(a + b)

Solution (Python):
N, A, B = map(int, input().split())

X = N//(A+B)
Y = N%(A+B)

if A == 0:
    print(0)
else:
    if Y <= A:
        print(A * X + Y)
    else:
        print(A * X + A)

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):
import math
N, a, b = map(int, input().split())

all = a + b


if a == 0:
    print(0)
    exit(0)

if N <= a:
    print(N)
    exit(0)


c = math.floor(N / all)
d = N % all

roundCnt = a * c
amariCnt = 0

if d != 0:
    if d <= a :
        amariCnt = d
    else:
        amariCnt = a

print(roundCnt + amariCnt)

Solution (Python):
n,a,b = list(map(int,input().split()))
if(a != 0):
    kurikaeshi = n // (a + b)
    mod = n % (a + b)
    ans = a*kurikaeshi
    if(mod - a > 0):
        ans += a
    else:
        ans += mod
if(a == 0):
    ans = 0
print(ans)

Solution (Python):
N,B,R = map(int,input().split())
k = N % (B + R)
k2 = int(N / (B + R))



if k <= B:
	print(k2*(B) + k)
else:
	print(k2*(B) + B)

Solution (Python):
N,A,B = [int(i) for i in input().split(" ")]


def check(N,A,B):
    if A == 0:
        return 0
    r  = N//(A+B)
    x = N-r*(A+B)
    if x > A:
        return r*A+A
    else:
        return r*A+x
print(check(N,A,B))

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):
import math
num, blue, red = map(int, input().split())

line = math.floor(num / (blue + red))
amari = num % (blue + red)

b1 = line * blue


if blue > amari:
    print(b1 + amari)
else:
    print(b1 + blue)

Solution (Python):
import math
n,a,b = map(int,input().split())

c = math.floor(n/(a+b))
ans1 = c*a

if n - (a+b)*c <= a:
    ans2 = n - (a+b)*c
else:
    ans2 = a
print(ans1 + ans2)

Solution (Python):
N, A, B = map(int, input().split())
quo = (N // (A+B)) * A
rem = N % (A+B) if N % (A+B) <= A else A
print(quo + rem)

Solution (Python):


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

x = n // (b + r)

if n % (b + r) > b:
    print(x * b + b)
   
else:
    print((x * b) + (n % (b + r)))

Solution (Python):
import sys
n, a, b = map(int, input().split())
if a == 0 or n == 0:
    print(0)
    sys.exit()
j = n //(a + b)

if n - (a + b) * j >= a:
    print(a * j + a)
    sys.exit()
else:
    print(a * j + n- (a + b)*j )
    sys.exit()

Solution (Python):
N,A,B = map(int,input().split())
cnt = N % (A+B)
if cnt == 0:
    print(N // (A+B) * A)
    exit()
else:
    if cnt - A >= 0:
        print(N // (A+B) * A + A)
        exit()
    else:
        print(N // (A+B) * A + cnt)
        exit()

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

ans = 0
ans += n // (a + b) * a
rem = n % (a + b)
if a == 0:
    pass
elif rem > a:
    ans += a
elif rem <= a:
    ans += rem
print(ans)

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

C = N // (A + B) * A
D = N % (A + B)

if 0 <= D and D <= A:
    print(C + D)
else:
    print(C + A)

Solution (Python):
n, a, b = (int(x) for x in input().split())

syou = n // (a + b)
sa = n % (a + b)

if sa > a:
  ans = syou * a + a
else:
  ans = syou * a + sa
print(ans)

Solution (Python):
N, A, B = map(int,input().split())

ans = A * (N//(A+B))

if (N%(A+B)) > 0:
  ans = ans + min((N%(A+B)),A)

print(ans)

Solution (Python):

n,a,b = map(int,input().split())
ans = 0
c = n % (a + b)

if a == 0 and b == 0:
    print(0)
else:
    ans = int(n / (a + b)) * a
    if 0 <= c <= a:
        print(ans + c)
    elif a <= c <= a + b:
        print(ans + a)
    else:
        print("What??")

Solution (Python):
K = input().split(" ")
N = int(K[0])
A = int(K[1])
B = int(K[2])
if A == 0:
    print(0)
else:
    M = N%(A+B)
    L = N//(A+B)
    if M <= A:
        K = L*A+M
    else:
        K = L*A+A
    print(K)

Solution (Python):
N,A,B=map(int,input().split())
ans=(N//(A+B))*A
if N%(A+B)>=A:
	ans+=A
else:
	ans+=N%(A+B)
print(ans)

Solution (Python):
N,A,B = map(int,input().split())

ans = (N//(A+B))*A
tmp = N - (N//(A+B))*(A+B)
if(tmp <= A): ans += tmp
else: ans += A
print(ans)

Solution (Python):
N,A,B=map(int,input().split())
M=N
if A==0:
    print(0)
    exit()
if A+B>=N:
    print(min(A,N))
    exit()
cnt=N//(A+B)
ans=cnt*A
N=N-cnt*(A+B)
if N<=A+B and N>A:
    ans+=A
    print(ans)
    exit()
elif N<=A:
    ans+=M-cnt*(A+B)
    print(ans)

Solution (Python):
n,a,b=map(int,input().split())
div=n//(a+b)
re=n%(a+b)
ans=0
if a==0:
    print(0)
    exit()
if a > re:
    ans=re
else:
    ans=a
print(div*a + ans)

Solution (Python):
N, A, B = [int(i) for i in input().strip().split()]
q, r = divmod(N, A+B)
if r <= A:
  print(A*q + r)
else:
  print(A*q + A)

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

l=a+b
sub=int(n//l)
ans=sub*a
zan=n-sub*l
ans+=min(a,zan)
print(ans)

Solution (Python):
number = input().split(" ")
N = int(number[0])
B = int(number[1])
R = int(number[2])

a = int(B+R)
b = int(N/a)
c = int(N%a)

if b <= 0:
    if R ==0:
        print(N)
    else:
        if B > N:
            print(N)
        else:
            print(B)
else:
    if R == 0:
        print(N)
    else:
        if B == 0:
            print(0)
        else:
            if c > B:
                print((b*B)+B)
            else:
                print((b*B)+c)

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

count = N // (A + B)
amari = N%(A+B)
sum_blue = A * count + min(A, amari)

print(sum_blue)

Solution (Python):
N, A, B = map(int, input().split())
all_ball_cnt = N // (A + B)
remainder = N % (A + B)
bule_remainder = remainder if remainder < A else A
ans = all_ball_cnt * A + bule_remainder
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
r = int(n / (a + b))
res = n % (a + b)

if r + 1 < 10 ** 18:
    x = res if res <= a else a
    print((a * r) + x)
else:
    print(a*r)

Solution (Python):
NAB = list(map(int, input().split()))
N = NAB[0]
A = NAB[1]
B = NAB[2]
ans = ( N//(A+B)) * A

if N%(A+B) <= A:
  ans += N%(A+B)
else:
  ans += A

print(ans)

Solution (Python):
N,A,B=map(int,input().split())
import math
sets = math.floor(N/(A+B))
res = A * sets
res += min(N - (A+B)*sets, A)
print(res)

Solution (Python):
import math

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

result = 0

a = math.floor(N / (A + B))
r = N % (A + B)

if r > A:
    ad = A
else:
    ad = r

result = A * a + ad
print(result)

Solution (Python):
N,A,B=map(int,input().split())
ctpossible=A*(N//(A+B))
if N%(A+B)<=A:
    adding=N%(A+B)
else:
    adding=A
print(ctpossible+adding)

Solution (Python):

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

num = N // (A+B) * A
amari = N % (A+B)
num += min(amari, A)

print(num)

Solution (Python):

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


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


print(Ans)

Solution (Python):
import sys

s = sys.stdin.readline().split()

n, a, b = map(int, s)
res = (n // (a+b)) * a + min(a, n%(a+b))
print(res)

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

q = n // (a + b)
m = n % (a + b)

if m <= a:
    print(q * a + m)
else:
    print(q * a + a)

Solution (Python):
N,A,B = map(int, input().split())


ans1 = (N//(A+B))*A
ans2 = (N%(A+B))
if ans2 > A:
    ans2 = A

ans = ans1 + ans2

print(ans)

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

q,mod=divmod(n,a+b)
mod=min(mod,a)
print(a*q + mod)

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):
import math

n,a,b=(int(x) for x in input().split())

sum = a+b
n_num = math.floor(n/sum)
n_amari = n%sum

result = 0

if a != 0:
    result = a*n_num
    if n_amari != 0 and n_amari < a:
        result += n_amari
    elif n_amari != 0 and n_amari > a:
        result += a
print(result)

Solution (Python):
n, a, b = map(int, input().split())
if n <= (a + b): print(min(n, a))
elif (n % (a + b)) <= a:
  print(a * (n // (a + b)) + (n % (a + b)))
else: print(a * (n // (a + b)) + a)

Solution (Python):
def resolve():
    n, a, b = map(int, input().split())
    sum = a + b
    d = n // sum
    mod = n % sum
    if mod > a:
        c = (a * d) + a
    else:
        c = (a * d) + mod
    print(c)

if __name__ == '__main__':
    resolve()

Solution (Python):
N, A, B = map(int, input().split(' '))


def count_num_of_blue():
    global N, A, B

    total = 0
    division = int(N / (A+B))
    remainder = int(N % (A+B))
    if division > 0:
        total += A * division

    if remainder < A:
        total += remainder
    else:
        total += A

    print(total)


count_num_of_blue()

Solution (Python):
n, a, b = map(int, input().split())
d = n//(a+b)
e = 0
if n%(a+b) <= a:
  e += n%(a+b)
else:
  e += a
print(d*a+e)

Solution (Python):
a=list(map(int,input().split()))
N = a[0]
A = a[1]
B = a[2]

ans = A*(N//(A+B))
amari = N%(A+B)
if amari <= A:
    ans += amari
else:
    ans += A

print(ans)

Solution (Python):
n,a,b = map(int,input().split(' '))

block = a + b

if a == 0:
    print(0)
    exit(0)

number = n // block

remaining = n - number*block

print(number*a + min(a, remaining))

Solution (Python):
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

Solution (Python):



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

m = n % (a + b)

if (m <= a):
    v = m
else:
    v = a

print(int(n / (a + b)) * a + v)

Solution (Python):
N, A, B = map(int, input().split())

ans = 0
if A == 0:
    print(ans)
    exit()

ans +=  N // (A + B) * A
ans += min(N % (A + B), A)

print(ans)

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

Solution (Python):
import math

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

    print((n//(a+b))*a+min(n%(a+b),a))


if __name__ == '__main__':
    main()

Solution (Python):
N,A,B = map(int,input().split())
RepNum = int(N/(A+B))
Atotal = A * RepNum
amari = N-RepNum*(A+B)
if amari > 0:
  if amari >= A:
    amari = A
print([0,Atotal + amari][A!=0])

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

m = n//(a+b)
s = n%(a+b)
if n < a+b:
    if n <= a:
        print(n)
    else:
        print(a)
else:
    if s <= a:
        print(a*m+s)
    else:
        print(a*m+a)

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

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

m=c*a
if d>a:
    m+=a
else:
    m+=d

print(m)

Solution (Python):
n,a,b=map(int,input().split())
s=0
s+=a*(n//(a+b))
s+=a if (n%(a+b)>a) else n%(a+b)
print(s)

Solution (Python):
n,a,b = map(int, input().split())
ans =(a*int(n//(a+b))) + (int(n%(a+b)) if a>=n%(a+b) else a)
print(ans)

Solution (Python):
n, a, b = map(int, input().split())
k = n // (a + b)
m = n % (a + b)
print(k * a + min(a, m))

Solution (Python):


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

q, mod = divmod(N, A+B)
X=q*A

if mod<A:
    Y=mod
else:
    Y=A

print(X+Y)

Solution (Python):
N, A, B = map(int, input().split())
n = N//(A+B)
d = N%(A+B)
ans = n*A
if d>=A:
    ans += A
else:
    ans += d
print(ans)