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,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,a,b = LI()
    c = a+b
    r = n // c * a
    r += min(a, n % c)

    return r


print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

n = N % (b+r)
if n>b:
    print(int(N / (b+r)) * b + b)
else:
    print(int(N / (b+r)) * b + n)

Submission status: Accepted

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

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

ans += min(a, r)

print(ans)

Submission status: Accepted

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

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

print(x)

Submission status: Accepted

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



k = n // (a + b)

c = k * a

md = n % (a + b)

if md >= a:
    c += a
else:
    c += md

print(c)

Submission status: Accepted

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

q, r = divmod(N, A + B)
print(q * A + (A if A <= r else r))

Submission status: Accepted

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

if mod<a:
  print(a*q+mod)
else:
  print(a*q+a)

Submission status: Accepted

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

# nは高橋君の試行よりも絶対に小さいとする

# 青を置いて赤を置いて，という一連の動作がnの中に何個入っているか
c = int(n / (a+b))
count = c * a

#余りの部分
d = int(n % (a+b))
#dが青いボールよりも大きい場合
if d > a:
    count += a

#dが青いボールよりも小さい場合
if d <= a:
    count += d

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

x,y = divmod(N,(A+B))

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

Submission status: Accepted

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

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:
import math
N, A, B = (int(x) for x in input().split(' '))
tmp = A * math.floor(N/(A+B))

if ( N % (A+B) ) > A:
  print(tmp+A) 
else:
  print(tmp+( N % (A+B)))

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:
a=list(map(int,input().split()))
num=a[1]*(a[0]//(a[1]+a[2]))
if a[0]%(a[1]+a[2])>=a[1]:
  num=num+a[1]
else:
  num=num+a[0]%(a[1]+a[2])
print(num)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int,input().split())
if a == 0 and b == 0:
    print(0)
if a != 0 or b != 0:
         
    kumi = n // (a + b)
    nokori = n % (a + b)
    if nokori == 0:
        print(a * kumi)
    elif nokori >= 1 and nokori < a:
        print(a * kumi + nokori)
    elif nokori >= a:
        print(a * kumi + a)

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
# 単位長さ
C = A+B
base = A*(N//C)

if N%C >= A:
    hasu = A
else:
    hasu = N%C

answer = base + hasu
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

N, A, B = map(int, input().split())
C = A+B
x = N//C
print(x*A+min(N-x*C, A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
b=int(N/(A+B))
ans=int(A*b)
if(N-b*(A+B)<=A):
    ans=ans+N-b*(A+B)
else:
    ans+=A
print(int(ans))

Submission status: Accepted

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

# 1.A,Bを1グループとして計上
n_group = N // (A+B)
ans = A * n_group

# 2.Aの追加できる分の計上
res = N - (A+B)*n_group
ans += min(A,res)

# 3.answer
print(ans)

Submission status: Accepted

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

c = a + b
n_1 = n // c
amari = n % c

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()
n,a,b = map(int, s.split(" "))
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:
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(8, 3, 4), 4)

    def test_2(self):
        self.assertEqual(think(8, 0, 4), 0)

    def test_3(self):
        self.assertEqual(think(6, 2, 4), 2)


def solve():
    n, a, b = read()
    result = think(n, a, b)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, a, b):
    mode = a + b
    if n % mode == 0:
        return a * (n // mode)
    else:
        blue = a * (n // mode)
        remain = n - (n // mode) * mode
        if a <= remain:
            return blue + a
        else:
            return blue + remain


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

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

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:
"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
import bisect
import heapq
# from math import *
from collections import defaultdict as dd  # defaultdict(<datatype>) Free of KeyError.
from collections import deque  # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()


def out(var): sys.stdout.write(var)


def l(): return list(map(int, data().split()))


def sl(): return list(map(str, data().split()))


def sp(): return map(int, data().split())


def ssp(): return map(str, data().split())


def l1d(n, val=0): return [val for i in range(n)]


def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]


n, a, b = sp()
answer = min(a, n % (a+b))
temp = n - (n % (a+b))
answer += a * (n // (a+b))
out(str(answer))

Submission status: Accepted

Solution code:
i = input()
j = i.split(' ')
c,b,r = int(j[0]),int(j[1]),int(j[2])
if b == 0:
    print(0)
elif b <= c%(b+r):
    rsl = b*(c//(b+r))+b
    print(rsl)
else:
    rsl = b*(c//(b+r))+(c%(b+r))
    print(rsl)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = a * (n // c) + min(a, mod)
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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 = list(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())
c=n//(a+b)
d=0
if a==0:
	print(0)
else:
	if n>=(a+b):
		if n-c*(a+b)<=a:
			d=a*c+n-c*(a+b)
			print(d)
		else:
			d=a*(c+1)
			print(d)
	else:
		if n>=a:
			print(a)
		else:
			print(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools

INF = 1001001001

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']
Yn=['Yes','No']
 
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
#ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

set_num = N // (A + B)
mod_num = N % (A + B)
if mod_num >= A :
    mod_num = A

ans = set_num * A + mod_num
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

q = int(n/(a+b))
c = n-q*(a+b)

if c<=a:
    ans = a*q+c
else:
    ans = a*(q+1)

print(ans)

Submission status: Accepted

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


S = A+B
div = N//S
dd = N % S

ans = div * A + min(dd,A)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

res = 0

res += (N // (A+B)) * A
res += min([N % (A+B), A])

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = [int(x) for x in input().split()]

total = line[0]
b = line[1]
r = line[2]

ini = (total//(b+r))*b
ini = ini + min([b, total - ((b+r)*(total//(b+r)))])

print(ini)

Submission status: Accepted

Solution code:
N,blue,red = map(int,input().split())
count = N // (blue + red)
amari = N % (blue + red)
if N%(blue+red) >= blue:
    print(blue*(count + 1))
else:
    print(blue * count + amari)

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

Submission status: Accepted

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

num_A=int(N/(A+B))
sur=int(N-(A+B)*num_A)

if A==0:
    print(0)
elif A!=0 and N>(A+B) and sur>=A:
    print(num_A*A+A)
elif A!=0 and N>(A+B) and sur<A:
    print(num_A*A+sur)
elif A!=0 and N<=(A+B) and N>=A:
    print(A)
elif A!=0 and N<=(A+B) and N<A:
    print(N)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3 ## -*- python -*-

t = input().split()
n = int(t[0])
a = int(t[1])
b = int(t[2])

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

print("{}".format(a*x + min(a,y)))

Submission status: Accepted

Solution code:
num = input().split(" ")
ball = int(num[0])
blue = int(num[1])
red = int(num[2])

a = ball // (blue + red)
b = ball - a * (blue + red)
if(b > blue):
    b = blue
print(a*blue + b)

Submission status: Accepted

Solution code:
N = list(map(int, input().split()))
print((N[0]//(N[1]+N[2]))*N[1] + min([N[0]%(N[1]+N[2]), N[1]]))

Submission status: Accepted

Solution code:
N,A,B = [int(i) for i in input().rstrip().split()]
s = N // (A+B)
a = min( N % (A+B), A )
print(s*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 = list(map(int,input().split()))
def problem2(N, A, B):
  if A <= N % (A+B):
    answer = (N // (A+B)) * A + A
  else:
    answer = (N // (A+B)) * A + N % (A+B)
  return answer
print(problem2(N, A, B))

Submission status: Accepted

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

Submission status: Accepted

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

n = int(n)
a = int(a)
b = int(b)

q = n // (a + b)
rest = n - q * (a + b)

if rest >= a:
    blue_ball = a * q + a
    print(blue_ball)
else:
    blue_ball = a * q + rest
    print(blue_ball)

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

Submission status: Accepted

Solution code:
#AtCoder

N, A, B = map(int, input().split())
q, mod = divmod(N,(A+B))
blue = (q*A)
blue += min(mod, A)

print(blue)

Submission status: Accepted

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

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

ans = (Q * A + min(r,A))
print(ans)

Submission status: Accepted

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

c = b + r

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

Submission status: Accepted

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

AB = A + B
x1 = N // AB
x2 = N % AB

if x2 < A:
    ao = A * x1 + x2

else:
    ao = A * x1 + A
print(ao)

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

Submission status: Accepted

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

if lost >= a:
    lost = a

print(a * (n // sumab) + lost)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

if A!=0:
    ans = N//(A+B)*A
    mod = N%(A+B)
    plus = min(mod, A)
    c = ans + plus 
else:
    c = 0
print(c)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

c = a+b

ans = n//c *a
remainder = n%c

ans += min(remainder,a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if int(A) == 0:
    print('0')
else:
    k = (int(N)//(int(A)+int(B))) * int(A) 
    if int(N)%(int(A) + int(B)) >= int(A):
        k = k + int(A)
    else:
        k = k + int(N)%(int(A) + int(B))
    print(str(k))

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())
syou, amari = divmod(N, (A + B))
if amari > A:
  amari = A  
print((syou * A) + amari)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, blue_num, red_num = map(int, input().split())

count = n // (blue_num + red_num)
rest = n % (blue_num + red_num)

if rest > blue_num:
    print(count * blue_num + blue_num)
else:
    print(count * blue_num + rest)

Submission status: Accepted

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

if A==0:
  print(0)
elif A>=N:
  print(N)
elif N>A and N<=A+B:
  print(A)
elif N>A and N>A+B and A>=remainder:
  out = roop * A + remainder
  print(out)
elif N>A and N>A+B and A<remainder:
  out = roop * A + A
  print(out)

Submission status: Accepted

Solution code:
inp=list(map(int,input().split()))
s=inp[0]
b=inp[1]
r=inp[2]
print(s//(b+r)*b+min(s%(b+r),b))

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(' '))
r = a * int(n / (a + b)) + (a if a < n % (a + b) else n % (a + b))
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

else:
    rem=min(N%(A+B),A)
    print(N//(A+B)*A+rem)

Submission status: Accepted

Solution code:
S = input()
N = int(S.split(' ')[0])
A = int(S.split(' ')[1])
B = int(S.split(' ')[2])
 
b_count = (N // (A+B)) * A
rem = N % (A+B)
b_count = b_count + min(rem, A)
print(b_count)

Submission status: Accepted

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

m = a + b

t, r = divmod(n, m)

ans = t*a

if r > 0:
    ans += min(a, r)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
info = [int(n) for n in input().split()]

group = info[1] + info[2]

a = info[0] // group
b = info[0] % group
if b > info[1]:
    b = info[1]


result = a * info[1] + b
print(result)

Submission status: Accepted

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

q,mod=divmod(n,a+b)

c=q*a+min(a,mod)

print (c)

Submission status: Accepted

Solution code:
N,b,r = map(int,input().split())
if(b == 0 and r == 0):
  print(0)
elif (b ==0):
  print(0)
else :
  sets = N//(b+r)
  surplus = N%(b+r)
  if(surplus - b > 0):
    residue = b
  elif(surplus - b < 0):
    residue = surplus  
  Number_of_Blue = sets * b + residue
  print(Number_of_Blue)

Submission status: Accepted

Solution code:
NAB = input()
n_a_b = NAB.split(" ")
N = int(n_a_b[0])
A = int(n_a_b[1])#青
B = int(n_a_b[2])#赤
numOfAB = N//(A+B)
n = N - numOfAB*(A+B)#残りのボールの数
if (n - A) >= 0:
    print(numOfAB*A + A)
else:
    print(numOfAB*A + n)

Submission status: Accepted

Solution code:
s = input().split(" ")
N = int(s[0])
A = int(s[1])
B = int(s[2])

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

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

Submission status: Accepted

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

unit = a + b

if n >= unit:
  # c: 商
  # d: 余り
  c = n // unit
  d = n % unit
  num = c * a
  if d >= a:
    num += a
  else:
    num += d
else:
  d = n % unit
  if d >= a:
    num = a
  else:
    num = d
    
print(num)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if D >= 1:
    ans = A * D
    if N % C <= A:
        ans = ans + N%C
    elif N % C > A:
        ans = ans + A

elif D < 1:
    if N >= A:
        ans = A
    else:
        ans = N
print(ans)

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:
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:
s, a, b = map(int, input().split())
ans = (s//(a+b)) * a
mod = s%(a+b)
if mod > a:
    ans += a
else:
    ans += mod

print(ans)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b=a[0]
c=a[1]
d=a[2]
e=0
f=0
e = (b//(c+d))*c
f= b % (c+d)
if c<=f:
  e=e+c
else:
  e=e+f

print(e)

Submission status: Accepted

Solution code:
S = input().split()
N = int(S[0])
A = int(S[1])
B = int(S[2])
AB = A + B
DIV = int(N / AB)
MOD = N % AB
X = 0
if MOD <= A:
  X = MOD
else:
  X = A
print(A * DIV + X)

Submission status: Accepted

Solution code:
list = input().split(" ")
N = int(list[0])
A = int(list[1])
B = int(list[2])

num1 = N // (A + B)
num2 = N % (A + B)
if num2 <= A:
    print(num1 * A + num2)
else:
    print(num1 * 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 = input().split()
N = int(n)
A = int(a)
B = int(b)
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:
S,a,b=(int(x) for x in input().split())
ans = S//(a+b) * a
rem = S % (a+b )
ans +=min(rem,a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, input().rstrip('\n').split()))
    d, m = divmod(n, (a + b))
    print(d * a + min(m, a))


if __name__ == '__main__':
    solve()

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=[int(x) for x in input().split()]
a,b = divmod(N,A+B)
print((a+1)*A if b>A else a*A+b)

Submission status: Accepted

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

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

Submission status: Accepted

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

#output
answer = 0
c = N//(A+B)

answer += c * A

if N - c*(A+B) < A:
    answer += N - c* (A+B)
else:
    answer += A
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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