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())
answer=0
if a==0:
    answer=0
elif b==0:
    answer=n
elif a==1 and b==1:
    answer=n//2
else:
    while n>a+b:
        answer+=n//(a+b)*a
        n-=n//(a+b)*(a+b)
    if n>a:
        answer+=a
    else:
        answer+=n
print(answer)

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 + r)
else:
    print((q + 1) * A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,a,b = map(int,input().split())
zyu = n // (a+b)
ans = 0
ans += a * zyu
nok = n - zyu * (a+b)
if nok >= a:
    ans += a
elif nok < a:
    ans += nok
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
total=A+B
if N<=A:
  print(N)
else:
  c=N//total
  m=N%total
  o=min(A,m)
  print(c*A+o)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 20:52:57 2020

@author: over-
"""


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

S=N//(A+B)
M=N%(A+B)
if M>A:M=A
ans=S*A+M

print(ans)

Submission status: Accepted

Solution code:
line = input().split()
N = int(line[0])
nB = int(line[1])
nR = int(line[2])

if nB == 0:
  print(0)
  quit()

nball = nB + nR
nGroup = N // nball
nAdditional = N % nball

if nAdditional > nB:
  nAdditional = nB

nBlueTotal = nB * nGroup + nAdditional
print(nBlueTotal)

Submission status: Accepted

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

result = 0

tmp = N // (A + B)

result += tmp * A


rest = N - tmp * (A + B)

if rest <= A:
    result += rest
else:
    result += A


print(result)

Submission status: Accepted

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

each=a+b

baisu=n//each
amari=n%each

ans+=(a*baisu)

if amari<=a:
    ans+=amari
else:
    ans+=a
    
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, a, b = map(int, input().split())
ans = 0
allcnt = 0
if a > n:
    print(n)
    sys.exit()
elif a+b >= n:
    print(a)
    sys.exit()
else:
    allcnt = n//(a+b)
    amari = n%(a+b)
    if amari > a:
        amari = a 
    print(allcnt*a+amari)

Submission status: Accepted

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

t = a + b
na1 = a * (n // t)
na2 = n % t if (n % t) < a else a

print(na1 + na2)

Submission status: Accepted

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

Submission status: Accepted

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

if b == 0:
    print(0)
else:
    x = n // (b + r)
    a = n % (b + r)

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
ab=A+B
if N <= ab and N>=A:
    print(A)
elif N <= ab:
    print(N)
else:
    t = N//ab
    t2 = N%ab
    if t2>=A:
        print(A*t + A)
    else:
        print(A*t + t2)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,B,R=map(int,input().split())
process_n = N//(B+R)
amari = N%(B+R)
result = process_n*B

if amari <= B:
    result += amari
else:
    result += B
print(result)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
C = A+B
D = N//C
ans = 0
ans+=D*A
ans+=min(N-D*C,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:
def read():
    N, A, B = list(map(int, input().strip().split()))
    return N, A, B

def solve(N, A, B):
    if A == 0:
        return 0
    repeats = N // (A + B)
    right = N - (A + B) * repeats
    blues = A * repeats + min(right, A)
    return blues


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

import queue

def main():
    n, a, b = map(int, input().split())
    p = n // (a + b)
    remain = n - p * (a + b)
    print(p * a + min(a, remain))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

[n, a, b] = [int(x) for x in input().split(" ")]
quotient = n // (a + b)
remainder = min(a, n % (a + b))
print(quotient * a + remainder)

Submission status: Accepted

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

Submission status: Accepted

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

a = N // (A+B)

M = N - (A+B)*a

if M >= A:
    print(a*A+A)

else :
    print(a*A+M)

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, b, c = map(int, input().split())
print(int(a/(b+c))*b + min(b, a%(b+c)))

Submission status: Accepted

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

def main(): 
    if a == 0:
        print(0)
        return
    if b == 0:
        print(n)
        return
    r = n % (a+b)
    d = int(n // (a+b))
    ans = a * d + min(r, a)
    print(ans)
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

if a==0:
    print(0)
else:
    sets=n//(a+b)
    res=n%(a+b)

    resa=min(res,a)

    print(sets*a+resa)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if a <= ama:
    print(ans + a)
else:
    print(ans + ama)

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:
nums=input().split(" ")
N,B,R= [int(nums[i]) for i in range(len(nums))]
sum=B+R

sets,amari=N//sum,N%sum
if amari>=B:
	x=B
else:
	x=amari

print(sets*B+x)

Submission status: Accepted

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

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

    print(blue)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

x = input().split(" ")
ans = 0

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

set = n // (b + r)
ama = n % (b + r)

ans = set * b

if ama < b :
    ans = ans + ama
else :
    ans = ans + b

print(ans)

Submission status: Accepted

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

n,a,b = map(int,readline().split())
if a == 0:
    print(0)
    exit()
ans = n//(a+b)
ans *= a
res = n%(a+b)

res = min(a,res)

ans += res

print(ans)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
ans = 0
ans += (n //(a + b)) * a
# print(ans)
val =  n - ((a + b) * (n // (a + b)))

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

Submission status: Accepted

Solution code:
numbers=input().rstrip().split(" ")
N=int(numbers[0])
A=int(numbers[1])
B=int(numbers[2])
X=int(N/(A+B))
Y=N-X*(A+B)
if Y>=A:
    delta=A
elif Y<A:
    delta=Y
print(X*A+delta)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = list(map(int, input().split()))
ans = 0
ans += (n//(a+b))*a
#print(ans)
amari = n%(a+b)
#print(amari)
nokori = min(a,amari)
#print(nokori)
ans += nokori
print(ans)

Submission status: Accepted

Solution code:
def main():

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

    # blue = ['b']*A
    # red = ['r']*B
    # l = []
    # while len(l) <= N:
    #     l.extend(blue)
    #     l.extend(red)
    # print(l[:N].count('b'))

    # c = 0
    # len = 0
    # while len <= N-A:
    #     len += A+B
    #     c += A
    # c += N-len
    # print(c)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans += count * 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())
AB = A + B
ans = (N // AB) * A
mod = N % AB 
print(ans+mod if mod < A else ans+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)
else:
    ans = (n // (a + b)) * a + a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if a == 0:
    print(0)
    exit()
tmp = N % (a+b)
print((N // (a+b))*a + min(tmp, a))

Submission status: Accepted

Solution code:
from sys import stdin

N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = stdin.readline().rstrip().split()
#print(S)
if N%(A+B)==0:
    print(A*int(N/(A+B)))
else:
    temp1=int(N/(A+B))
    temp=N-(temp1*(A+B))
    if temp<A:
        print(temp1*A+temp)
    else:
        print(temp1*A+A)

Submission status: Accepted

Solution code:
n,a,b=(int(x) for x in input().split())
l=n//(a+b)
m=n%(a+b)
if m>=a:
    m=a
print(l*a+m)

Submission status: Accepted

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

blue_count = a * (n // (a + b))
n -= (a + b) * (n // (a + b))
if n >= a:
    blue_count += a
else:
    blue_count += n
print(blue_count)

Submission status: Accepted

Solution code:
n,a,b= list(map(int, input().split()))
s=(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 = 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())

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

if amari > a:
    amari = a

print(ite*a + amari)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil as c
n,a,b=map(int,input().split())
q,r=divmod(n,a+b)
s=q*a
if r<=a:
  print(s+r)
else:
  print(s+a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b=map(int,input('').split(' '))
s=0
u=a+b
m=n//u
s=s+m*a

l=n%u
if l<=a:
    l=l
else:
    l=a

s=s+l

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
S = [int(x) for x in input().split()]
N = S[0]
A = S[1]
B = S[2]

Amari = N % (A+B)
Wari = N // (A+B)
if Amari > A:
    ans =Wari*A+A
else:
    ans =Wari*A+Amari
print(ans)

Submission status: Accepted

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

from math import ceil

x = N // (A+B)

ans = 0
if x > 0:
    N -= x * (A + B)
    ans += x * A

ans += min(N, A)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys, math
sys.setrecursionlimit(300000)


def solve(N: int, A: int, B: int):
    tmp = math.floor(N / (A + B))
    ret = tmp * A
    ret += min(A, N - tmp * (A + B))
    print(ret)
    return

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 = int(input())
n, a, b = [int(x) for x in input().split()]
#n, m = [int(x) for x in input().split()]


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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


if(N%c>=A):
    print(int(N/c)*A+A)
else:
    print(int(N/c)*A+N%c)

Submission status: Accepted

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

reps = int(N / (A+B))
complete_block = (A+B) * reps
complete_As = A * reps
left = min(N - complete_block, A)
print(complete_As+left)

Submission status: Accepted

Solution code:

import collections


class Solution:
    def solve(self, N, A, B):
        return A * (N//(A+B)) + min(N % (A+B), A)


sol = Solution()

[N, A, B] = list(map(int, input().strip().split()))
print(sol.solve(N, A, B))

Submission status: Accepted

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

total = a+b
k = n // total
ans = k * a
ans += min(a, n - k * total)
print(ans)

Submission status: Accepted

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

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

if n%(a+b)!=0:
	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())


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

print(d + r)

Submission status: Accepted

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

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

if a > d:
    s = c * a + d
else:
    s = (c+1) * a

print (s)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def calculate(n,a,b):
    s1 = n // (a + b)
    sum = a * s1

    s2 = n % (a + b)

    if s2 <= a:
        sum = sum + s2
    else:
        sum = sum + a

    return sum

result = calculate(N,A,B)

print(result)

Submission status: Accepted

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

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC158 B Count Balls

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

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

if(N-c*(A+B) > A):
    print((c+1)*A)
else:
    print(c*A + N - c*(A+B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

print d * a + min(a, m)

Submission status: Accepted

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

x = n//(a+b)

rem = n - (a+b)*x
ans = a * x + min(a, rem)
print(ans)

Submission status: Accepted

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

operation_count = N // (A+B)
blue_count = A * operation_count
if N % (A+B) > 0:
    rest = N % (A+B)
    blue_count += min([rest, A])

print(blue_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Q(A+B) gives QA blue balls, where Q = N/(A+B)
# then the left over is R = N - Q(A+B) < (A+B)
# from the left over, there are additional min(A, R) blue balls


def get_num_blue(n, a, b):
  if a == 0: return 0
  q, r = divmod(n, a+b)
  return q*a + min(a, r)


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

Submission status: Accepted

Solution code:
def main():
    N, A, B = map( int, input().split())
    n = N//(A+B)
    ans = n*A
    N -= n*(A+B)
    if N <= A:
        ans += N
    else:
        ans += A
    print(ans )
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
C=A+B
D=N//C #何セットあるか
E=C*D #セットの最後までの個数

if N-E>=A:
  ans= D*A + A
else:
  ans= D*A+ (N-E)
  
print(ans)

Submission status: Accepted

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

comb = int(N / (A + B))
index = N % (A + B)
n_bule = A * comb + min(index, A)

print(n_bule)

Submission status: Accepted

Solution code:
def main():
  n, blue, red = input_list()
  d = n % (blue+red)
  if d == 0:
    print(blue * (n // (blue+red)))
  else:
    if d > blue:
      d = blue
    print(blue * (n // (blue+red))+d)
    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Submission status: Accepted

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys

def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]


def main():
    n, a, b = _ia()
    #
    ab = n//(a+b)
    cnt = a * ab
    print(cnt + min(n-(a+b)*ab, a))


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N,b,r = map(int, input().split())
 
num = int(N / (b+r))
rest = N - num * (b + r)

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

Submission status: Accepted

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

M = int(N/(A+B))
m = N%(A+B)

Bsum = M*A
if(m <= A):
  Bsum += m
else:
  Bsum += A

print(Bsum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n, a, b = input().split()
    n, a, b = int(n), int(a), int(b)
    syou = int(n / (a + b))
    amari = n % (a + b)
    
    if amari - a < 0:
        print(a * syou + amari)
    else:
        print(a * syou + a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

blue = 0

if n <= (a+b):
  if n > a:
    blue = a
  else:
    blue = n
else:
  blue = (n // (a+b))*a

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

# input = sys.stdin.readline

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

sho = n // (a + b) 

mod = n % (a + b)

if mod <= b:
    b_num = sho * b + mod
else:
    b_num = sho * b + b
print(b_num)

Submission status: Accepted

Solution code:
import math
from collections import deque
def main():
    n,a,b = tuple([int(t)for t in input().split()])

    if b == 0:
        print(n)
    else:
        t = a+b
        res = (n // t)*a+min(n%t,a) 
        print(res)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

blue = 0
ab_num = n // (a + b)

trunk = ab_num * a

remain = n - ab_num * (a + b)

blue = trunk + min(remain, a)

print(blue)

Submission status: Accepted

Solution code:

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

ans = 0

if a + b > 0:
    step = a + b
    ans += a * (n // step)
    
    ans += min(a, n % step)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def abc158b(n, a, b):
    num_b = 0
    if a+b != 0:
        rep = n // (a+b)
        mod = n % (a+b)
        num_b = rep * a
        if mod < a:
            num_b += mod
        else:
            num_b += a

    return num_b

###
# main
if(__name__ == '__main__'):
    # input
    n, a, b = map(int, input().split(" "))
    
    accomplishment = abc158b(n, a, b)
    
    # output
    print(accomplishment)
# else:
    # do nothing

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print( a*A+ min(b,A))

Submission status: Accepted

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

Submission status: Accepted

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

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 fractions import gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

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


def main():
    N, A, B = MAP()
    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())

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

amari=a

if a>y:
  amari=y

print(a*x+amari)

Submission status: Accepted

Solution code:

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

if N <= A:
    print(N)
elif N <= (A+B):
    print(A)
else:
    sum = A+B
    repeat = int(N/sum)
    amari = N%sum

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

n, a, b = np.asarray(input().split(), dtype=np.uint64)

times = np.asarray([0], dtype=np.uint64)
times += n // (a+b)

last = np.asarray([0], dtype=np.uint64)
last += n % (a+b)

answer = np.asarray([0], dtype=np.uint64)

if last <= a:
    answer += times * a + last
else:
    answer += a * (times + 1)

print(int(answer))

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

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

Submission status: Accepted

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

modans = X % (A + B)
n = X // (A + B)

if modans <= A:
	ans = (A * n) + modans
elif modans == 0:
	ans = A * n
else:
	ans = A * (n + 1)

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:
# -*- coding: utf-8 -*-

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

x = n // (a+b)
res = x * a

y = n - x*(a+b)
if y >= a:
    res += a
else:
    res += y

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

if b_ball == 0:
  print(0)
else:
  cycle = int(n / (b_ball + r_ball))
  amari = int(n % (b_ball + r_ball))
  if amari > b_ball:
    amari = b_ball
  
  sum_ball = cycle * b_ball + amari
  print(sum_ball)