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

def main():

    input = stdin.readline

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

    group_num = N // (A+B)

    amari = N % (A+B)
    amari_red = amari if  A >= amari else A

    # group_num * A
    ans_num = group_num * A + amari_red

    print(ans_num)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = n // (blue + red)
a = n % (blue + red)

ans = 0
if blue > 0:
    if blue > a:
        ans += a
    else:
        ans += blue

print(ans + s * blue)

Submission status: Accepted

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

num = 0
i = 0
i = int(n / (a + b)) + 1
if ((a + b)*i) - n <= b:
    print(a * i)
else:
    num1 = ((a + b)* i) - n
    num2 = a * i
    num3 = num1 - b
    print(num2 - num3)

Submission status: Accepted

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

import math
n = math.ceil(N//(A+B))
mod = N % (A+B)
b = n*A
if mod <= A:
    b += mod
else:
    b += A

print(b)

Submission status: Accepted

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

x = n//(a+b)

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

Submission status: Accepted

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

n, a, b = MAP()

# x = n // (a + b)
# pr/int(x)
x = 0
x = (n // (a + b)) * a
y = 0
if a != 0:
    y = n % (a+b)
    if not 0 <= y <= a:
        y = a

print(x + y)

Submission status: Accepted

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

if a != 0:
    rem = n % (a+b)
    quo = n // (a+b)

    if rem > a:
        rem = a
        
    print(quo*a + rem)
    
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

if rem >= a:
	print(a + x*a)
else:
	print(rem + x*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())

num = n//(a+b)
if (a+b)*num == n:
  print(a*num)
elif (a+b)*num + a <= n:
  print(a*(num+1))
else:
  print(a*num + n - (a+b)*num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def answer(N, A, B):

    if N < A:
        return N
    else:
        T = A + B
        P, Q = divmod(N, T)
        if Q < A:
            return A * P + Q
        else:
            return A * (P + 1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A+B > N:
    if A == 0:
        print(0)
    elif A <= N:
        print(A)
    else:
        print(N)
elif A+B == N:
    print(max(A, 0))
else:
    x, y = divmod(N, A+B)
    if A == 0:
        print(0)
    else:
        if y > A:
            print(x*A+A)
        else:
            print(x*A+y)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
 
sum = b + c
 
#何セットあるか確かめる
set = int(a / sum)
#print(set)
 
#セットの中にある青玉の個数
blue_1 = set * b 
#print(blue_1)
 
#最後のあまりを数える
amari = a % sum
#print(amari)
 
if amari <= b:
  print(blue_1 + amari)
  
else :
  print(blue_1 + b)

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:
"""
B - Count Balls
"""

N, A, B = map(int, input().split(' '))
kat = int(N/(A+B))
kalan = N%(A+B)

a = A*kat
if kalan > A:
    a += A
else:
    a += kalan

print(a)

Submission status: Accepted

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

# 処理

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

print(result)

Submission status: Accepted

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

if A == 0:
    print(0)
# elif N <= A:
#     print(N)
# elif N < (A+B):
#     print(A)
elif N < (A+B):
    print(min(A,N))
else:
    div = int(N/(A+B))
    quob = min(N%(A+B),A)
    ans = div*A+quob
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, A, B = map(int, input().split())

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

s = A + B

a = N // s

ans = A*a
nokori = N-s*a

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

p,q = divmod(n, c)

print(p * a + min(q, a))

Submission status: Accepted

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

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

if A == 0:
    print(0)
elif B == 0:
    print(N)
elif A + B == N:
    print(A)
elif A + B > N and N >= A:
    print(A)
elif A + B > N and N < A:
    print(N)
# 8 10 4
# bbbbbbbb bbrrrr
else:
    r = int(N / (A+B))
    q = N % (A+B)
    if (q <= A):
        print(r * A + q)
    else:
        print(r * A + A)

# 8 1 4
# brrrrbrr rr

# -----
# 8 4 2
# bbbbrrbb bb

# 13 4 2
# bbbb rr bbbb rr b

# 2 4 2
# bb

# r = N / (A+B)
# q = N % (A+B)
# r * A + q

Submission status: Accepted

Solution code:
n,a,b  =map(int,input().split())
se = a+b
br = 0
cnt = 0
if a == 0:
    print(0)
elif b == 0:
    print(n)
else:
    cnt = n//se
    if cnt == 0:
        if n < a:
            print(n)
        else:
            print(a)
    else:
        res = a*cnt
        n -= se*cnt
        if n <= a:
            res += n
        else:
            res += a
        print(res)

Submission status: Accepted

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

q=n//(a+b)
r=n-q*(a+b)
if r>=a:
  print(a*(q+1))
else:
  print(a*q+r)

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())
k=N//(A+B)

if (A+B)*k==N:
  print(A*k)
else:
  if N-k*(A+B)>A:
    print(k*A+A)
  else:
    print(k*A+N-k*(A+B))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# N, A, B = [6, 2, 4]
# N, A, B = [8, 0, 4]
# N, A, B = [8, 3, 4]

S = A + B
quot, remainder = divmod(N, S)

blue_balls = A
if remainder < A:
    blue_balls = remainder

blue_balls += quot * A
print(blue_balls)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

answer = A * q + min(A, r)
print(answer)

Submission status: Accepted

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


if a == 0:
    print(0)
else:
    count = (int)(n / (a + b))
    amari = (int)(n % (a + b))

    if amari > a:
        amari = a
    print(count * a + amari)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

C = A + B

m = N % C
n = N // C

if m == 0:
    print(A*n)
else:
    if m >= A:
        print(A*(n+1))
    else:
        print(A*n + m)

Submission status: Accepted

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

if J > A:
    print((K+1)*A)
else:
    print((K*A)+J)

Submission status: Accepted

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

W = A + B
AB = N // W

exp = N - AB * W
if exp < A:
  ans = exp
else:
  ans = A
ans += AB * A
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0

num_rb = n//(a+b)

if num_rb == 0:
    if n >= a:
        print(a)
        exit(0)
    else:
        print(n)
        exit(0)

ans += (num_rb)*a
ans += min(a, n - num_rb*(a+b))

print(ans)

Submission status: Accepted

Solution code:
N,A,B = map(int, input().split())
adds = A + B
times = N // adds
boalsLen = adds * times
count = A * times


while True:
    if boalsLen > N:
        break
    
    tmpBoalsLen = boalsLen + A
    if tmpBoalsLen > N:
        addBoals = N - boalsLen
        count += addBoals
        break
    
    boalsLen = tmpBoalsLen
    boalsLen += B
    count += A

print(count)

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
d=0
e=0
ok=False

total=int(a/(b+c))
sa=a-(b+c)*total
if total==0:
    if a>=b:
        print(b)
    else:
        print(a)
else:
    if sa>=b:
        print(b+b*total)
    else:
        print(sa+b*total)

Submission status: Accepted

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

if amari < a:
    print((syo*a)+amari)
else:
    print((syo*a)+a)

Submission status: Accepted

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

Submission status: Accepted

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

print(b1 + b2)

Submission status: Accepted

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

import math

s = input()
num = s.split(" ")
N = int(num[0])
A = int(num[1])
B = int(num[2])

X = math.floor(N/(A+B))
resid = N-(A+B)*X

if A>=resid:
  add_val = resid
else:
  add_val = A

print(A*X + add_val)

Submission status: Accepted

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

Submission status: Accepted

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

ans = (N // element) * A 
hanpa = N % element
if  hanpa <= A :
  ans += hanpa
else :
  ans += A

print(ans)

Submission status: Accepted

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

C=A+B
d=N//C
N -= C*d

b=0
r=0
while N>0:
    N-=A
    b+=A
    if N<=0:
        b+=N
        break

    N-=B
    r+=B
    if N<=0:
        break

print(b+d*A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cmin = lambda a,b : a if a<b else b
cmax = lambda a,b : a if a>b else b
iin = lambda : int(input())
lin = lambda : list(map(int,input().split()))
rin = lambda n : [int(input()) for _ in range(n)]

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

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

print(d*a+m if m<a else d*a+a)

Submission status: Accepted

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

print(amari + A * o)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = a + b
dev = n//sum

ans = 0
if a == 0:
    print(0)
else:
    if dev == 0:
        if n > a:
            print(a)
        else:
            print(n)
    else:
        ans = n - sum * dev 
        if ans < a:
            print(dev * a + ans)
        else:
            print(dev * a + a)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

N, A, B = [int(x) for x in input().split()]
times = N // (A + B)
mod = N % (A + B)

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

Submission status: Accepted

Solution code:
N , A , B = (map(int , input().split()))
def divmod_(a ,b):
    q, mod = divmod(a ,b)
    return q, mod
c , d = divmod_(N ,A+B)
if (d - A) > 0:
    d = A
print((c * A) + d)

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-1):
    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())
 
a = N // (A+B)
b = N % (A+B)

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

Submission status: Accepted

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

j=i[1]+i[2]
k,mod=divmod(i[0],j)

if i[1]<mod:
	l=(k+1)*i[1]
else:
	l=k*i[1]+mod
print(l)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N-cnt*(A+B)>A:
    print(res+A)
else:
    print(res+N-cnt*(A+B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N, A, B = list(map(int, input().split()))
print(math.floor(N / (A+B)) * A + min(N % (A+B), A))

Submission status: Accepted

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

c=(A+B)*(N//(A+B))
s=A*(N//(A+B))

if c+A<=N:
    print(s+A)
else:
    print(s+N-c)

Submission status: Accepted

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

Submission status: Accepted

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

s = n // (a + b)
amari = n - s * (a + b)

amarib = min(amari, a)
print(s * a + amarib)

Submission status: Accepted

Solution code:
N, blue, red = map(int, input().split())
repeat = N // (blue+red)
partial = N % (blue+red)

ans = repeat * blue
if partial > blue:
    ans += blue
else:
    ans += partial
print(ans)

Submission status: Accepted

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

if b>=A:
  print(a*A+A)
else:
  print(a*A +b)

Submission status: Accepted

Solution code:
import math

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

allcount = math.floor(n/(a+b))
if a < n - allcount * (a+b):
    nokori = a
else:
    nokori = n - allcount * (a+b)
ans = allcount * a + nokori
print(ans)

"""
ans = 0
count = 0
while(n>0 and count<=10000):
    n -= a
    if n >= 0:
        ans += a
    else:
        ans += a + n
    n -= b
    count += 1
print(ans)
"""

Submission status: Accepted

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

loop, m = divmod(N, A + B)
print(loop * A + (m if m < A else A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=[int(x) for x in input().rstrip().split()]
 
ans=N//(A+B)
amari=N%(A+B)
if A<=amari:
    amari=A
ans1=ans*A+amari
print(ans1)

Submission status: Accepted

Solution code:
import math

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

set_count = math.floor(n / one_set)

def get_blue_count():
  last_balls = n - one_set * set_count
  if last_balls >= a:
    return a
  else:
    return last_balls

print(a * set_count + get_blue_count())

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

# 青がa,赤がb

# n番目の数は赤or青

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

Submission status: Accepted

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

import sys

DEBUG = False

def solve():
    return


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

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

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n, blue, red = read_int_list()
    ans = 0
    nr_cycle = n // (blue + red)
    ans += nr_cycle * blue
    n = n % (blue + red)
    if blue < n:
        ans += blue
    else:
        ans += n
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

time = int(N / (A + B))

if time == 0 or (time == 1 and N / (A + B) == 1):
  if N - A <= 0:
    print(N)
  else:
    print(A)
else:
  N -= (A + B) * time
  if N - A <= 0:
    print(N + A*time)
  else:
    print(A + A*time)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 0
if A == 0:
    print(0)
    exit()
if B == 0:
    print(N)
    exit()

x = N // (A+B)
y = N % (A+B)
c = x * A
if A <= y:
    c += A
else:
    c += y

print(c)

Submission status: Accepted

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



if b > A:
    print( a * A + A )
else:
    print( a * A + b )

Submission status: Accepted

Solution code:
inp = input().split(" ")
N, A, B = (int(inp[0]), int(inp[1]), int(inp[2]))
if int(N % (A + B)) <= A:
    print(int(N / (A + B)) * A + int(N % (A + B)))
else:
    print(int(N / (A + B)) * A + A)

Submission status: Accepted

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

sum = A + B
result1 = N // sum

result2 = N % sum

if result2 > A:
    result2 = A

result = result1 * A + result2
print(result)

Submission status: Accepted

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

#１セットで増える数
c=a+b


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if mod_num >= a:
  ans += a
else:
  ans += mod_num
  
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

    tmp = n // (a + b)

    if n - tmp * (a + b) > a:
        print(tmp * a + a)
    else:
        print(tmp * a + n - tmp * (a + b))

    # TLE
    # while n >= leng:
    #     if a < (n - leng):
    #         ans += a
    #         leng += (a + b)
    #     else:
    #         ans += n - leng
    #         leng += (a + b)

    # if a >= n:
    #     print(n)
    # else:
    #     print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
ans = N // (A + B) * A
r = N % (A + B)
ans += min(r, 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(a*(x+1))
else:
    print(x*a+y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,A,B = list(map(lambda x:int(x),input().split(" ")))
x = n%(A+B)
r = min(x,A)
ans = n//(A+B)*A+r
print(int(ans))

Submission status: Accepted

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

C = A+B

amari = N % C

if amari <= A:
    print((N // C)*A + amari)
else:
    print((N // C)*A + A)

Submission status: Accepted

Solution code:
def main():
    n,a,b = map(int, input().split())
    if a == 0:
        print(0)
        exit()
    elif b == 0:
        print(n)
        exit()
    c = a + b
    d,e = divmod(n,c)
    f,g = divmod(e,a)
    if f == 0:
        print(a * d + g)
    else:
        print(a * d + a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

box = n // (blue + red)       #variable box indicates how much sets of a line can get into n
mod = n % (blue + red)

#最後に青の残り(r_blue)がどれだけあるか
if mod <= blue:    #余りが全部青
    r_blue = mod
else:              #余りが一部赤
    r_blue = blue

print(box * blue + r_blue)

Submission status: Accepted

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

div = N // (A+B)

ans = A*div

diff = N - ((A+B)*div)

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

print(ans)

Submission status: Accepted

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

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

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

d = min(a, n % (a+b))

print(c + d)

Submission status: Accepted

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

M = N // (A + B)
x = M * A + min(N - M * (A + B), A)

print(x)

Submission status: Accepted

Solution code:
import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\158\\B'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        q = [int(i) for i in self.input_data().split()]
        N = q[0]
        A = q[1]
        B = q[2]

        shou = int(N / (A + B))
        amari = N % (A + B)

        if amari <= A:
            result = shou * A + amari
        else:
            result = (shou+1) * A


        print(str(result))


solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

syou = n // (a+b)
amari = n % (a+b)

if amari <= a:
    print(syou*a + amari)
else:
    print(syou*a + a)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)