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: Time Limit Exceeded

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

x = []
z = n // (a+b) + 1
for i in range(z):
    for j in range(a):
        x.append(0)
    for j in range(b):
        x.append(1)

count = 0
for i in range(n):
    if x[i] == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

is_blue = True

while True:
    if is_blue:
        if count_all + A > N:
            count_blue += A - ((count_all + A) - N)
            break

        count_all += A
        count_blue += A
        is_blue = not is_blue
    else:
        if count_all + B > N:
            break
        count_all += B
        is_blue = not is_blue

print(count_blue)

Submission status: Time Limit Exceeded

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

blue_count = 0
while n != 0:
    # 青
    if n > a:
        n -= a
        blue_count += a
    else:
        blue_count += n
        n = 0
    if n > b:
        n -= b
    else:
        n = 0

print(blue_count)

Submission status: Time Limit Exceeded

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

while 1:
    if n>a:
        n-=a
        an+=a
    else:
        print(an+n)
        exit()
    
    if n>b:
        n-=b
    else:
        print(an)
        exit()

Submission status: Time Limit Exceeded

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

    MAX_COUNT = 10**(100)
    ao_count = 0

    for i in range(MAX_COUNT):
        if A <= N:
            ao_count += A
            N -= A
        else:
            ao_count += N
            print(ao_count)
            return

        if B <= N:
            N -= B
        else:
            print(ao_count)
            return



if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
while count < 10**100:
    n -= a
    tmp += a
    if n <= 0:
        print(tmp + n)
        break
    n -= b
    if n <= 0:
        print(tmp)
        break

Submission status: Time Limit Exceeded

Solution code:
def resolve():

    n,a,b =map(int, input().split())
    lis = []
    while True:
        for i in range(a):
            lis.append("b")
        for j in range(b):
            lis.append("r")
        if len(lis)>= n:
            break
    print(lis[0:n].count("b"))
    
    
    
if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

blue_count = 0
while n != 0:
    # 青
    if n >= a:
        n -= a
        blue_count += a
    else:
        blue_count += n
        n = 0
    if n >= b:
        n -= b
    else:
        n = 0

print(blue_count)

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

v=n//(a+b)
ans=v*a
mod=n%(a+b)

for i in range(min(mod,a)):
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

acnt = 0
bcnt = 0
while True:
    acnt += a
    if acnt + bcnt >= n:
        acnt -= (acnt + bcnt) - n
        break
    bcnt += b
    if acnt + bcnt >= n:
        break
print(acnt)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
total_count, blue_count, color = 0, 0, 0
while True:
    if color == 0:
        total_count += a
        blue_count += a
    else:
        total_count += b
    if total_count >= n:
        break
    color = (color + 1) % 2

if total_count > n and color == 0:
    blue_count -= total_count - n
print(blue_count)

Submission status: Time Limit Exceeded

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
    tmp = 0
    while True:
        for a in range(A):
            if(tmp == N):
                break
            ret += 1
            tmp += 1

        for b in range(B):
            if(tmp == N):
                break
            tmp += 1

        if (tmp == N):
            break


    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
aa=n//(a+b)
ss=n%(a+b)
ans=0
for i in range(aa):
    ans+=a
if ss>a:
    ans+=a
else:
    ans+=ss

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, A, B = MAP()

blues = 0
while N > 0:
    if N - A < 0:
        A = N
    N -= A
    blues += A

    N -= B

print(blues)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = (int(x) for x in input().split())
c = 0
b_flg = True
while True:
  if n <= 0:
    break
  if b_flg:
    n -= a
    c += a
    if n <= 0:
      c += n
    b_flg = False
  else:
    n -= b
    b_flg = True
print(c)

Submission status: Time Limit Exceeded

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

count = 0
ret = 0
while(count < n):
    if count + a >= n:
        ret += n - count
        break
    if count + a + b >= n:
        ret += a
        break
    count += a + b
    ret += a
print(ret)

Submission status: Time Limit Exceeded

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

aa = a
bb = b
nn = n

balls = ''

while n > 0:
    while aa > 0:
        balls += 'b'
        aa -= 1
    while bb > 0:
        balls += 'r'
        bb -= 1
    n -= 1
    aa = a
    bb = b

ans_balls = balls[:nn]

ans = ans_balls.count('b')

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ans = 0
while N >= 0:
    ans += min(A,N)
    N -= (A+B)
print(ans)

Submission status: Time Limit Exceeded

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

boals = ''

while len(boals) < N:
    for i in range(A):
        boals += 'b'
    
    for i in range(B):
        boals += 'r'

print(boals[:N].count('b'))

Submission status: Time Limit Exceeded

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

ans = 0
while True:
    if n >= a:
        n -= a
        ans += a
    else:
        ans += n
        break

    if n >= b:
        n -= b
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n, a, b = tuple([int(s) for s in input().split()])
    res = 0

    while n > 0:
        res += min([a, n])
        n -= a
        n -= b

    print(res)

Submission status: Time Limit Exceeded

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

x = []
for i in range(n):
    for j in range(a):
        x.append(0)
    for j in range(b):
        x.append(1)

count = 0
for i in range(n):
    if x[i] == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

all_count = 0
blue_count = 0

while all_count < N:
    if all_count + A >= N:
        blue_count += N - all_count
        break
    all_count += A
    all_count += B
    blue_count += A

print(blue_count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
cnt = 0
ans = 0
while cnt <= n:
  ans+=a
  cnt+=a+b
cnt -= a+b
ans-=a
nokori = n - cnt
if nokori >= a:
  ans+=a
else:
  ans+=nokori
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ans = 0
while True:
  if N >= A:
    ans += A
    N -= A + B
  else:
    ans += max(N, 0)
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
ans=0
end=True
while end:
    if n>=a:
        n-=a
        ans+=a
        if n>b:n-=b
        else:end=False
    else:
        ans+=n
        end=False
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,a,b = map(int, input().split())
    q = deque()

    while len(q) < n:
        for i in range(a):
            q.append('Blue')
        for i in range(b):
            q.append('Red')
    
    blue = 0
    for i in range(n):
        if q[i] == 'Blue':
            blue += 1
    print(blue)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
# 先頭からN個のボール, 列の末尾にA個の青ボール追加, B個の赤ボール追加

count = N // (A + B)
total = A * count + min(N - (A + B) * count, A)
print(total)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, a, b = map(int, input().split())
    quo = n // (a+b)
    rem = n % (a+b)
    ans = quo * a
    if a >= rem:
        ans += rem
    else:
        ans += a
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

m = n // (b+r)

last = min(n-(b+r)*m, b)

print(b*m + last)

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:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n,a,b=sep()
k=n//(a+b)
ans=(k*a)
k2=n%(a+b)
if k2<=a:
    ans+=k2
else:
    ans+=a
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    c = A + B
    d = N // c
    ans = d * A
    e = N % c
    if e >= A:
        ans += A
    else:
        ans += e
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    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
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = k*b+min(p,b)
print(ans)

Submission status: Accepted

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

div, mod = divmod(n, a + b)
ans = div * a + min(mod, 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:
    res = a
else:
    res = r

print(q * a + res)

Submission status: Accepted

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

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 = input()
n = n.split()
a = int(n[1])
b = int(n[2])
n = int(n[0])
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(' '))
q, r = divmod(n, a + b)

s = q * a

if r > a:
    s += a
else:
    s += r

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = a + b
div = n // c
mod = n % c

if mod > a:
    mod = a

ans = div * a + mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split())
ans = 0
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())
line = n // (a + b)
remain = n % (a + b)

ans = line * a
ans += min(a, remain)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

    if (rem > A): rem = A
    ans = quo * A + rem

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
sho,amri = divmod(N,(A+B))
if amri > A:
    amri = A
print(A*sho+amri)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

r=N//(A+B)*A
s=N%(A+B)

x=r+min(A,s)
print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
#print (N//(A+B))


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n,a,b = map(int,input().split())
    a_count=0
    d,r=divmod(n,a+b)
    a_count+=a*d
    if r > a:
        a_count+=a
    else:
        a_count+=r
    print(a_count)

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 27
N, A, B = map(int, input().split(' '))
 
ans = 0
if (A + B) != 0:
    taple = divmod(N, A + B)
    ans = taple[0] * A
    if B == 0: ans = N
    elif taple[1] > A: ans += A
    else: ans += taple[1]
 
print(ans)

Submission status: Accepted

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

ans = 0
if A + B > 0:
    taple = divmod(N, A + B)
    ans = taple[0] * A + min(A, taple[1])

print(ans)

Submission status: Accepted

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

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

print(ans)

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

if a+b ==0:
    print(0)
else:
    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:
import sys
import copy
import math
import itertools

a = [int(c) for c in input().split()]
N=a[0]
A=a[1]
B=a[2]

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

cnt += int(N/(A+B))*A
print(cnt)

Submission status: Accepted

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

if a+b == 0:
  print(0)
  
else:  

  d = n//(a+b)
  q = n % (a+b)

  
  if q <= a:
    print(a*d+q)
  else:
    print(a*d+a)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

whole = n // (a + b)
rest = n % (a + b)

blue = whole * a

if rest <= a:
	blue += rest
else:
	blue += a
	
print(blue)

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

kumi = n // (a + b)

kumi_ao = kumi * a

nokori = n % (a+b)

if nokori <= a:
  nokori_ao = nokori
  
else:
  nokori_ao = a
  
print(kumi_ao+nokori_ao)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = [int(x) for x in input().split()]
n = N//(A+B)
ans = n * A
d = N - n*(A+B)
if d >= A:
  ans += A
else:
  ans += d
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import math
# import statistics
# a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
e1,e2,e3 = map(int,input().split())
# f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
# h = []
# for i in range(e1):
#     h.append(list(map(int,input().split())))

ba1=e1//(e2+e3)
ba2=e1-ba1*(e2+e3)
if ba2<=e2:
    print(ba2+ba1*e2)
elif ba2>e2:
    print(e2+ba1*e2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,A,B = map(int, input().split())
# 11 3 3 
# bbbrrr bbbrr
blue = N//(A+B)*A + min(N%(A+B),A)
print(blue)

Submission status: Accepted

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

Submission status: Accepted

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

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())
count = 0

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

print(count)

Submission status: Accepted

Solution code:
n,A,B=map(int,input().split())
z=A+B
if n%z<=A:
    print(int(n/z)*A+n%z)
elif A<=n%z<=z:
    print(int(n/z)*A+A)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
n,blue,red = [int(x) for x in input().split()]
p = n // (blue + red)
r = n % (blue + red)
if r > blue:
  c = blue
else:
  c = r
print(p * blue + c)

Submission status: Accepted

Solution code:

def main():
    n, a, b = map(int, input().split(" "))
    one_round = a+b
    x = n // one_round
    n = n % one_round
    ans = x * a
    ans += min(n,a)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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


def main():

    v = list(map(int, input().split()))
    n = v[0]
    a = v[1]
    b = v[2]

    answer = 0
    if n < a:
        answer = n
    elif n < a+b:
        answer = a
    elif a == 0 and b == 0:
        answer = 0
    else:
        answer += math.floor(n / (a+b)) * a
        rest = n % (a+b)
        if rest <= a:
            answer += rest
        else:
            answer += a
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
import math

count = 0
num, blue_num, red_num = map(int, input().split())
all_ball = blue_num + red_num
count = num // all_ball
rest = num % all_ball
print(count * blue_num + min(rest, blue_num))

Submission status: Accepted

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

n, m = divmod(n, a+b)
print(n*a + min(a, m))

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

Submission status: Accepted

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

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

if c<a:
  print(d*a+c)
else:
  print((d+1)*a)

Submission status: Accepted

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

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

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

print(ans)

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+1)*a)
 
else:
  print(x*a+y)

Submission status: Accepted

Solution code:
import math

N, A, B = map(int, input().split())
K = math.floor(N // (A + B))
blue = A * K
L = N % (A + B)
if L > A:
  blue += A
else:
  blue += L
print(blue)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ri = lambda S: [int(v) for v in S.split()]
N, A, B = ri(input())

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

blue = (A * q) + r if r <= A else (A * q) + A
print(blue)

Submission status: Accepted

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

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

if x >= 1:
    print(x*a+y)
else:
    print(min(n, a))

Submission status: Accepted

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

print(q+t)

Submission status: Accepted

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

Submission status: Accepted

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

if A==B==0:
  print(0)
else:
  r = N%(A+B)
  q = N//(A+B)
  if r<=A:
    print(q*A + r)
  else:
    print((q+1)*A)

Submission status: Accepted

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

cnt_A = i * A

if N < A:
  cnt_A += N
else:
  cnt_A += A
  
print(cnt_A)

Submission status: Accepted

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

d = N//(A+B)
z = N%(A+B)

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

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:
        blue = A * (N // (A+B)) + A
    else:
        blue = A * (N // (A+B)) + N%(A+B)
    print(blue)
elif N < A+B:
    if N < A:
        print(N)
    else:
        print(A)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N, A, B = MI()
    print((N // (A + B)) * A + min(N % (A + B), A))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

quotient += min((remainder, A))

print(quotient)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
ans=0
m=n//(a+b)
l=n%(a+b)
ans+=m*a
if l<=a:
  print(ans+l)
else:
  print(ans+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())
 
L = []
i = 0
k = 0
j = 0
P = N // (A + B)
Q = N % (A + B)

if A > Q:
    print((P * A) + Q)
else:
    print((P * A) + A)

Submission status: Accepted

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

quotient=N//(A+B)
remainder=N%(A+B)
quo_bball=quotient*A
if remainder <=A:
    rem_bball=remainder
else:
    rem_bball=A
print(quo_bball+rem_bball)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
 
# 完全に含まれる操作の回数はfloor(N/(A+B))
ans = (N // (A+B)) * A
res = N % (A+B)
# 不完全な操作は高々1回
# A>resなら、青色はres個で、res>=Aなら、青色はA個
ans += min(res, A)
 
print(ans)

Submission status: Accepted

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

# 完全に含まれる操作の回数はceil(N/(A+B))
ans = (N // (A+B)) * A
# 不完全な操作は高々1回
# A>N%(A+B)なら、青色はN%(A+B)個で、N%(A+B)>=Aなら、青色はA個
ans += 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())
 
s = A + B
ans = (N // s)*A
if (N % s) < A: print(ans + N % s)
else: print(ans + A)