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:
import math
N,A,B= list(map(int,input().split(" ")))
ans = 0
d = N //(A + B)
amari = N % (A + B)
ans += d * A
ans += min(amari,A)
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

n, a, b = na()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(v) for v in input().split()]
c = n // (a + b)
d = n % (a + b)

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

Submission status: Accepted

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

d, rem = divmod(n, a + b)
ans = d * a + min(rem, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
n,a,b = map(int, stdin.readline().rstrip().split())

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

print(ans)

Submission status: Accepted

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

n = N // (A + B)
k = N % (A + B)

if k < A:
    print(n * A + k)
else:
    print(n * A + A)

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, Nb, Nr = map(int, input().split())

batch_total = Nb + Nr
remain = min(Nb, N%batch_total)
iterate_num = N // batch_total

sum_num = iterate_num * Nb + remain
print(sum_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, A, B = map(int, input().split())
    full = N // (A+B)
    ans = full * A
    N -= full * (A+B)
    if N >= A:
        ans += A
    else:
        ans += N
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, a, b = list(map(int, input().split(" ")))
    c = n // (a + b)
    if (n - c * (a + b)) <= a:
        d = n - c * (a + b)
    else:
        d = a

    print(c * a + d)

Submission status: Accepted

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

at = int(N/(A+B))
bt = int(N % (A+B))

if bt > A:
    print(A*at + A)
else:
    print(A*at + bt)

Submission status: Accepted

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

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

    tmp = n % (a + b)

    if tmp > a:
        ans += a
    else:
        ans += tmp

    print(ans)

Submission status: Accepted

Solution code:
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,a,b = IL()
print( N//(a+b)*a + min(N%(a+b),a))

Submission status: Accepted

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

Submission status: Accepted

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

tmp = n // (a+b)
tmpamari = n % (a+b)

ans = tmp * a
ans += min(tmpamari, a)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    print((n // (a+b)) * a + min(n % (a+b), 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 = input().split(" ")
n = int(n)
a = int(a)
b = int(b)

ans = n // (a+b) * a
delta = n % (a + b)
if delta >= a:
    delta = a
ans += delta
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, A, B = map(int, input().split())

    d, m = divmod(N, A + B)
    ans = d * A + min(m, A)
    print(ans)


main()

Submission status: Accepted

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

    d = N // (A + B)
    r = N % (A + B)

    print(d * A + min(r, A))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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


y=N-N//(A+B)*(A+B)

z=min(A,y)

print(x+z)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input = raw_input
N, a, b = map(int, input().split(" "))

unit = a+b
r = N // unit 
q = N % unit
nokori = min(q, a)
out = r*a + nokori
print(out)

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())
X = A + B
ans = N // X * A
ans += min(N%X,A)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sum = A + B

q, mod = divmod(N, sum)

if mod > A:
    mod = A

print(q * A +mod)

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

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

Submission status: Accepted

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

C = A + B
a = N // C
b = N % C
c = a * A + min(b, A)
print(c)

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
count, r = divmod(N, A + B)
ans = A * count + min(A, r)
print(ans)

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
n, a, b = (int(i) for i in input().split())  


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

print(answer)

Submission status: Accepted

Solution code:
# coding:utf-8

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

if A == 0:
    print(0)
else:
    if N <= A:
        print(N)
    else:
        ans, rem = divmod(N, A+B)
        ans *= A
        if rem >= A:
            ans += A
        else:
            ans += rem
        print(ans)

Submission status: Accepted

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


t = A + B
tn = N // t
ta = N % t
res = tn * A

if ta > A:
    print(res + A)
else:
    print(res + ta)

Submission status: Accepted

Solution code:
N,A,B = [int(i) for i 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())

if int(N) <= int(A):
  print(int(N))
elif int(N) <= int(A + B):
  print(int(A))
else:
  a = int(N//(A+B))
  b = int(N - (A+B)*a)
  c = min(b,A)
  print(a*A+c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,a,b = mi()
ans = 0
ans += (n//(a+b)) * a
tmp = n % (a+b)
tmp2 = min(a,tmp)
ans += tmp2
print(ans)

Submission status: Accepted

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

if (r > a):
    r = a

z = t * a + r

print(z)

Submission status: Accepted

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

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

if k <=a:
    print(l*a+k)
else:
    print(l*a+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())
print(A * (N // (A + B)) + min(A, N % (A + B)))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input

def resolve():
    N,A,B=pin()
    ans=0
    cycle=A+B
    ans+=A*(N//cycle)
    t=N%cycle
    if t <= A:
        ans+=t
    else:
        ans+=A
    print(ans)
    #print(N//cycle)
    #print(ans)
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()

"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """8 3 4"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """8 0 4"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6 2 4"""
        output = """2"""
        self.assertIO(input, output)

# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input

def resolve():
    N,A,B=pin()
    ans=0
    cycle=A+B
    ans+=A*(N//cycle)
    t=N%cycle
    if t <= A:
        ans+=t
    else:
        ans+=A
    print(ans)
    #print(N//cycle)
    #print(ans)
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()

"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """8 3 4"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """8 0 4"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6 2 4"""
        output = """2"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
sets = N // (A + B)
rem = N - sets * (A + B)
#print("sets={}, rem={}".format(sets, rem))

if rem <= A:
    print(sets * A + rem)
else:
    print(sets * A + A)

Submission status: Accepted

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

Submission status: Accepted

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

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:
a,b,c=map(int,input().split())
print((a//(b+c))*b+min(b,a%(b+c)))

Submission status: Accepted

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

Submission status: Accepted

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

x = A * (N // (A + B))
y = N % (A + B)

print(x + min(A, y))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, A, B = MI()
    a = N % (A + B)
    b = N // (A + B)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    n,a,b = map(int,input().split())
    x = n // (a + b)
    ans = a * x
    if n-(a+b)*x<=a:
        ans += n - (a + b) * x
    else:
        ans += a
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

c = n // (a+b)
d = c * a
e = min(a, n%(a+b))

print(d + e)

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B = imn()

ans1 = (N //(A+B))*A
mod = (N%(A+B))
ans2 = min(mod, A)

print(ans1+ans2)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=q*a

if r>=a:
  ans+=a
else:
  ans+=r
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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*A+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:
def main():
    N,A,B = map(int,input().split())
    ab =A + B
    div = N // ab
    remain = N % ab

    ans = div*A + min(remain,A)
    print(ans)
    return

if __name__ == "__main__":
    main()

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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B):
    m = N // (A + B)
    x = m * A
    return x + min((N-(A+B)*m), A)


def main():
    N, A, B = read_int_n()
    print(slv(N, A, B))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

c = a + b

if a == 0:
    print(0)
else:
    if n < a:
        print(n)
    else:
        if n < c:
            print(a)
        else:
            print((n // c) * a + min(n % c, a))

Submission status: Accepted

Solution code:
def solve(n, a, b):
    res = n // (a + b) * a
    res += min(n % (a + b), a)
    return res


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


def test():
    assert solve(8, 3, 4) == 4
    assert solve(8, 0, 4) == 0
    assert solve(6, 2, 4) == 2


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, A, B = map(int, input().split(' '))

C = (A + B)
n = N // C
m = min(N - C * n, A)

print(n * A + m)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

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

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:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, A, B = [int(x) for x in input().split()]

    q, r = divmod(N, (A + B))
    ans = 0
    ans += q * A
    ans += min(r, A)

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

se=n//(a+b)
am=n%(a+b)

print(se*a+min(a, am))

Submission status: Accepted

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N,A,B = input_int()

temp_B = N%(A+B)
temp_A = N//(A+B)



print(temp_A * A + min(temp_B, A))

Submission status: Accepted

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

Submission status: Accepted

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

n1=N//(A+B)
n2=N%(A+B)

print(int(n1*A+min(n2,A)))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# /usr/bin/env python3


def count_blue_balls(n, a, b):
    d, m = divmod(n, a + b)
    num_blues = d * a + min(a, m)
    return num_blues


def main():
    n, a, b = (int(z) for z in input().split())
    res = count_blue_balls(n, a, b)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

d, m = divmod(N, A+B)

print(d * A + min(m, A))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

c = A + B

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

ans = 0
cnt = N // c
ans += cnt * A
N -= cnt * c

ans += min(N, 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())

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

if mod > A:
    ans = (shou * A) + A
else:
    ans = shou * A + mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, A, B = map(int, input().split())

S = A+B

if S==0:
  print(0)
else:
  Q = N//S
  R = N%S
  if R>=A:
    print((Q+1)*A)
  else:
    print(Q*A+R)

Submission status: Accepted

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

v = N // (A + B)
amari = N % (A + B)
r = v * A
if amari > A:
    r += A
else:
    r += amari

print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())

M = A + B
c, d = divmod(N, M)
ans = c * A + min(d, A)
print(ans)

Submission status: Accepted

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


x = N // (A + B)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

A_B = A + B

sho = N // A_B

ama = N % A_B

if ama > A:
    print((sho+1)*A)
else:
    print(sho*A + ama)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

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

loop = n // (a+b)
count = a * loop
residue = n - loop * (a+b)

if residue >= a:
    residue = a

count += residue
print(count)

Submission status: Accepted

Solution code:
N, A, B = [int(x) for x in input().split()]
l = A + B
ans = A * (N//l) + min(A, N%l)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--

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())
d=a+b
ans=n//d*a

ans+=min(a,n%d)
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())

count = n // (a+b)
sum = a*count
m = n % (a+b)
if m > a:
  sum += a
else:
  sum += m
print(sum)

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

k = N // (A+B)
l = N % (A+B)

ans = k * A + min(l,A)

print(ans)

Submission status: Accepted

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

c = A + B
d = N // c
e = N % c
a, b = d*A, d*B
a += min(e, A)
b += max(0, min(e-min(e, A), B))
print(a)