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:
def main():
    N, A, B = map(int, input().split())
    ret = 0
    AB = A + B
    times = N // AB
    ret += (times * A)

    left = min(N - AB*times, A)
    ret += left
    print(ret)

main()

Submission status: Accepted

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

num = N // (A + B)

tmp = N - (A + B) * num
if tmp <= A:
    blue_num = tmp
    red_num = 0

else:
    blue_num = A

blue_num = blue_num + num*A
print(blue_num)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
l=A+B
c,r=divmod(N,l)
if r>A:
  r=A
print(A*c+r)

Submission status: Accepted

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

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

amari = (N%(A+B))*( (N%(A+B))<=A ) + A*( (N%(A+B))>A )

print( dai + amari )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, open(0).read().split())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b  = [int(x) for x in input().split()]
summ = a * (n // (a + b))
ama = n % (a + b)
if ama > a:
    summ += a
else:
    summ += ama
print(int(summ))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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())
k=a+b
m=n//k
x=n%k
if a>=x:
  y=x
else:
  y=a
ans=m*a+y
print(ans)

Submission status: Accepted

Solution code:
"""
// Author : snape_here - Susanta Mukherjee
     
"""
 
from __future__ import division, print_function
 
import os,sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
 
 
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
    
 
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 
 
 
import math

mod=1000000007 

def main():

    n,a,b=mi()
    s=a+b
    if a==0:
        print(a)
        exit() 
    c=(n//s)*a
    d=min(n%s,a) 
    print(c+d)

# region fastio#
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
 
if __name__ == "__main__":
    #read()
    main() 
#Comment read()

Submission status: Accepted

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

if r > a:
    r = a

print(f*a+r)

Submission status: Accepted

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

Submission status: Accepted

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

c = A + B
p, q = divmod(N, c)
ans = A * (N // c)

if q >= 1:
    if q > A:
        ans += A
    else:
        ans += q

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if A + B == 0:
    print('0')
else:
    AB = A + B
    quo = N // AB
    rem = N % AB
    ans = quo * A + min(rem, A)
    print(ans)

Submission status: Accepted

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

lep = int(n / (a+b))
per = n % (a+b)
if per > a:
    print (lep * a + a)
else:
    print (lep * a + per)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N , A , B = map ( int , input().strip().split(" ") ) ;
c = N // ( A + B ) ;

x = c * A

r = N - c * ( A + B ) ;
if r >=A :
	x += A ; 
else :
	x += r ; 
print ( x ) ;

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().rstrip().split())
k = n // (a + b)
r = n % (a + b)
print(k * a + min(r, a))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N,A,B = [int(i) for i in 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())
c=n//(a+b)
d=n%(a+b)
if d>=a:
    d=a
e=a*c+d
print(e)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

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:
n,a,b = map(int,input().split())

rep = n//(a+b)

#print(rep*b,+n-rep*(a+b),a)

print(rep*a+min(n-rep*(a+b),a))

Submission status: Accepted

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

Submission status: Accepted

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


q=n//(a+b)
r=n%(a+b)
ans=0
if 0<=r<=a:
    print(q*a+r)
elif a<r:
    print(q*a+a)

Submission status: Accepted

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

ans = 0
tmp = A + B

syo = N // tmp
amari = N % tmp

ans += syo * A

if amari < A:
    ans += amari
else:
    ans += A
print(ans)

Submission status: Accepted

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

sum=(n//(a+b))*a
k=n%(a+b)
if k>a:
    k=a
sum+=k
print(sum)

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N, A, B = mulinputs()

    ans = N//(A+B)
    mod = N - (A+B)*ans
    ans *= A
    if mod != 0:
        if mod > A:
            ans += A
        else:
            ans += mod
    # 出力
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N, A, B = map(int, input().split())

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

ans = A * p + min(mod, A)
print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

answer = d * A
if m <= A:
    answer += m
else:
    answer += A

print(answer)

Submission status: Accepted

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

sousa = n//(a+b)
nokori = n - sousa*(a+b)
if nokori > a:
    ao = a
else:
    ao = nokori

print(sousa*a+ao)

Submission status: Accepted

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

if a == 0 or b == 0:
    print(n if b == 0 else 0)
else:
    num_of_sets, rem = divmod(n, a + b)
    a_num = num_of_sets * a
    b_num = num_of_sets * b
    a_add = min(rem, a)
    rem -= a_add
    a_num += a_add
    print(a_num)

Submission status: Accepted

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

pea = (n//(a+b))
cnt = a*pea
cnt += min(a, n-(a+b)*pea)

print(cnt)

Submission status: Accepted

Solution code:
n,a,b=(int(x) for x in input().split())
su = a+b
co = 0
di = n//su
co = di*a
nokori = n-di*su
if nokori>=a:
	print(co+a)
else:
	print(co+nokori)

Submission status: Accepted

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

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

Submission status: Accepted

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

# 1ターンで追加されるボールのかず
append_per_turn = A + B

d = N // append_per_turn
m = N % append_per_turn

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

Submission status: Accepted

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

s = N // (A + B)

a = min(N - s*(A+B), A)

print(s*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, a, b = map(int, input().split())
roop = n // (a + b)
count = roop * a
if n - roop * (a + b) >= a:
    count += a
else:
    count += n - roop * (a + b)
print(count)

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    tot = A + B
    set = N // tot
    res = N % tot

    ans = set * A

    if res >= A:
        ans += A
    else:
        ans += res

    print(ans)



main()

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	

N,blue,red = list(map(int, stdin.readline().rstrip().split()))
total = blue + red
x = N // total
ans = blue*x
ans += min(N%total,blue)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

N, A, B = map(int, sys.stdin.readline().strip().split())

if B == 0:
    print(N)
else:
    s = A + B
    a = N // s
    r = N % s

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

v=n//(a+b)
ans=v*a
mod=n%(a+b)

temp=min(mod,a)
ans+=temp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

[n, a, b] = [int(i) for i in input().split()]
times = math.floor(n / (a + b))
rem = n % (a + b)
if rem <= a:
    output = times * a + rem
else:
    output = times * a + a
print(output)

Submission status: Accepted

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

k = n // (a + b)
if (n - k * (a + b)) > a:
    ans = a * (k + 1)
else:
    ans = a * k + (n - k * (a + b))

print(ans)

Submission status: Accepted

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

one_count = A + B
ans = divmod(N, one_count)
if ans[1] < A:
    print(ans[0]*A + ans[1])
else:
    print(ans[0]*A+A)

Submission status: Accepted

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

Submission status: Accepted

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

boxes = int(N/(A+B))
hasuu = N % (A+B)

blue = boxes*A
if hasuu >= A:
  blue += A
else:
  blue += hasuu

print(blue)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 商 n1 余り n2
n1 = N // (A + B)
n2 = N % (A + B)

# 青いボール
blue = n1 * A
if n2 <= A:
    blue += n2
else:
    blue += A
    
print(blue)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

#print(q,r)

if r == 0:
    print(a*q)
elif r > a:
    print(a*q + a)
else:
    print(a*q + r)

Submission status: Accepted

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

res=N-(A+B)*cnt

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(num1 + num2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

div = n//(b+r)
res = n%(b+r)
resblue = min(res, b)
print(div*b + resblue)

Submission status: Accepted

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

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
n,a,b = map(lambda x: int(x),input().split())

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

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

if y > a :
    y = a
print(x * a + y)

Submission status: Accepted

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

repeat = N // (A + B)
residue = N % (A + B)

ans += A * repeat

if residue < A:
    ans += residue
else:
    ans += A

print(ans)

Submission status: Accepted

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

# print('-----output-----')
print(N // (A+B) * A + min(N % (A+B), A))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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())
a = N//(A+B)
ans = A*a
b = N%(A+B)
if b>=A:
    ans += A
else:
    ans += b

print(ans)

Submission status: Accepted

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

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


if(n2 >= A):
    ans = n1 *A + A
else:
    ans = n1*A + n2

print(ans)

Submission status: Accepted

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

print(d + a if n > a else d + n)

Submission status: Accepted

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

if A==0:
    print(count)
else:
    div=int(N/(A+B))
    rem=N%(A+B)
    if rem<=A:
        print(div*A+rem)
    else:
        print((div+1)*A)

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(int(1e6))

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

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

Submission status: Accepted

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

tmp=n//(a+b)

ans=tmp*a + min(a,(n-tmp*(a+b)))

print(ans)

Submission status: Accepted

Solution code:
def bmon(n , a , b):

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

    ans += min(n % (a + b), a)

    return ans

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

cluster = NAB[1] + NAB[2]
q, mod = divmod(NAB[0], cluster)

q *= NAB[1]
q += NAB[1] if (NAB[1] < mod) else mod

print(q)

Submission status: Accepted

Solution code:
# B - Count Balls

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:
# 2020/03/07
# AtCoder Beginner Contest 158 - B

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

ab = a + b
div = n // ab
rem = n % ab

# Calc
ans = div * a + min(rem, a)

# Output
print(ans)

Submission status: Accepted

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

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

if n%(a+b) != 0:
    ans += min(a, n%(a+b))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(N, A, B):
    loop = N // (A + B)
    delta = N % (A + B)
    return A * loop + min(delta, A)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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


if amari >= a:
    ans += a
elif amari < a:
    ans += amari

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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())
num = N//(A+B)
rest = N%(A+B)
rest_a = rest-A
if rest_a > 0:
  print(num*A + A)
else:
  print(num*A + rest)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


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



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 = (n//(a+b))*a
ans += min(n%(a+b),a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if A == 0:
    print(0)
else:
    count = N // (A+B)
    result = count*A
    if (N-(count*(A+B))) >= A:
        result += A
    else:
        result += (N-(count*(A+B)))

    print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def resolve():
    N,A,B=map(int,input().split())
    if A==0:
        print(0)
        return
    if B==0:
        print(N)
        return

    C=A+B
    D=N//C
    S=N%C

    print(A*D+min(A,S))



if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

lot = a + b
div = n // lot
res = n % lot
ans = div * a + (a if res >= a else res)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if A == 0:
    print(0)
else:
    ans = N // (A + B)

    temp = N % (A + B)

    if temp >= A:
        print(ans * A + A)
    else:
        print(ans * A + temp)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans += a if n >= a else n

print(ans)

Submission status: Accepted

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

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())
a=N//(A+B)
b=N%(A+B)
if A>b:
  c=b
else:
  c=A
print(A*a+c)

Submission status: Accepted

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

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

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

print(int(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, A, B = map(int, input().split())
    pair_count = N // (A+B)
    ans = A * pair_count
    length = pair_count * (A+B)
    ans += min(N-length, A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
k=n//(a+b)
ans=a*k
ans+=max(0,min(a,n-(k*(a+b))))
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)