Problem:


Score : 200 points

Problem Statement

Takahashi has many red balls and blue balls. Now, he will place them in a row.

Initially, there is no ball placed.

Takahashi, who is very patient, will do the following operation 10^{100} times:

Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.

How many blue balls will be there among the first N balls in the row of balls made this way?

Constraints

1 \leq N \leq 10^{18}

A, B \geq 0

0 < A + B \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of blue balls that will be there among the first N balls in the row of balls.

Sample Input 1

8 3 4

Sample Output 1

4

Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.

Sample Input 2

8 0 4

Sample Output 2

0

He placed only red balls from the beginning.

Sample Input 3

6 2 4

Sample Output 3

2

Among bbrrrr, there are two blue balls.



Sample input:
8 3 4


Sample output:
4

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	N, A, B = map(int, input().split())
	x = N // (A + B)
	y = N % (A + B)
	ans = A * x + min(y,A)
	print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = N // (A + B)

ans = 0
if x == 0:
    if N > A:
        ans = A
    else:
        ans = N
else:
    if N - (A + B)*x > A:
        ans = A * (x + 1)
    else:
        ans = N - B * x

print(ans)

Submission status: Accepted

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

b_r = blue + red

round = int(n/b_r)

if n - (b_r * round) == 0:
  print(blue * round)
else:
  empty = n - (b_r * round)
  if empty < blue:
    print((blue * round) + empty)
  else:
    print((blue * round) + blue)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
ab = a+b

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

ans = n // ab
ans = ans * a
if n % ab > a:
    ans += a
else:
    ans += n % ab

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

if n - int(n/(a+b))*(a+b) > a:
    answer = answer + a
else:
    answer = answer + (n - int(n/(a+b))*(a+b))

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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


if a==0:
    print(0)
else:
    na=n//(a+b)
    nr=n%(a+b)
    nx=na*a+min(nr,a)
    print(nx)

Submission status: Accepted

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd
enu = enumerate

sys.setrecursionlimit(10**7)
N, A, B = map(int, input().split())

AB = A+B
if AB == 0:
    print(0)
    exit()

if A >= N:
    print(N)
elif AB >= N:
    print(A)
else:
    cnt = A * (N//AB)
    if N % AB >= A:
        cnt += A
    else:
        cnt += N % AB
    print(cnt)

Submission status: Accepted

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

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

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

    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    if amari - a < 0:
        print(count*a + amari)
    else:
        print((count + 1) * a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
string = input()
n = int(string.split()[0])
a = int(string.split()[1])
b = int(string.split()[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 = list(map(int, input().split()))

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

Submission status: Accepted

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

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

if mod <= A:
    print(int(A * n + mod))

else:
    print(int(A * (n + 1)))

Submission status: Accepted

Solution code:

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

cnt = 0
sum = 0
i = 0
if a == 0:
    print(0)
    exit()
i = x // (a + b)
cnt = i * a
sum = i * a + i * b


print(cnt + min(x - sum, a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, A, B = list(map(int, input().split(' ')))
S = A + B
count = N // S if S != 0 else 0
mod = min(N % S, A) if S != 0 else 0
print(A*count + mod)

Submission status: Accepted

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

S=N//(A+B)
E=N%(A+B)

if E>A:
  print(S*A+A)
else:
  print(S*A+E)

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n, a, b = map(int, input().split())
    cnt = 0
    if a == 0:
        print(0)
        return 0
    div = n // (a+b)
    cnt = div * a
    n -= div * (a+b)
    while n > 0:
        cnt += min(n,a)
        n -= a
        n -= b
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

nn = N // (A+B)

amari = N % (A+B)

if amari < A:
    print(A*nn + amari)
else:
    print(A*nn + A)

Submission status: Accepted

Solution code:
n, b, r = map(int, input().split())
i = 0
hoge = n // (b+r)
count = hoge*b
n = n - hoge*(b+r)
if n == 0:
    print(count)
while (n>i):
    count += b
    i += b
    if n<=i:
        print(count - (i-n))
        break
    i += r
    if n<=i:
        print(count)

Submission status: Accepted

Solution code:

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

ans = 0
S=A+B
Q=int(N/S)
#print(int(N/(A+B)))
#for i in range(1, int(N/(A+B))+1):
#    ans = ans + A
ans = Q*A

r = N-Q*S
#print(r)

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

print(ans)

Submission status: Accepted

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

ans = 0
shou = n // (a + b)
amari = n % (a + b)
if a == 0:
    ans = 0
else:
    ans = a * shou + min(a, amari)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
def amari(n,a,b):
  amari = n % (a+b)
  if amari >= a:
    return(a)
  else:
    return(amari)
cou = n//(a+b)
result = a * (n//(a + b)) + amari(n,a,b)
print(result)

Submission status: Accepted

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

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

if x<=a:
  ans += x
else:
  ans += a

print(ans)

Submission status: Accepted

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

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

N = N - ((A + B) * x)
if N < A:
  result += N
else:
  result += A
print(result)

Submission status: Accepted

Solution code:
import math

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

answer = math.floor(N / (A+B))*A

remain = N - math.floor(N / (A+B))*(A+B)
if remain<=A:
  answer += remain
else:
  answer += A

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

tms = n // (a + b)
mod = n % (a + b)
cnt = 0

cnt += a * tms
if (mod - a) >= 0:
    cnt += a
else:
    cnt += mod
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math
s,b,r=map(int,input().split())
sum=math.floor(s/(b+r))
ans=b*sum
rem=s-(sum*(b+r))
if rem>=b:
    ans+=b
else :
    ans+=rem
print(ans)

Submission status: Accepted

Solution code:

ls = input().split()
l = [int(i) for i in ls]


b = l[1]+l[2]
n = int(l[0]/b)
a = n*l[1]
if l[0]%b>=l[1]:
    a+=l[1]
else:
    a+=l[0]%b
    
print(int(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())
ab = A + B
cnt = N // ab
remain = N - (cnt * ab)
blue = 0
if remain > A:
    blue = A
else:
    blue = remain
ans = A * cnt + blue
print(ans)

Submission status: Accepted

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

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:
num_str = input().split()

num = [0, 0, 0]

for i in range(3):
  num[i] = int(num_str[i])

count_rb = int(num[0] / (num[1] + num[2]))
amari = int(num[0] % (num[1] + num[2]))

# print(count_rb , amari)

if amari >= num[1]:
  print(count_rb * num[1] + num[1])
else:
  print(count_rb * num[1] + amari)

Submission status: Accepted

Solution code:
import numpy as np

grid = []
#for i in range(1):
array = list(map(int,input().strip().split()))
#    grid.append(array)
#print(array)
n = array[0]
a = array[1]
b = array[2]
if a == 0:
    print(0)
else:
    kaisuu = int(n/(a+b))
    nokori = n%(a+b)
    if nokori < a:
        print(kaisuu*a+nokori)
    else:
        print(kaisuu*a+a)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

i = 0
ab = a+b
ans = (n//ab+1) * a
if n%ab < a:
    ans -= a - n%ab
print(ans)

Submission status: Accepted

Solution code:
N,A,B = [int(x) for x in input().split(" ")]
if (A == 0):
  print(0)
else:
  total_sec = A+B
  print(int(N/total_sec)*A + min(N%total_sec, A))

Submission status: Accepted

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

c = a + b

d = n // c

tmp = n - c * d
if tmp <= a:
    e = tmp
else:
    e = a
print(d * a + e)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

k = n // (a+b)
l = n - (a+b) * k
l = a if l > a else l

ans = k * a + l
print(ans)

Submission status: Accepted

Solution code:
n,a,b=(int(x) for x in input().split())
c=a+b
m=n//c
k=m*c
d=n-k
if d-a>0:
    g=a
else:
    g=d
print(m*a+g)

Submission status: Accepted

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

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

Submission status: Accepted

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

if c > 0:
    ans = a*c + min((n - (a+b)*c),a)
    if ans > (a+b)*(10**100):
        ans = a*(10**100)
else:
    ans = min(a,n)
    
print(ans)

Submission status: Accepted

Solution code:
import math
n, a, b = map(int,input().split())
try:
    ans = int(n / (a + b)) * a + min(n % (a + b),a)
except Exception as e:
    ans = 0
print(ans)

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

k = int(n / ab)
amari = n - k * ab
bcount += k * a
if amari >= a:
    bcount += a
else:
    bcount += amari

print(bcount)

Submission status: Accepted

Solution code:
li = list(map(int,input().split()))
out = int(li[0] / (li[1] + li[2])) * li[1]
remain = li[0] - int(li[0] / (li[1] + li[2])) *  (li[1] + li[2])
if(remain > li[1]):
    out += li[1]
else:
    out += remain
print(out)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
#NをA+Bで割ったときの商
shou = N//(A+B)
#NをA+Bで割ったときのあまり
amari = N%(A+B)

#amariがA以上であれば青を使い切ってる　この時はA*shou+A
if amari >= A:
    print(A*shou+A)
#amariがAより小さいときは青が途中　この時はA*shou+amari
elif amari < A:
    print(A*shou+amari)

Submission status: Accepted

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

amari = N % (b+r)
rupu = N // (b+r)

if amari >= b:
    ans = rupu * b + b
elif amari < b:
    ans = rupu * b + amari

print(ans)

Submission status: Accepted

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

if s >= 1 and t >= a:
  ans = a*(s+1)
elif s >= 1 and t < a:
  ans = a*s+t
elif s == 0 and t >= a:
  ans = a
elif s == 0 and t < a:
  ans = t

print(ans)

Submission status: Accepted

Solution code:
N, A, B = list(map(int, input().split()))
C = A + B
result = 0
if A < N:
    q, mod = divmod(N, C)
    result = q * A + min(mod, A)
else:
    result = N

print(result)

Submission status: Accepted

Solution code:
a = input()
N, A, B = [int(b) for b in a.split(" ")]
blue = (N // (A+B)) * A

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

Submission status: Accepted

Solution code:
# N=総数、A=青、B=赤
N, A, B = map(int, input().split())

# A+Bの商
n = N // (A+B)
# A+Bのあまり
r = N % (A+B)

# A+BのあまりがAより大きい場合は、Aとする
if(r > A):
    b_r = A
else:
    b_r = r

# 青の個数 = 商*A + あまり(0~A)
blue = n * A + b_r

print(blue)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(p*(a+b)-p*b + (q if q <= a else a))

Submission status: Accepted

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

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

if(a == 0):
    print(0)
elif(n == 0):
    print(0)
else:
        
    ans = (n//(a+b)) * a

    tmp = n%(a+b) 

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = a + b
batch = n // count
remain = n % count

if remain > a:
  result = (a * batch) + a
else:
  result = (a * batch) + remain

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# Print(N / (A + B))
set_blue = A*(N // (A + B))

rem = N % (A + B)
if rem >= A:
    rem_blue = A
else:
    rem_blue = rem

print(set_blue + rem_blue)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
 
if N >= A+B:
    ans = A*(N//(A+B))
    ans += min(A,N%(A+B))
else:
    ans = min(A,N)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

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

# 整数除算
m = n // (a+b)

# あまり
amari = n % (a+b)

# まずはあまりを除いた青の数
blue_num = m * a

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

print(blue_num)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
tmp = A * (N//(A+B))
res = N - (A+B) * (N//(A+B))
if res > A:
    print(tmp + A)
else:
    print(tmp + res)

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

Submission status: Accepted

Solution code:
def inputs(): return [int(x) for x in input().split()]
n,a,b = inputs()
ans = n//(a+b)*a
re = n%(a+b)
if re<=a:
  print(re+ans)
else:
  print(a+ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = syou * A

if(amari >= A):
    ans += A
else:
    ans += amari

print(ans)

Submission status: Accepted

Solution code:
import math

line = input().split(" ")
capture = int(line[0])
blue = int(line[1])
red = int(line[2])

amari = capture % (blue + red)
waru = math.floor(capture / (blue + red))

if amari > blue:
	print(blue * waru + blue)
else:
    print(blue * waru + amari)

Submission status: Accepted

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

Submission status: Accepted

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

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, A, B = map(int, input().split())
blue = N // (A + B) * A
if N % (A + B) <= A:
    print(str(blue + N % (A + B)))
else:
    print(str(blue + A))

Submission status: Accepted

Solution code:
def main():
    N,A,B=map(int,input().split())
    count=(N//(A+B))
    if (A+B)*10**100 <= N:
        print(A*10**100)
        return 0
    ans=count*A
    left_ball=N-(A+B)*count
    if A>=left_ball:
        ans+=left_ball
        print(ans)
    else:
        print(ans+A)
        
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, A, B = (int(i) for i in input().split())
k = N//(A+B)
m = N%(A+B)
if m <= A:
    s = m
else:
    s = A
print(k*A+s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

doTest=0

def yn(n):
    if n==1:
        print("Yes")
    else:
        print("No")
    return

def resolve():
    readline=sys.stdin.readline

    n,a,b=list(map(int, readline().strip().split()))
    #arr=list(map(int, readline().strip().split()))
    #n=int(readline().strip())
    #yn(n)
    ab = a+b

    if n <= a:
        print(n)
        return

    if n <= ab:
        print(a)
        return
    t = n//ab
    print(t*a + min(n-t*ab, a))

    return

if doTest==0:
    resolve()
    sys.exit()

Submission status: Accepted

Solution code:
N, A, B = (int(x) for x in input().split())
M = N//(A+B)
L = N%(A+B)
if L>=A:
    L = A
print(M*A + L)

Submission status: Accepted

Solution code:

def main():

    n, a, b = [int(i) for i in input().split()]
    
    result = n // (a + b) * a

    if n % (a + b) > 0:
        if n % (a + b) >= a:
            result += a
        else:
            result += n % (a + b)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    if res < b:
        ans += res
    else:
        ans += b

    print(ans)
    
resolve()

Submission status: Accepted

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

b =  a[1] + a[2]

sho = a[0] // b
amari = a[0] % b

if amari < a[1]:
    print(sho * a[1] + amari)
else:
    print((sho +1 )* a[1] )

Submission status: Accepted

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

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

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


amari = N % (A+B)
sho = math.floor(N/(A+B))

if amari<A:
  last = amari
else:
  last = A



print(int(sho*A+last))

Submission status: Accepted

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

N=(int)(N)
A=(int)(A)
C=(int)(C)

kumi = A+C
kumi_syou = N//kumi
kumi_num = N%kumi

ans = kumi_syou*A

if kumi_num<A:
    print(ans+kumi_num)
else:
    print(ans+A)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

comb = A+B
n = N//comb

nn = n*comb
dif = N - nn

if dif >= A:
  ans = (n+1)*A
else:
  ans = n*A + dif

print(ans)

Submission status: Accepted

Solution code:
import math
a = list(map(int, input().split()))
N = a[0]
A = a[1]
B = a[2]
if N%(A+B)!=0:
    repTimes = math.floor(N//(A+B))
    bB = repTimes*A
    if N%(A+B) > A:
        extra = A
    else:
        extra = N%(A+B)
    bB += extra
else:
    repTimes = math.floor(N//(A+B))
    bB = repTimes * A
print(bB)

Submission status: Accepted

Solution code:
import math

N,A,B =input().split()
N = int(N)
A = int(A)
B = int(B)
count = divmod(N,A+B)
result = count[0]*A
if count[1]<=A:
    result+=count[1]
elif count[1]>A:
    result+=A

print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, A, B = map(int, input().split())
    cell = N // (A + B)
    mod = N % (A + B)

    print(cell * A + min(mod, A))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ao_count = 0

    count_num = N // (A + B)
    amari_num = N % (A + B)



    ao_count = count_num * A

    if A <= amari_num:
        ao_count += A
    else:
        ao_count += amari_num

    print(ao_count)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def main():
    N,A,B = map(int,input().split())
    a = N//(A+B)
    b = N - (a * (A+B))
    if b >= A:
        print(a*A+A)
    elif b < A:
        print(a*A+b)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

AB = A + B

def blue(n):
    if n <= A:
        return n
    else:
        return A


if A == 0:
    print(0)
elif N <= AB:
    r = blue(N)
    print(r)
else:
    t = N // AB
    m = N % AB
    r = blue(m)
    print(t*A+r)

Submission status: Accepted

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

iteration = int(N/(A+B))
extra = N - iteration*(A+B)
extra_A = extra
if extra > A:
    extra_A = A
print(iteration*A+extra_A)

Submission status: Accepted

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

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

x = n // (b + r)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(blue_num)

Submission status: Accepted

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

s=n%(a+b)
w=int(n/(a+b))

if(s<a):
    print(w*a+s)
else:
    print((w+1)*a)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

#print(n)
if((a+b) != 0):
    s = n//(a+b)*a
    l = n - n//(a+b)*(a+b)
    if(l >= a):
        l = a
    print(s+l)
else:
    print(0)