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

Submission status: Accepted

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

Submission status: Accepted

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

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

if k >= b:
  print(l*b + b)
else:
  print(l*b + k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
temp = input().split()
N, A, B = [int(num) for num in temp]
# print(N, A, B)

q, mod = divmod(N, A + B)
# print(q, mod)

r = A if mod > A else mod

num = A * q + r
print(num)

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

x=int(N/(A+B)) #行いきった回数
y=x*(A+B)

if N-y>A:
    print((x+1)*A)
else:
    print(x*A+(N-y))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
q, mod = divmod(N, (A+B))
print(q*A + min(mod, 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())

c = a+b

print(a*(N//c)+min(N%c, a))

Submission status: Accepted

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

s = N // (A+B)
t = N - s * (A+B)
ans = s*A

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ab_set = N//(A+B)
ab_rem = N%(A+B)

if ab_rem >A:
    print(A + ab_set*A)
else:
    print(ab_rem + ab_set*A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
total=(A+B)*(10**100)
cycle=N//(A+B)
amari=N-cycle*(A+B)
if amari>=A:
    print(A+cycle*A)
else:
    print(amari+cycle*A)

Submission status: Accepted

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

N = a[0]
A = a[1]
B = a[2]

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

if amari <= A:
    print(k*A+amari)
else:
    print(k*A+A)

Submission status: Accepted

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

s = a + b
n_s = n // s
l = n - s * n_s

if l <= a:
	ans = a * n_s + l
else:
    ans = a * n_s + a
    
print(ans)

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
x = N//(A+B)
y = N%(A+B)

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

Submission status: Accepted

Solution code:
N, A, B = list(map(int, input().split()))
x = (N // (A + B))
a = x * A
x = N - (x * (A + B))
if x >= A:
    a += A
else:
    a += x
print(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())

count= N // (A+B)
N = N %(A+B)
blues=A*count
reds=B*count

if N<=A:
	blues+=N
else:
	blues+=A


print(blues)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,a,b=n1()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,b,r=INTM()
    s=r+b
    print(n//s*b+min(b,(n%s)))
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, A, B = LI()

ans = 0

ans = math.floor(N / (A + B)) * A
ans += min(N - math.floor(N / (A + B)) * (A + B), A)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(x) for x in 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())
mod = int(n % (a + b))
cycle = n // (a + b)
if mod == 0:
    print(a * cycle)
elif mod > a:
    print(a * cycle + a)
else: 
    print(a * cycle + mod)

Submission status: Accepted

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

a, b = divmod(N, (A + B))
if A <= b:
    print((a+1) * A)
else:
    print((a * A) + b)

Submission status: Accepted

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

mod = n % (a+b)
num = n // (a+b)
if a == 0:
    print(0)
else:
    print(num*a+min(mod,a))

Submission status: Accepted

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

pair = a + b

s = n//pair
t = n%pair

adj = min(a, t)

print(s*a + adj)

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

# まとめて数える方
taba = n // (a + b)
taba_blue = taba * a

# ちょっと余った方
rest = n - taba * (a + b)
if rest <= a:
  haji_blue = rest
else:
  haji_blue = a

print(taba_blue + haji_blue)

Submission status: Accepted

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

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

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

if b == 0:
    print(n)
    sys.exit()

ab = a + b

n_ab = n // ab

ans = n_ab * a

remain = n - ab * n_ab

ans += min(a, remain)

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

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n,a,b = map(int,input().split())
  ans = n//(a+b) * a
  rem = n % (a+b)
  ans += min(rem,a)
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(C)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=[int(i) for i in input().split()]
bball=N//(A+B)*A
bamari=N%(A+B)
if bamari>A:
    bball=bball+A
else:
    bball=bball+bamari

print(bball)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

l = a + b
set_cnt = n // l
rest = n % l
if rest >= a:
    ans = set_cnt * a + a
else:
    ans = set_cnt * a + rest

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

Submission status: Accepted

Solution code:
n, a, b = [int(i) for i in input().split()]
if n%(a+b)<= a:
    c= n%(a+b)
else:
    c=a
print(a*(n//(a+b))+c)

Submission status: Accepted

Solution code:
import math
a,b,c= input().split()
x,y,z=(int(a),int(b),int(c))
num_one_gr = y + z
num_gr = math.floor(x/num_one_gr)
amari = x - num_one_gr*num_gr
if amari <= y:
    total = y * num_gr + amari
else:
    total = y*(num_gr + 1)
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

rate = N//(B+R)

m = 0
N %= (R+B)
if N!=0:
    if B >= N:
        m = N
    else:
        m = B
ans = rate * B + m
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math
n, a, b = map(int, input().split())
 
r = a*math.floor(n/(a+b))
res = n%(a+b)
if res>a:
  r += a
else:
  r += res
 
print(str(int(r)))

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

A_amari = A % 2
B_amari = B % 2

# print(A_amari)
# print(B_amari)

if A+B == 0:
    print(0)
    exit()
else:
    cnt = N // (A+B)
    amari = N % (A+B)

# print(cnt)
# print(amari)
if amari <= A:
    print(A*cnt+amari)
else:
    if amari <= B or amari > A:
        print(A*(cnt+1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, blue, red = map(int, input().split())
ball = blue + red

if blue == 0:
    print(0)
    sys.exit()
if n <= blue or red == 0:
    print(n)
    sys.exit()
if n <= ball:
    print(blue)
    sys.exit()

ans = n // ball
additional = n % ball

if additional == 0:
    print(ans * blue)
elif additional <= blue:
    print(ans * blue + additional)
else:
    print((ans + 1) * blue)

Submission status: Accepted

Solution code:
#ABC158B
import sys
n,blue,red = map(int, sys.stdin.readline().split())

total = blue + red
syo = n // total
amari = n % total
if n <= blue:
    print(n)
elif n <= total:
    print(blue)
elif amari<=blue:
    print(syo*blue + amari)
elif amari >blue:
    print(syo*blue + blue)

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

N, A, B = map(int, sys.stdin.readline().rstrip().split())
C = A + B
n = N // C
ans = n * A
r = N - n * C
ans += min(A, C - (C - r))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
S,A,B=map(int,input().split())

q=S//(A+B)
mod=S%(A+B)

if mod>=A:
    print(q*A+A)
else:
    print(q*A+mod)

Submission status: Accepted

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

if A == 0:
    print(0)
elif b <= A:
    print(a*A+b)
else:
    print(a*A+A)

Submission status: Accepted

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

sum = 0
times, mod = divmod(N, blue + red)
sum += blue * times
if mod < blue :
    sum += mod
else :
    sum += blue

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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 += a
else:
    ans += n % (a+b)
print(ans)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
ans = 0
if a > 0:
    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 = map(int, input().split())
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())
t = n%(a+b)
u = n//(a+b)
ans = u*a
if t <= a:
    ans += t
else:
    ans += a
print(ans)

Submission status: Accepted

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

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:
def main():
    N,A,B = (int(i) for i in input().split())

    d,m = divmod(N, A+B)
    ans = d * A
    if A > m:
        ans += m
    else:
        ans += A
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

L = N % (A + B)
if L < A:
    ans += L
else:
    ans += A

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B = list(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())
n = N//(A+B)
p = N%(A+B)
if p<=A:
    print(n*A+p)
else:
    print(n*A+A)

Submission status: Accepted

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

x = n % (a + b) 
if x > a:
  x = a

print((n // (a + b)) * a + x)

Submission status: Accepted

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

Submission status: Accepted

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

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

if y<=a:
    ans = x*a + y
else:
    ans = x*a + a
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:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


n, a, b = inp_list()
q = n // (a + b)
n -= q * (a + b)

ans = q * a + min(a, n)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

quotient = N // (A+B)
remainder = N % (A+B)

if quotient == 0:
    ans = N if A >= N else A
elif remainder > A:
    ans = quotient*A + A
else:
    ans = quotient*A + remainder

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, a, b = map(int, input().split())
x = n // (a + b)
r = n % (a + b)
print(a * x + r) if r < a else print((a * (x + 1)))

Submission status: Accepted

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

num = n // (a+b)
remainder = n % (a+b)

if remainder < a:
    print(num * a + remainder)
else:
    print((num+1) * a)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

stack = int(n / (a+b))
rem = n % (a+b)

if a > rem:
    print(stack * a + rem)
else:
    print(stack * a + a)

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=map(int, input().split())
C=N//(A+B)*A
D=N%(A+B)
if D<=A:
    print(C+D)
else:
    print(C+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())
it = N//(A+B)
res = N%(A+B)
nb = it*A + min(res,A)
print(nb)

Submission status: Accepted

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

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

amari = min(a, amari)

print(sho * a + amari)

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

Submission status: Accepted

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

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

sets = int(N/(A+B))
flow = N - sets*(A+B)
if flow > A:
    flow = A
print(sets*A+flow)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

n_div_ab = n // (a+b)
n_mod_ab = n % (a+b)
if a == 0:
    res = 0
elif n_mod_ab // a > 0:
    res = a
else:
    res = n_mod_ab

print(n_div_ab * a + res)

Submission status: Accepted

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

Submission status: Accepted

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

if amari <= a:
  print(n//roop * a + amari)
else:
  print(n//roop * a + a)

Submission status: Accepted

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

print(blue)

Submission status: Accepted

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

r = a+b

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    n, a, b = map(int, string.split())
    return str(n // (a + b) * a + min(n % (a + b), a))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

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

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())
# A: blue, B: red
t = N // (A+B) 

ans = t * A

temp = N - t*(A+B)
if temp >= A:
    ans += A
else:
    ans += temp
print(ans)

Submission status: Accepted

Solution code:
# 解答確認後
N, A, B = map(int, input().split())
AB = A + B

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

Submission status: Accepted

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

if N >= AB:
    iters, div = divmod(N, AB)
    if div <= A:
        print((A*iters + div))
    else:
        print((A*(iters + 1)))
elif N >= A:
    print(A)
else:
    print(N)

Submission status: Accepted

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

x = n//(a+b)
y = n%(a+b)
if y-a < 0:
  z = y
else:
  z = a

ans = x*a + z


print(ans)

Submission status: Accepted

Solution code:
s=input().split()
n=int(s[0])
a=int(s[1])
b=int(s[2])
p=n//(a+b)
q=n%(a+b)
print(a*p+q if q<a else a*(p+1))

Submission status: Accepted

Solution code:
import sys

def main():
    N, A, B = list(map(int, sys.stdin.readline().rstrip().split()))
    count = int(N / (A + B))
    mod = N % (A + B)
    if mod > A:
        print((count * A) + A)
    else:
        print((count * A) + mod)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
#print(l)
ans = 0

mm = l[0]//(l[1]+l[2])
nn = l[0]%(l[1]+l[2])

ans += mm*l[1]

if nn >= l[1]:
  ans += l[1]
else:
  ans += nn

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, b, r = map(int, input().split())
# inputText1 = "8 3 4"
# inputText1List = inputText1.split()
# n = int(inputText1List[0])
# b = int(inputText1List[1])
# r = int(inputText1List[2])
if b == 0:
    print(b)
else:
    # i = (count // (b + r)) + 1 # 最大繰り返し数
    baseTextCount = b + r # 7
    i = n // baseTextCount
    mod = n % baseTextCount
    # print(i * b) # あまりを除いた青のボール数
    if mod < b:
        print(i * b + mod)
    else:
        print(i * b + b)

Submission status: Accepted

Solution code:
inputText1 = input()
# inputText1 = "8 3 4"
inputText1List = inputText1.split()
n = int(inputText1List[0])
b = int(inputText1List[1])
r = int(inputText1List[2])
count = 10 **100
if b == 0:
    print(b)
else:
    # i = (count // (b + r)) + 1 # 最大繰り返し数
    baseTextCount = b + r # 7
    i = n // baseTextCount
    mod = n % baseTextCount
    # print(i * b) # あまりを除いた青のボール数
    if mod < b:
        print(i * b + mod)
    else:
        print(i * b + b)

Submission status: Accepted

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

n = n_a_b[0]
a = n_a_b[1]
b = n_a_b[2]

division = n // (a+b)
remainder = n % (a+b)

answer = division * a

if remainder <= a:
  answer += remainder
else:
  answer += a

print(answer)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,a,b=map(int,input().split())
x=n//(a+b)*a
y=n%(a+b)
y=min(y,a)
print(x+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:
n, a, b = map(int, input().split())
l, m = divmod(n, a+b)
print(l*a+min(a, m))

Submission status: Accepted

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

a = N // (A + B) * A
b = N % (A + B) if N % (A + B) < A else A

print(a + b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
total,blue,red=map(int,input().split())
a=blue+red
if total<blue:
    ans=total

else:
    ans=(total//a)*blue
    temp=total%a
    if temp>blue:
        ans+=blue
    else:
        ans+=temp

print(ans)

Submission status: Accepted

Solution code:
total,blue,red=map(int,input().split())
a=blue+red
if total<blue:
    ans=total
elif total<a:
    ans=blue
else:
    ans=(total//a)*blue
    temp=total%a
    if temp>blue:
        ans+=blue
    else:
        ans+=temp

print(ans)