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.



Sample input:
8 3 4


Sample output:
4

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
# 全体の中の青の割合
out = N // (A + B) * A
# 8を7で割った余り　Aより大きければ青は全部置ける
rem = min(N % (A + B), A)
print(out + rem)

Submission status: Accepted

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

sum=0
L=n//(a+b)
M=n%(a+b)

if a<=M:
  print(a*L+a)
else:
  print(a*L+M)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=[int(a) for a in input().split()]

div,mod=divmod(N,A+B)
ans=div*A + min(A,mod)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
k = int(n/(a+b))
l = n%(a+b)
count = 0
count += k*a
if l>a:
    count +=a
else:
    count +=l

print(count)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
K=N//(A+B)
print(K*A+min(A,N%(A+B)))

Submission status: Accepted

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

x = n // (a + b) * a
k = n % (a + b)
if k <= a:
    print(x + k)
else:
    print(x + a)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
div = N //(A+B)
mod = N% (A+B)
print(div*A+min(mod,A))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, A, B = map(int, input().split())

    ans = A * (N // (A + B))
    m = N % (A + B)
    if m > A:
        ans += A
    else:
        ans += m
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

t = N%(A+B)

if t > A:
    print((N//(A+B)+1)*A)
else:
    print(N//(A+B)*A+t)

Submission status: Accepted

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

turn = n //(a+b)
rest = n%(a+b)

if turn == 0:
  if n >= a:
    print(a)
  else:
    print(n)
else:
  if rest >= a:
    print((turn + 1) * a)
  else:
    print(turn * a + rest)

Submission status: Accepted

Solution code:
N, num_of_blue, num_of_red = map(int, input().split())

num_of_repetition = (N // (num_of_blue + num_of_red))
remainder_s = N % (num_of_blue + num_of_red)

count_b = num_of_blue * num_of_repetition + min(num_of_blue, remainder_s)

print(count_b)

Submission status: Accepted

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

Submission status: Accepted

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

if B==0:
    print(N)
elif A==0:
    print(0)
else:
    n = (N//(A+B))
    ans = n * A
    N -= n*(A+B)
    if N >= A:
        ans+=A
    else:
        ans+=N
    print(ans)

Submission status: Accepted

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

print(N//(A+B)*A+min(A,N%(A+B)))

Submission status: Accepted

Solution code:
combined = input().split(" ")
n = int(combined[0])
a = int(combined[1])
b = int(combined[2])

if n % (a + b) < a:
    print((int(n / (a + b)) * a) + (n % (a + b)))
else:
    print((int(n / (a + b)) * a) + a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    per, remain = divmod(N, A + B)
    print(per * A + min(A, remain))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if A == 0:
        print(0)
        return

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


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B = list(map(int, input().split()))
print(N//(A+B)*A + min(N%(A+B), A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
div, mod = divmod(n, (a+b))
if mod >= a:
    print(div*a+a)
else:
    print(div*a+mod)

Submission status: Accepted

Solution code:
def main():
    N, A, B = map(int, input().split())
    AB = A + B

    q, r = divmod(N, AB)
    print(A * q + min(r, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
print(min((N//(A+B))*A + N - (N//(A+B))*(A+B), (N//(A+B))*A + A))

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

N, A, B = mi()

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

blue = div * A

if A >= mod:
    blue += mod
else:
    blue += A

print(blue)

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
if n <= a:
    print(n)
elif a < n and n <= a+b:
    print(a)
else:
    s,v = divmod(n,a+b)
    if v <= a:
        print(s*a+v)
    else:
        print(s*a+a)

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
a = N//(A+B)
b = N%(A+B)
if b >= A:
    b = A
print(a*A+b)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(a*l+y if y<a else a*l+a)

Submission status: Accepted

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

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

print(X + Y if Y <= A else X + A)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

#NがA+Bかどうか
#NがA+B以上ならA+Bをわったあまりを判定

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

Submission status: Accepted

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

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

Submission status: Accepted

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

SET = N // (A + B)
BAL = N % (A + B)

if BAL >= A:
    print(SET * A + A)
else:
    print(SET * A + BAL)

Submission status: Accepted

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

c = a+b
m = n//c
l = n%c
ans = 0
if l<a:
  ans = ans + l
elif l>a:
  ans = ans + a
  
print(ans + (a*m))

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
C = A + B
D = N // C
E = N % C
if N <= A:
    print(N)
elif N <= C:
    print(A)
else:
    if E <= A:
        print(A*D + E)
    else:
        print(A*D + A)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

loop = n//(b+r)
extra = n%(b+r)

if extra > b:
    print(b*(loop+1))
else:
    print(b*loop +extra)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())
count = int(n/(a+b))
mod = n%(a+b)

ans = count * a
if mod > a:
  ans += a
else:
  ans += mod
print(ans)

Submission status: Accepted

Solution code:
n,a,b = map(int, input(). split())
s = a + b
k = n//s
x = min(n-k*s, a)
print(a*k+x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int,input().split())
AB = A + B

X = N // AB
C1 = A * X

Y = N % AB
if A >= Y:
    C2 = Y
else:
    C2 = A

print( C1 + C2 )

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
apple = N % (A + B)
print(A * (N // (A + B)) + min(apple, A))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
q,r=divmod(n,a+b)
print(q*a+min(a,r))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,A,B=pin()
    C=A+B
    n=N%C
    m=N//C
    ans=A*m
    if n<=A:
        ans+=n
    else:
        ans+=A
    print(ans)
#%%submit!
resolve()

Submission status: Accepted

Solution 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 heapq import heapify, heappop, heappush
 
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

N, A, B = MAP()

a = N % (A + B)
b = N // (A + B)
c = 0

if 0 <= a <= A:
    c = a
else:
    c = A

print(b * A + c)

Submission status: Accepted

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

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

# print(n//(a+b))
# print(min(a, n%(a+b)))
# print("--------")

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A == 0:
  ans = 0
else:
  c = N//(A+B)
  d = N - c*(A+B)
  if d >= A:
    ans = (c+1)*A
  else:
    ans = c*A + d
    
print(ans)

Submission status: Accepted

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

ans = n // (a+b) * a
ans += n % (a + b) if n % (a + b) <= a else a

print(ans)

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, a, b = map(int, input().split())
ans = 0
tmp = 0
ans = (n//(a+b))*a
tmp = n % (a+b)
ans += min(tmp, a)
print(ans)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
n = N//(A+B)
m = N%(A+B)
k = min(m,A)
print(n*A+k)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    q, r = divmod(n, a + b)
    if r < a:
        res = q * a + r
    else:
        res = q * a + a

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
  n, a, b = map(int, input().split())
  ans = (n // (a + b)) * a
  ans += min(a, n % (a+b))
  print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

T = A+B

ans = (N//T)*A

if N%T >= A:
  ans += A
  print(ans)
else:
  ans += N%T
  print(ans)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
K = N%(A+B)
L = N//(A+B)*A
if A == 0:
    print(0)
elif N<A:
    print(N)
elif A==N:
    print(A)
elif N<=(A+B):
    print(A)
else:
    if N%(A+B) > A:
        print(L+A)
    else:
        print(L+K)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
d,m = divmod(N,A+B)
ans = d*A + min(m,A)
print(ans)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
count = 0

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

if n % (a + b) <= a:
    count += n % (a + b)
else:
    count += a

print(count)

Submission status: Accepted

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

x = n // (a+b)
ans = x * a

x = n % (a+b)
if x < a:
  ans += x
else:
  ans += a

print(ans)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
x=(n//(a+b))*a
y=min(a,n%(a+b))
print(x+y)

Submission status: Accepted

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

if n <= a:
    print(n)
elif n<=a+b:
    print(a)
else:
    count = a*(n//(a+b))
    amari = n%(a+b)
    if amari <= a:
         print(count+ amari)
    else:
        print(count+a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def numberofblues(N,A,B): 
    
    if A==0:
        return 0
    elif N<=A:
         return N
    else:
        k=(N-A)//(A+B)
        l=N-A-k*(A+B)
        if l<=B:
            return A+k*A
        else:
            return A+k*A+l-B
   
N,A,B=map(int, input().split())
print(numberofblues(N,A,B))

Submission status: Accepted

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

ans = n //(blue + red) * blue

plus = n % (blue + red)
ans += min(plus, blue)

print(ans)

Submission status: Accepted

Solution code:
import math
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
z = 0
z = math.floor(n / (a+b)) * a
amari = math.floor(n % (a+b))
if amari == 0:
  pass
elif amari <= a:
  z += amari
else:
  z += a
print(z)

Submission status: Accepted

Solution code:
n,a,b = list(map(int, input().split()))
q,r = divmod(n, a+b)
print(q*a + min(a,r))

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
out=N//(A+B) * A
ama=min(N % (A+B),A)
print(out+ama)

Submission status: Accepted

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

a = N // (A+B)
b = N % (A+B)
print(A*a + A if b - A>=0 else A*a + b)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
t = n//(a+b)
u = n%(a+b)

if u > a:
    print(t*a+a)
else:
    print(t*a+u)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(_) for _ in input().split()]
print((n // (a + b)) * a + min(n%(a+b), a))

Submission status: Accepted

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

Submission status: Accepted

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

rep = n // (a + b)
rem = n % (a + b)

ans = rep * a

if rem < a:
    ans += rem
else:
    ans += a
print(ans)

Submission status: Accepted

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

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

if d <= a:
    e = d
else:
    e = a

print(a*c + e)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,A,B = LI()
    ans = 0
    n_ab = int(N/(A+B))
    amari = N-n_ab*(A+B)
    ans = n_ab*A+A if amari >= A else n_ab*A+amari
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, a, b = tin()
	#s = input()
	ra = n // (a+b)
	blue_num = ra * a
	amari = n % (a+b)
	blue_num += min(amari, a)
	
	print(blue_num)
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
c=n//(a+b)
d=n%(a+b)
print(a*c+min(d, a))

Submission status: Accepted

Solution code:
import sys

def ep(*params):
    print(*params,file=sys.stderr)

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

times = N // (A+B)
left = N % (A+B)
ba = times * A
if left >= A:
    ba += A
else:
    ba += left
print(ba)
sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

tot = a+b
ans = (n//tot)*a
c = n % tot
if c >= a:
    ans += a
else:
    ans += c

print(ans)

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
tama = int(n/(a+b))*(a+b)
blue = int(n/(a+b))*a
nokori = n - tama
if nokori<a:
    blue += nokori
else:
    blue += a


print(blue)

Submission status: Accepted

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

x = n // (a+b)
if n%(a+b) <= a:
    print(x*a + n%(a+b))
elif n%(a+b) > a:
    print((x+1) * a)
else:
    print(x*a)

Submission status: Accepted

Solution code:
# coding: utf-8
n, a, b = map(int, input().split())
ans = a * (n // (a + b))
buf = n % (a + b)
if buf < a:
    ans = ans + buf
else:
    ans = ans + a
print(ans)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
r = N//(A+B)*A+min(A, N-N//(A+B)*(A+B))
print(r)

Submission status: Accepted

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

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

if a > A:
    a = A
    
print(cnt*A + a)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
ans = N//(A+B)*A
rem = N%(A+B)
ans +=min(rem,A)
print(ans)

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
x = 0
y = 0
if(n%(a+b) == 0):
  x=int(n/(a+b))*a
else:
  y = n%(a+b)
  x = int(n/(a+b))*a + min(a,y)
print(x)

Submission status: Accepted

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

s=a+b

shou=int(n//s)

amari=int(n%s)

if n<s:
    if a<n:
        print(a)
    else :
        print(n)
else :
    if amari<a:
        print(a*shou+amari)
    else :
        print(a*shou+a)

Submission status: Accepted

Solution code:
import sys
 
readline = sys.stdin.buffer.readline
 
N,A,B = map(int, readline().split())
 
div,mod =divmod(N, A+B)
 
if div < 1:
  if N > A:
    print(A)
  else:
    print(N)
else:
  if mod > A:
    print(A*div + A)
  else:
    print(A*div + mod)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
print(A*(N//(A+B)) + min(A, N - (A+B) * (N//(A+B))))

Submission status: Accepted

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

c1 = (N // (A + B))

c2 = (N % (A + B))
c3 = A if c2 > A else c2

print(c1*A + c3)

Submission status: Accepted

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

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

print(a * A + min(b, A))

Submission status: Accepted

Solution code:
import sys

def ISI(): return map(int, sys.stdin.readline().rstrip().split())

n, a, b = ISI()
ans = n//(a+b)*a
if a!=0:
	if n%(a+b)>a:ans+=a
	else:ans+=n%(a+b)
print(ans)

Submission status: Accepted

Solution 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)

Submission status: Accepted

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

Submission status: Accepted

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

m = N%(A+B)

print((N//(A+B))*A + (A if m > A else m))

Submission status: Accepted

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n, a, b = invr()

p = int(n/(a+b))
r = n % (a+b)

res = a*p
res += min(r, a)
print(res)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc158/tasks/abc158_b

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

cycle=a+b
cycle_cnt=n//cycle
rest=n-cycle*cycle_cnt
if rest<=a:
    print(cycle_cnt*a+rest)
else:
    print(cycle_cnt*a+a)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
S = A + B
count = N//S * A
if N%S >= A:
    count += A
else:
    count += N%S

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    quotient = N // (A+B)
    remainder = N % (A+B)
    return quotient * A + min(remainder, A)


def main():
    N, A, B = map(int, sys.stdin.readline().split())
    print(solve(N, A, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N,A,B = map(int, input().split())
    x = A+B
    q,r = divmod(N,x)
    ans = A*q + min(r,A)
    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
x, y = divmod(N, A + B)
print(A * x + y if y <= A else A * (x + 1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

mod = n%(a+b)

if mod < a:
    count_b += mod
else:
    count_b += a

print(count_b)

Submission status: Accepted

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

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

print(x*a + min(y,a))

Submission status: Accepted

Solution code:
def main():
    n, a, b = list(map(int, input().split()))
    loop = n // (a+b)
    mod = n % (a+b)
    print(a*loop + min(a,mod))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
d, mod = divmod(N, A+B)
print(d*A + min(mod, A))

Submission status: Accepted

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

if A == 0:
  print(0)
else:
  out = N % (A+B)
  if out <= A:
    print(A*int(N/(A+B))+out)
  else:
    print(A*int(N/(A+B))+A)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = N//(A+B) * A
ra = N % (A+B)
if ra <= A:
    ans += ra
elif ra > A:
    ans += A

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
cnt = 0
n = N // (A+B)
m = N % (A+B)

if m >= A:
    cnt += A
else:
    cnt += m
cnt += (n*A)
print(cnt)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A == 0 or (A+B == 0):
    print(0)
elif B == 0:
    print(N)
else:
    s = A*(N // (A+B))
    rem  = N % (A+B)
    if rem > A:
        rem = A
    print(s+rem)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
X=N//(A+B)*A
if A==0:
    print(0)
else :
    print(X+N-X*(A+B)//A if N-X*(A+B)//A<=A else X+A)

Submission status: Accepted

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

q = (N // (A + B))
if (N % (A + B)) <= A:
    r = (N % (A + B))
else:
    r = A
res = q * A + r

print(res)

Submission status: Accepted

Solution code:
def count_balls(n, b, a):
	if b == 0:
		return 0
	
	num = n // (a + b)
	mod = n % (a + b)
	if mod != 0:
		if mod < b:
			return num * b + mod
		else:
			return num * b + b
	else:
		return num * b

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
List = list(map(int, input().split()))

Set0 = List[0]//(List[1]+List[2])

Blue = Set0 * List[1] + min(List[0] - (List[1]+List[2])*Set0, List[1])

print(Blue)

Submission status: Accepted

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

sho = n//(a+b)
amari = n%(a+b)

print(sho*a+min(amari,a))

Submission status: Accepted

Solution code:
N,A,B = list(map(int,input().split()))
NN = N % (A+B)
NNN = N // (A+B)
ans = 0
ans += NNN*A
if 0 <= NN <= A:
    ans += NN
else:
    ans += A
print(ans)

Submission status: Accepted

Solution code:
List = list(map(int, input().split()))

Set0 = List[0]//(List[1]+List[2])
E = List[0] - (List[1]+List[2])*Set0

if E >= List[1]:
    Blue = Set0 * List[1] + List[1]
else:
    Blue = Set0 * List[1] + E

print(Blue)

Submission status: Accepted

Solution code:
import math

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

if a == 0:
    print(0)

elif a >= n:
    print(n)

else:
    num_a = (n // (a+b)) * a
    left_repeated = (n % (a+b))
    print(num_a + min(left_repeated, a))

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
sho = n//(a+b)
amari = n % (a+b)
print(sho*a+min(a, amari))

Submission status: Accepted

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

Submission status: Accepted

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

if N%(A+B) <= A:
    print(int(int(N/(A+B))*A+N%(A+B)))
else:
    print(int(int(N/(A+B))*A+A))

Submission status: Accepted

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

p, q = n//(a+b), n%(a+b)
x = min(q, a)
print(p*a + x)