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

Submission status: Accepted

Solution code:
# B Count Balls

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

set, mod = divmod(N, (A + B))
ans = set * A

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if a==0:
    print(0)
    
elif b==0:
    print(n)
    
else:
    
    quo=n//(a+b)
    
    #商
    if n%(a+b)==0:
        rem=0
    elif  1<=n%(a+b)<=a:
        rem=n%(a+b)
    else:
        rem=a
        
    print(quo*a+rem)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


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


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(f'{solve(N, A, B)}')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if A == 0:
    print(0)
else:
    i = N // (A + B)
    j = N % (A + B)
    if j >= A:
        count = A * (i + 1)
        print(count)
    else:
        count = A * i + j
        print(count)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n, a, b = inpl()
l = n // (a + b)
m = n % (a + b)
print(a * l + min(m, a))

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Accepted

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

# Aが青で,Bが赤
C =A*(N//(A+B))
if N%(A+B) <A:
    D = N%(A+B)
else:
    D = A
print(C+D)

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

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

print(ans)

Submission status: Accepted

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

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


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

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

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

print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# abc158_b.py
# https://atcoder.jp/contests/abc158/tasks/abc158_b

# B - Count Balls /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高橋君は青と赤の 2色のボールを持っており、これらを一列に並べようとしています。
# 初め、列にボールはありません。
# 根気のある高橋君は、次の操作を 10100回繰り返します。
#     列の末尾に、A個の青いボールを加える。その後、列の末尾に B個の赤いボールを加える。
# こうしてできる列の先頭から N個のボールのうち、青いボールの個数はいくつでしょうか。

# 制約
#     1≤N≤1018
#     A,B≥0
#     0<A+B≤1018
#     入力は全て整数である

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N A B

# 出力
# 列の先頭から N個のボールのうち、青いボールの個数を出力せよ。

# 入力例 1
# 8 3 4

# 出力例 1
# 4

# 青いボールをb、赤いボールを rで表すと、列の先頭から 8個のボールは bbbrrrrb であるので、このうち青いボールは 4個です。

# 入力例 2
# 8 0 4

# 出力例 2
# 0

# そもそも赤いボールしか並んでいません。

# 入力例 3
# 6 2 4

# 出力例 3
# 2

# bbrrrr のうち青いボールは 2個です。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, A, B = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

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

    result = q*A + min(mod, A)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['8 3 4']
        lines_export = [4]
    if pattern == 2:
        lines_input = ['8 0 4']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['6 2 4']
        lines_export = [2]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

d, m = divmod(n, a + b)

ans = d * a + min(m, a)

print(ans)

Submission status: Accepted

Solution code:
# ABC158 B - Count Balls

M,A,B = map(int,input().split())
import math
C = math.floor(M/(A+B))
N = M%(A+B)
E = C*A

if N >= A:
    E+=A
else:
    E+=N
print(E)

Submission status: Accepted

Solution code:
# ABC158 B - Count Balls

M,A,B = map(int,input().split())
import math
C = math.floor(M/(A+B))
N = M%(A+B)
E = C*A
A_A = 0
B_B = 0
for i in range(N):
    if N >= A:
        A_A +=A
        N -=A
    else:
        A_A +=N
        break
    if N >= B:
        B_B +=B
        N -=B
    else:
        B_B +=N
        break
print(A_A+E)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
#Aが青
#Bが赤
i = N // (A+B)
b = i*A
t = N % (A+B)
if t > A:
   t = A
print(b+t)

Submission status: Accepted

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

i = N // (A+B)
b = i*A
t = N % (A+B)

if t > A:
  t = A
  
print(b+t)

Submission status: Accepted

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

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

y = N % (A+B)
if y >= A:
  y = A

print(x + y)

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())
tot = a + b
div, mod = divmod(n, tot)
if mod >= a:
    print(a * div + a)
else:
    print(a * div + mod)

Submission status: Accepted

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

if not ( 1 <= N <= 10**18 and 0 <= A and 0 <= B and 0 < A + B <= 10**18 ): sys.exit()
if not ( isinstance(N,int) and isinstance(A,int) and isinstance(B,int) ): sys.exit()

count = N // (A+B)
remind = N % (A+B) if N % (A+B) <= A else A
    
print(count * A + remind)

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    n, a, b = map(int, input().split())
    if a + b == 0:
        print(0)
    else:
        q, mod = divmod(n, a + b)
        print(q * a + min(mod, a))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

n%=a+b

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

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:
"""
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...

N = 8
[青青青赤赤赤赤青]

return 青 = 4
"""

def count_balls():
    # 入力
    N, A, B = map(int, input().split())
    # [青青青赤赤赤赤]の個数と余り
    comb_count = N // (A + B)
    remainder = N % (A + B)
    # 集計
    if remainder <= A:
        return A * comb_count + remainder
    else:
        return A * comb_count + A

result = count_balls()
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(N*a+min(m,a))

Submission status: Accepted

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

q, r = divmod(N, A + B)
ans = 0
ans += q * A
ans += min(r, A)

print(ans)

Submission status: Accepted

Solution code:
import sys
n,a,b = map(int,input().split())
if a == 0:
    print(0)
    sys.exit()

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

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

try:
    blue_num = A * (N // (A + B))
    residue = N - ((A + B) * (N // (A + B)))
    if(residue > A):
        blue_num += A
    else:
        blue_num += residue
except ZeroDivisionError:
    blue_num = 0

print(blue_num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    N,A,B = MI()
    oneset = A + B

    rep = N // oneset

    print(rep * A + min(N % oneset,A))


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
# A: blue, B: red
N, A, B = map(int, input().split())
# N, A, B = 8,0,4
#print(N)

q, mod = divmod(N, A+B)
if mod < A:
    extra = mod
else:
    extra = A
result = q * A + extra

print(result)

Submission status: Accepted

Solution code:
n,a,b = list(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())
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 B==0:
    print(N)
elif 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,a,b = map(int,input().split())
'''
bbbbrrbbbbrr...
n // (a+b) : a+b個の塊がn個のなかにいくつ入っているか
n % (a+b)  : a+b個の列のうち、いくつまで入るか
'''

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

Submission status: Accepted

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

num = A if (N%(A+B)) > A else N%(A+B)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,a,b=map(int,input().split())
val = n//(a+b)
pos = n%(a+b)
if pos>a:
    pos = a
print(val*a + pos)

Submission status: Accepted

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

total = b + r
num = n // total
rest = n - (num * total)

if rest <= b:
  print(num * b + rest)
else:
  print(num * b + b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

p = N // (A+B)
q = N % (A+B)
if q > A:
    r = A
else:
    r = q
print(A * p + r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans= 0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, A, B = map(int, input().split())
    ans = 0
    ans += (N // (A + B)) * A
    ans += min([N % (A + B), A])
    print(ans)


if __name__ == '__main__':
    main()

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
x = N % (A+B)

if x < A:
  print(ans+x)
elif x >= A:
  print(ans+A)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#26
N,A,B = map(int,input().split())
num = int(N/(A+B))
blue = 0

blue = num*A
if (N-num*(A+B)) <= A:
    blue += (N-num*(A+B))
else:
    blue += A

print(blue)

Submission status: Accepted

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

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

if q - a >= 0:
    ans += a
if q - a < 0:
    ans = ans + a +(q-a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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())
c = a + b

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

print(ans)

Submission status: Accepted

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

set_num = n // (a + b)
remain_num = n - (a + b) * set_num

print(set_num * a + min(remain_num, a))

Submission status: Accepted

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

    if a + b == 0:
        print(0)
    else:
        c, r = n // (a + b), n % (a + b)
        nblue = c * a + min(a, r)
        print(nblue)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num1 = n%(a+b)
num2 = n//(a+b)

print(num2*a+min(num1,a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
n, a, b = map(int, input().split())

c = a + b
d = n % c
e = n // c

if d <= a:
    print(e * a + d)
else:
    print((e + 1) * 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())

d = a+b
c = n%d
e = n//d

if c <= a:
    print(e*a+c)
if c > a:
    print((e+1)*a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n,a,b = [int(x) for x in stdin.readline().strip().split()]
print(int(n/(a+b))*a+min(n%(a+b), a))

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
#n blue red
#8 3 4
#bbbrrrrb
#4
ans = 0
x = N // (A+B)
ans += (x * A)
N -= x * (A+B)
if N <= A:
  ans += N
else:
  ans += A
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
#N 13 8
ball=A+B #3+4=7 BBBRRRR
s=N//ball #1
y=N%ball #6 #1
if y<A:
  print(s*A+y)
else:
  print(s*A+A)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

t = n // (a + b)
u = n - (a + b) * t
if a < u:
    u = a
print(t * a + u)

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())
rem=n%(a+b)
#割った商
quot=n//(a+b)
ans = a*quot + rem if rem < a else a*quot + a
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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 = list(map(int, input().split()))
p = N // (A + B)
q = N % (A + B)
print(p * A + min(A, q))

Submission status: Accepted

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

S = A+B

x = N//S
y = N%S

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

Submission status: Accepted

Solution code:
N, A, B = (int(x) for x in input().split())
div=int(N/(A+B))
amari=N%(A+B)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N, A, B = [int(_) for _ in input().split()]
q, r = divmod(N, A + B)
print(A * q + min(r, A))

Submission status: Accepted

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

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

if x == 0:
    print(min(a, n))
else:
    print(a * x + min(mod, a))

Submission status: Accepted

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

Submission status: Accepted

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

loop = N//(A+B)

remain = min(N - loop*(A+B),A)

print(loop*A+remain)

Submission status: Accepted

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

loop = N//(A+B)

remain = N - loop*(A+B)

if remain <= A:
    remain = remain
else:
    remain = A

print(loop*A+remain)

Submission status: Accepted

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

if n % c != 0:
    m = n % c
    if a <= m:
        print(z * a + a)
    else:
        print(z * a + m)
else:
    print(z * 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())

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())
 
if a != 0:
  answer = n // (a+b)
  remainder = n % (a+b)
  print((answer*a) + min(a, remainder))
else:
  print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

turn = A + B
result = (N // turn * A) + min(N % turn, A)

print(result)

Submission status: Accepted

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

count=0
m=n//(a+b)
l=n%(a+b)

if l==0:
    print(m*a)
elif l>a:
    print(m*a+a)
else:
    print(m*a+l%a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
num=a+b
ans,plus=divmod(n,num)
ans*=a
ans+=min(plus,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())

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

Submission status: Accepted

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

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

if ama > a:
  ao=sho*a+a
else:
  ao=sho*a+ama
print(ao)

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+a)
else : 
  print(c+d)

Submission status: Accepted

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

Submission status: Accepted

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

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

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 = a*(n//(a+b)) + min(a, n%(a+b))
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, open(0).read().split())

d, m = divmod(n, a+b)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if amari<=a:
    ans+=amari

elif amari>a:
    ans+=a

print(ans)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
m = int(N/(A+B))
n = N - m*(A+B)
if n > A:
  n = A
num = m * A + n
print(num)

Submission status: Accepted

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

if A == 0:
    print(0)
elif A+B >= N:
    print(min(A,N))
else:
    cnt = A * (N // (A+B))
    N -= (A+B) * (N // (A+B))
    cnt += min(A,N)
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

count = int(N / (A + B))
blue_balls = count * A

if N % (A + B) != 0:
    if N % (A + B) > A:
        blue_balls += A
    else:
        blue_balls += N % (A + B)

print(blue_balls)

Submission status: Accepted

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

x = n//(b+r)
x1 = n%(b+r)

if b >= x1:
  b_count = x1
else:
  b_count = b

print(x*b + b_count)

Submission status: Accepted

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

x = n//(b+r)
x1 = n%(b+r)

if b >= x1:
  b_count = x1
else:
  b_count = b

print(x*b + b_count)

Submission status: Accepted

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

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

def ans():
  if b<=A:
    return a+b
  else:
    return a+A

print(ans())

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().split()]
d, m = divmod(N, (A + B))
print(d * A + min(m, A))