Problem:


Score : 200 points

Problem Statement

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

Initially, there is no ball placed.

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

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

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

Constraints

1 \leq N \leq 10^{18}

A, B \geq 0

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

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

Sample Input 1

8 3 4

Sample Output 1

4

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

Sample Input 2

8 0 4

Sample Output 2

0

He placed only red balls from the beginning.

Sample Input 3

6 2 4

Sample Output 3

2

Among bbrrrr, there are two blue balls.



Sample input:
8 3 4


Sample output:
4

Submission status: Accepted

Solution code:
def main():
  n, a, b = list(map(int, input().split()))
  if a == 0:
    return 0
  if b == 0:
    return n
  if n <= a:
    return n
  if (a + b) >= n:
    return a
  
  temp = n - a
  set_count = temp // (a + b)
  mod = temp % (a + b)
  blue_in_mod = 0 if mod <= b else mod - b
  
  return a + (set_count * a) + blue_in_mod

print(main())

Submission status: Accepted

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

blue_ball = a
red_ball = b

n_bai = n // (a + b)
n_amari = n % (a + b)

balls = []
ans = 0

balls_sum = 0

while balls_sum < n_amari:
    balls.append(a)
    balls.append(b)
    balls_sum = sum(balls)

while n_amari > 0:
    if n_amari > blue_ball:
        ans += blue_ball
    else:
        ans += n_amari
    n_amari = n_amari - blue_ball - red_ball

ans += n_bai * blue_ball

print(ans)

Submission status: Accepted

Solution code:
balls = input().split(" ")

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])


if( b == 0 ):
  print( 0 )
else:
  
  step = b + r 
  cnt = n // step
  remain = n % step
  bcnt = cnt * b + min( remain, b)
  
  print( bcnt )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n, a, b = map(int, input().split())
    res = n
    count = 0
    if a == 0:
        print(0)
        exit(0)
    count = res // (a + b)
    res = n - ( ( a + b ) * count )
    if a < res:
        print(a * (count + 1))
    else:
        print(a * count + res)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[N, A, B] = list(map(int, input().split()))
pair = A+B
ans = 0

num = int((N-(N%pair))/pair)

if N - num*pair <= A:
  ans = num*A + N - num*pair
else:
  ans = num*A + A

print(ans)

Submission status: Accepted

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

if A == 0:
    print(0)
else:
    if N > A+B:
        a = N // (A+B)
        b = N % (A+B)
        if b > A:
            b = A
        print(a*A + b)
    else:
        if A > N:
            print(N)
        else:
            print(A)

Submission status: Accepted

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

if a == 0 :
    ans = 0
elif b == 0 :
    ans = n
else :
    roop = a + b
    roop_count = int(n/roop)
    roop_amari = n % roop
    if roop_amari <= a :
        ans = roop_count * a + roop_amari
    elif roop_amari > a :
        ans = roop_count * a + a
        
print(ans)

Submission status: Accepted

Solution code:
N,A,B = (int(x) for x in input().split())
num = N%(A+B)
cnt = 0
if num <= A:
  cnt = num
else:
  cnt = A
  
print(A*(N // (A+B))+cnt)

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

#　商
x = n // (b + r) 

#　余り
y = n % (b + r)


if b == 0:
    print(0)
elif(n <= b):
    print(n)
elif(y == 0):
    print(x * b)
else:
    if y < b:
        print((x * b) + y)
    else:
        print((x * b) + b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,a,b = list(map(int,input().split()))
to, ans = 0 , 0
 
if a == 0:
  print(0)
  exit()
if n < (a + b):
  if n < a:
    print(n)
  else:
    print(a)
  exit()

to = int(n / (a + b))
ans = to * a
if n - ((a + b) * to) < a:
  ans += n - ((a + b) * to)
else:
  ans += a
print(ans)

Submission status: Accepted

Solution code:
import math
import sys

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

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

if a + b >= n:
    print(min(a, n))
    sys.exit()

ans = 0
rep = n // (a + b)

ans += a * rep
n -= (a + b) * rep

ans += (min(a, n))

print(ans)

Submission status: Accepted

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

if n == a + b:
    print(a)
    exit()

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



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

Submission status: Accepted

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

ans = 0
if m > 0:
  ans = a * x + min(a, m)
else:
  ans = a * x
print(ans)

Submission status: Accepted

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

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

g = a + b

ans1 = int((n / g)) * a
rem = n - (int(n / g) * g)
ans2 = min(rem, a)

print(ans1 + ans2)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
if (0<A+B<=10**18)and(0<N<=10**18)and(A>=0)and(B>=0):
    if N%(A+B)<=A:
        c=(N//(A+B))*A+N%(A+B)
        print(c)
    else:
        d=(N//(A+B))*A+A
        print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, A, B = [int(i) for i in input().split()]
if A == 0 and B == 0:
    print(0)
else:
    count = A + B
    setCount = math.floor(N / count)
    amari = N - setCount * count
    if amari > 0:
        if A > amari:
            result = setCount * A + amari
        else:
            result = setCount * A + A
    else:
        result = setCount * A
    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()

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:
N,A,B = map(int,input().split())

b = 0
r = 0

if A >= N:
    print(N)
else:
    C = A * (N // (A+B) )
    D = N % (A+B) 
    if D <= A:
        print(C+D)
    else:
        print(C+A)

Submission status: Accepted

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

    r = N // (A+B)
    m = N % (A+B)
    
    rest = 0
    if A >= m:
        rest = m
    else:
        rest = A

    ans = A*r + rest

    return ans

print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

#moji="b"*A+"r"*B
#print(moji)

if A==B==0:
    print(0)
elif A==0:
    print(0)
else:

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

Submission status: Accepted

Solution code:
#B
N, A, B = list(map(int, input().split()))
su = A + B
ans = (N//su)*A
ext = N%su
if ext <= A:
    ans += ext
else:
    ans += A

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = input().split(" ")

N, A, B = int(line[0]), int(line[1]), int(line[2])

S = A + B
if S == 0:
    print(0)
    exit(0)
div, mod = divmod(N, S)

answer = div * A
answer += mod if mod < A else A
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sho = n // (a + b)
mod = n % (a + b)
if mod <= a:
    ret = sho * a + mod
else:
    ret = sho * a + a

print("{}".format(ret))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n, a, b = na()
    
    if (a == 0 and b == 0) or a == 0:
        print(0)
        return

    if n <= a:
        print(n)
        return
      
    AB = a + b
    if n <= AB:
        print(min(n, a))
        return 
    
    x = int(n / AB)

    print(x * a + min(n - (x * AB), a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m,l = map(int,input().split())
x, y = divmod(n, (m + l))
if y <= m:
    print(x*m+y)
else:
    print(x*m+m)

Submission status: Accepted

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

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

    cnt = 0
    if A <= amari:
        cnt = A
    else:
        cnt = amari
    
    print(n_times * A + cnt)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import numpy as np

NAB=np.array(input().split(" "),dtype=np.int64)

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

div=int(N//(A+B))
mod=N%(A+B)

blue=0
if(mod<=A):
    blue=mod
else:
    blue=A

print(A*div+blue)

Submission status: Accepted

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

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

AB = A+B

#print (N//AB)

if N <= AB*(10**100):
    print (min(A,(N-(N//AB)*AB)) + ((N//AB)*A))
else:
    print (A*(10**100))

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]

"""
count = 0
retu = []
while count < 10 ** 100 and count < N:
    count += 1
    for index in range(A):
        retu.append(1)
    for index in range(B):
        retu.append(0)
retu = retu[0:N]
print(sum(retu))
"""

if N % (A + B) == 0:
    print(N // (A + B) * A)
elif 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())
ab=a+b
s=(n//ab)*a
sd=n%ab
if(sd<=a):
    s+=sd
else:
    s+=a

print(s)

Submission status: Accepted

Solution code:
x = list(map(int,input().split(" ")))
n = x[0]
a = x[1]
b = x[2]

proc = a + b
mul_syo = n // proc
mul_ama = n % proc

ans = 0

if mul_ama <= a:
    ans = (mul_syo * a) + mul_ama
else:
    ans = (mul_syo * a) + a

print(ans)

Submission status: Accepted

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

am = n % (b + r)
s  = n // (b + r)
# print(b)
# print(r)
# print(am)
# print(s)

if am <= b:
    print((s * b) + am)
else:
    print((s+1) * b)

Submission status: Accepted

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

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

if N <= A:
    print(N)
    exit()

set_count = N // (A+B)
extra = N % (A+B)

if extra <= A:
    print(set_count*A + extra)
    exit()
else:
    print(set_count*A + A)
    exit()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, a, b = tuple([int(s) for s in input().split()])
    div = n // (a + b)
    mod = n % (a + b)

    print(a * div + min([a, mod]))

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
mm=max(a,b)
if a==0:
    print(0)
    exit()
if b==0:
    print(n)
    exit()
xx=n//(a+b)
ans=((xx-1)*a)
baaki=n-((xx-1)*a)-((xx-1)*b)
# print(baaki)
while baaki>0:
    temp=min(baaki,a)
    baaki-=temp
    ans+=temp
    if baaki<=0:
        break
    temp=min(baaki,b)
    baaki-=temp
    if baaki<=0:
        break 
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

x=n//(a+b)*a       # a+b個までで入っている青の数（入力例1の場合，3個）
y=n%(a+b)       # nを(a+b)で割った余り（入力例1の場合，1）

if y>a:
    x = x + a
else:
    x = x + y

print(x)

Submission status: Accepted

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = 0
    cnt = N // (A + B)

    if N % (A + B) == 0:
        print(int(A * cnt))
    elif N < A + B:
        print(min(N, A))
    else:
        ret += A*cnt
        if N - (A+B)*cnt <= A:
            ret += N - (A+B)*cnt
        else:
            ret += A

        print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

nokori = N - (result+(B*count))
if N % (A+B):
    if nokori <= A:
        result += nokori
    else:
        result += A

print(result)

Submission status: Accepted

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

M = A+B

C = N//M

b = N-(C*M)
if b>=A:
    print((C+1)*A)
else:
    print(b+C*A)

Submission status: Accepted

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

S = A+B
count = N//S
pre_cnt = A*count
S_amari  = N-S*count
if S_amari >= A:
  cnt  = pre_cnt + A
else:
  cnt = pre_cnt + S_amari

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n, a, b = (int(i) for i in input().split())
q, mod = divmod(ｎ, a+b)
print(a * q + min(mod, a))

Submission status: Accepted

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

Submission status: Accepted

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

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

if  A == 0 :
    print(0)

elif q < 1 and N <= A:
    print(N)
    
elif q < 1 and N > A:
    print(A)
    
elif q >= 1:
    if mod == 0 :
        print(q*A)
    elif mod <= A :
        print(q*A+mod)
    elif mod > A :
        print(q*A+A)

Submission status: Accepted

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

if n<=a:
    print(n)
    exit()

if n<=a+b:
    print(a)
    exit()

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

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

temp1=n//(a+b)

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
ans = divmod(n, a + b)
m = a if a < ans[1] else ans[1]
print(ans[0] * a + m)

Submission status: Accepted

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

if n <= a+b:
    if n >= a:
        print(a)
    elif n < a:
        print(n)
elif n > a+b:
    taba = n//(a+b)
    if n-taba*(a+b) >= a:
        print(taba*a+a)
    elif n-taba*(a+b) < a:
        print(taba*a+n-taba*(a+b))

Submission status: Accepted

Solution code:
N,A,B=input().split()
n=int(N)
a=int(A)
b=int(B)
m=int(n%(a+b))
l=int((n-m)/(a+b))
if m>a:
  y=a
else:
  y=m
x=a*l+y
x=int(x)
print(x)

Submission status: Accepted

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

if b == 0:
    print(0)
elif r == 0:
    print(n)
else:
    k = n // (b + r)
    q = n % (b + r)
    print(b * k + min(q, b))

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if A == 0:
    print(A)
    exit()
n = N // (A + B)
nn = N % (A + B)
if n != 0 and nn <= A:
    print(int(A*n + nn))
elif n != 0 and nn > A:
    print(int(A*(n+1)))
elif n == 0 and N >= A:
    print(A)
elif n == 0 and N < A:
    print(N)

Submission status: Accepted

Solution code:
NAB = input().split()

N = int(NAB[0])
A = int(NAB[1])
B = int(NAB[2])

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

if kaisuu >= 10**100:
  solution = A ** (10**100)
else:
  if amari <= A:
  	solution = A * kaisuu + amari
  else:
    solution = A * kaisuu + A

print(solution)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
ans = 0
ans += n // (a + b) * a      # a + b 個周期の分
ans += min(n % (a + b), a)   # a + b 個周期からはみだした分
print(ans)

Submission status: Accepted

Solution code:
# ABC158 B

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

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

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

print(res1 + res2)

Submission status: Accepted

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

q = N // (A+B)
mod = N % (A+B)
if mod <= A:
    s = (q * A) + mod
    print(s)
else:
    s = (q * A) + A
    print(s)

Submission status: Accepted

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

a = int(N/(A+B))
b = N%(A+B)

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

Submission status: Accepted

Solution code:
a,b,c = map(int,input().split())
d = 0
l = a // (b+c)
k = a % (b+c)
if b == 0:
    print('0')
    
elif b + c >= a:
    if b < a:
        print(b)
    elif b > a:
        print(a)
    
elif b + c < a:
    if a % (b + c) == 0:
        print(int(l))
    elif a % (b + c) != 0:
        if b > k:
            print(int(l*b + k))
        elif b < k:
            print(int(l*b + b))

Submission status: Accepted

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

num_char = (int(N /(a+b)))
num_joyo = (N %(a+b))
result = 0

if num_joyo <= a:
    result = num_char*a + (num_joyo)
else:
    result = num_char*a + a
    
print(result)

Submission status: Accepted

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

N, A, B = list(map(int, input().split()))
ans = 0
abset = N // (A+B)

ans += A * abset

if N % (A+B) != 0:
    if A > N - (A+B)*abset:
        ans += N - (A+B)*abset
    else:
        ans += A

print(ans)

Submission status: Accepted

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

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

if mod<A:
    print(roop*A+mod)
else:
    print(roop*A+A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
n = nums[0]
a = nums[1]
b = nums[2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def count(b, total, N):
  r = N%total
  if r < b:
    return r
  else:
    return b

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

total = b + r

ball = int(N/total) * b + count(b, total, N)
print(ball)

Submission status: Accepted

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

x, y = divmod(n, a + b)
i, j = divmod(y, a + 1)

if i > 0:
	print(a * x + a)
else:
    print(a * x + j)

Submission status: Accepted

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

if a == 0:
  print(0)
  exit()
elif b == 0:
  print(n)
  exit()

t = a + b

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

Submission status: Accepted

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

C = N // (A + B)
D = N % (A + B)

R = C * A + min(A, D)
print(R)

Submission status: Accepted

Solution code:
import numpy as np
import math
s = input().split()
N = int(s[0])
A = int(s[1])
B = int(s[2])

x = int(N/(A+B))
if N-x*(A+B)>=A:
  print(x*A+A)
else:
  print(x*A+N-x*(A+B))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    N,A,B = map(int,input().split())
    ans0 = N//(A+B)
    ans1 = A*ans0
    ans2 = (N-(A+B)*ans0)
    if ans2 <= 0:
        ans2 = 0
    if ans2 < A:
        ans1 += ans2
    elif ans2 >= A:
        ans1 += A

    print(ans1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if(A==0 & B==0):
  print("0")

else:
  r=N//(A+B)
  s=N%(A+B)
  if(A<s):
    s=A
  if(A!=0):
    t=(A*r)+s
  else:
    t=0
  print(t)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
div, rest =divmod(n, (a + b))
#div, rest
ans = a * div
if rest >= a:
    ans += a
else:
    ans += rest
print(ans)

Submission status: Accepted

Solution code:
import math
N,A,B = map(int,input().split())
x = A+B
y = N-x*math.floor(N/x)
ans = 0
ans += A*(math.floor(N/x))
if y >= A:
  ans += A
else:
  ans += y
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# B
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)) + a)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A == 0:
  print(0)
  exit()
if B == 0:
  print(N)
  exit()
t = int(N / (A + B))
diff = N - t * (A + B)
if diff > A:
  print(A * t + A)
else:
  print(A * t + diff)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N,A,B = map(int, input().split())
    if A == 0:
        print(0)
        return
    
    count=0

    sho1 = N // (A+B)
    amari1 = N % (A+B)
        
    sho2=amari1 // A
    amari2=amari1 % A
    
    if sho1 ==0:
        if sho2 == 0:
            count += amari2
        
        else:
            count += A
    else:
        count += sho1*A
        
        if sho2 == 0:
            count += amari2
        
        else:
            count += A
            

    print(count)
    
    
main()

Submission status: Accepted

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

cnt_blk = n // (b+r)
res_b = cnt_blk*b
num = cnt_blk*(b+r) + b

if num > n:
  res_b += b - (num - n)
else:
  res_b += b
      
print(res_b)

Submission status: Accepted

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

Submission status: Accepted

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

sum1 = a + b
iter1 = n // sum1
amari = n % sum1
if amari >= a:
	print(iter1 * a + (a))
else:
  print(iter1 * a + (amari))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, a, b = map(int, sys.stdin.readline().split())

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

print(x*a + y)

Submission status: Accepted

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

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

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

ans = 0

if rem >= A:
  ans = A * (cnt + 1)
else:
  ans = A * cnt + rem

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

x = int(N / (A+B))
y = N % (A+B)
z = 0
if y < A:
    z = y
else:
    z = A

blue = 0
if x < 10**100:
    blue = (x * A) + z
else:
    blue = 10*100*A + z
print(blue)

Submission status: Accepted

Solution code:
#B

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

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

Submission status: Accepted

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

M = A+B

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a,b=map(int, input().split()) 
X = n//(a+b)
Y = n%(a+b)
if Y > a:
    print(X*a + a)
else:
    print(X*a + Y)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.readline
T = read()
a, b, c = map(int, T.split())

temp = a // (b+c)
answer = temp * b
temp2 = a % (b+c)

if temp2 >= b:
    answer += b
else:
    answer += temp2

print(answer)

Submission status: Accepted

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

t1 = n // (a+b)
t2 = n % (a+b)

if t2 <= a:
  ans = t1 * a + t2
else:
  ans = t1 * a + a

if n < a + b:
  if n < a:
    ans = n
  else:
    ans = a

if a == 0:
  ans = 0
elif b == 0:
  ans = n
print(ans)

Submission status: Accepted

Solution code:
N, A, B = [int(y) for y in input().split(' ')]
count = N // (A+B)
residue = N % (A+B)
 
if A == 0:
  print(0)
elif residue > A:
  print(count*A + A)
elif residue > 0:
  print(count*A + residue)
else:
  print(count*A)

Submission status: Accepted

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

import sys
AB = A+B
maxnum = pow(10,100)
if A == 0:
    print(0)
    sys.exit()
if N <= A:
    print(N)
    sys.exit()
waru,amari = divmod(N,AB)
#waru = (N // AB)
#amari = N % AB
if amari > A:
    amari = A
answer = waru * A + amari
print(answer)

Submission status: Accepted

Solution code:
def input_int_list():
    return [int(thing) for thing in input().split(" ")]
N,A,B=input_int_list()
r=N//(A+B)
if A==0:
    print(0)
    exit()
    
if N-r*(A+B)<=A:
    ans=N-B*r
else:
    ans=A*(r+1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if a == 0:
  ans = 0
elif b == 0:
  ans = n
else:
  m = n // (a+b)
  r = n % (a+b)
  ans = a * m + min(a,r)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B

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

#処理
C=A+B
D=N//C
E=N-D*C
z=0

z+=A*D

if E>=A:
    z+=A
else:
    z+=E

print(z)

Submission status: Accepted

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

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

if n <= blue:
    print(n)
    exit()

if n <= blue + red:
    print(blue)
    exit()

q = n // (blue + red)
r = n % (blue + red)

cnt = q * blue

while True:
    if r >= blue:
        cnt += blue
        r -= blue
        if r <= red:
            break
        elif r > red:
            r -= red
    else:
        cnt += r
        break

print(cnt)

Submission status: Accepted

Solution code:
import math

N,A,B=map(int,input().split())
total=(10 ** 100) + 1

firstCnt=math.floor(N/(A+B))

for i in range(firstCnt,total):
  if N <= i*A + i*B :
    if N >= i*A + (i-1)*B :
      ans=i*A
      break
    else :
      ans=i*A - (i*A+(i-1)*B - N)
      break
print(ans)

Submission status: Accepted

Solution code:
inputarray = input().split(' ')
N = int(inputarray[0])
A = int(inputarray[1])
B = int(inputarray[2])
blue = 'b'
red = 'r'
amari = N % (A+B)
if A >= amari: 
    countnum = N // (A+B) * A +amari
else:
    countnum = N // (A+B) * A +A
print(countnum)

Submission status: Accepted

Solution code:
N,A,B = (int(x) for x in input().split())
S =  N % (A+B) - A
Acount = N % (A+B)
Ansn = int(N / (A + B)) * A
if S <= 0:
    print(Ansn + Acount)
else:
    print(Ansn + A)