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())
# n,a,b = map(int, "6 2 4".split())

tmp = int(n /(a+b))
amari = int(n %(a+b))

if amari >= a:
    print(tmp*a + a)
else:
    print(tmp*a + amari)

Submission status: Accepted

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

h = n//(a+b)
r = n%(a+b)

if r>=a:
  ans = h*a + a
else:
  ans = h*a +r
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

n=N%(A+B)
m=N//(A+B)

if n<A:
	ans=A*m+n
else:
	ans=A*(m+1)
	
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

x = A * b
print(x + min(N-(a*b), A))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

AplusB = A+B

action_num = N // AplusB
ans += action_num * A

action_mod = N % AplusB

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

print(ans)

Submission status: Accepted

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

if A == 0:
    print(0)
elif B == 0:
    print(N)
else:
    # A+Bの組がいくつ存在するか
    set_count = N // (A+B)
    # 余り
    mod = N % (A+B)
    
    if mod == 0:
        print(A*set_count)
    else:
        if mod < A:
            print(A*set_count+mod)
        else:
            print(A*set_count+A)

Submission status: Accepted

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

def main():
    N, A, B = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:
import math

def main():
  n,a,b = (int(x) for x in input().split())

  num_a = (math.floor(n/(a + b)))
  num_b = int(n % (a + b))

  print(int(num_a * a + min(a, num_b)))
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n,a,b = map(int, input().split(" "))
ans = n // (a + b) * a	# times a is appearing
rem = n % (a+b) # extras in the end
ans += min(a, rem)
print(ans)

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 = input().split();
N = int(N);
blue = int(A);
red = int(B);

sho = N // (blue + red);
amari = N % (blue + red);

last = min([amari, blue]);

ans = sho * blue + last;

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 main():
    args = input().rstrip().split(' ')
    N, A, B = int(args[0]), int(args[1]), int(args[2])
    unit = int(N/(A+B))
    rem = N % (A+B)
    if(rem > A):
        brem = A
    else:
        brem = rem
    print(A*unit + brem)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, a, b = map(int, readline().split())
if n <= a + b:
    print(min(n, a))
else:
    ans = n // (a + b) * a
    if n % (a + b) < a:
        ans += n % (a + b)
    else:
        ans += a
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

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

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

print(c)

Submission status: Accepted

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

times=n//(a+b)

k=n%(a+b)

total= a if k>a else k
print(times*a+total)

Submission status: Accepted

Solution code:
N,b,r=map(int,input().split())
ball,x,y=0,0,0
ans=0

ball=b+r
x=N%ball
y=N//ball

ans+=y*b

if x>b:
    ans+=b
else:
    ans+=x


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n, blue_count, red_count = map(int, input().split())

if blue_count >= n:
  print(n)
elif blue_count + red_count > n:
  print(blue_count)
else:
  set_count = blue_count + red_count

  margin = 0
  if n % set_count == 0:
    c =  n // set_count
  else:
    c =  n // set_count
    margin = n % set_count

  # NOTE: あまり部分が 青 -> 赤 の途中である事を前提としてしまっているので変更が必要
  if margin > blue_count:
    margin = blue_count
    
  print(blue_count * c + margin )

Submission status: Accepted

Solution code:
# coding: utf-8
def main():
    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)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

nb = A + B
nt = int(N/nb)
nr = A if N % nb >= A else N % nb

print(nt*A + nr)

Submission status: Accepted

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

N, A, B = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = (int(x) for x in input().split())
k = n - (a + b)*(n//(a + b))
if k <= a:
  print(a*(n//(a + b)) + k)
else:
  print(a*(n//(a + b)) + a)

Submission status: Accepted

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

print(total)

Submission status: Accepted

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

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
d = n // c
e = n % c
ans = a * d + min(e, a)
print(ans)

Submission status: Accepted

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

b = a[1] + a[2]
c = a[0] // b * a[1]
d = a[0] % b

if not d == 0:
    if d < a[1]:
        c += d
    else:
        c += a[1]

print(c)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

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

Submission status: Accepted

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


count = n // (b+r)
counts = n % (b+r)

countss=b*count
if counts<= b:
  coun=counts
else:
  coun=b

print(countss+coun)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n,a,b=map(int,input().split())
ans=0
ans+=(n//(a+b))*a
n%=a+b
if n<=a:
    ans+=n
else:
    ans+=a
print(str(ans)+"\n")

Submission status: Accepted

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

Submission status: Accepted

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

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 = tuple(int(n) for n in input().split())

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

Submission status: Accepted

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

'''
ext = []
cnt = 0
while cnt <= n:
    for _ in range(a):
        ext.append('b')
    cnt += a
    for _ in range(b):
        ext.append('r')
    cnt += b
print("".join(ext[0:n]))
'''

Submission status: Accepted

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

Submission status: Accepted

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

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 < 0:
  print(N // (A + B) * A + abs(N % (A + B)))
elif N % (A + B) - A > 0:
  print(N // (A + B) * A + A)

Submission status: Accepted

Solution code:
inp = input().split()
inp = list(map(int, inp))
n, a, b = inp[0], inp[1], inp[2]
div, mod = divmod(n, a+b)
if mod < a: print(div*a + mod)
else: print((div+1)*a)

Submission status: Accepted

Solution code:
x = input()
n = int(x.split()[0])
b = int(x.split()[1])
r = int(x.split()[2])

shou = n // (b + r)
amari = n % (b + r)

if amari - b == 0:
    sum = shou * b
elif amari - b < 0:
    sum = (shou * b) + amari
elif amari - b > 0:
    sum = (shou * b) + b
   
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ma(): return map(int,input().split()) 



n,a,b=ma()
c_num=n//(a+b)   
c_sum=c_num*(a+b)
c_rest=min(n-c_sum, a)

c_want=a*c_num + c_rest
print(c_want)

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:
import numpy as np
import sys
readline = sys.stdin.buffer.readline

N,B,R = map(int, readline().split())
 
print(N//(R+B)*B+min(N%(R+B),B))

Submission status: Accepted

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

Submission status: Accepted

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

a = N // (A+B)

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    d, m = divmod(n, a + b)
    print(a * d + min(a, m))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

ans = int(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())

X = N//(A+B)
Y = N%(A+B)

if Y > A:
    Y = A

print(X*A+Y)

Submission status: Accepted

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

k = n//(a+b)
l = n%(a+b)

print(k*a + min(l,a))

Submission status: Accepted

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

tmp = N // (A+B)
ans = tmp * A
remain = N - (tmp * (A+B))
if (remain >= A) :
    ans += A
    
else:
    ans += remain

print(ans)

Submission status: Accepted

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

if amari > a:
    print(syou * a + a)
else:
    print(syou * a + amari)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 20:10:24 2020

@author: Kanaru Sato
"""

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin

N, A, B = [int(x) for x in stdin.readline().rstrip().split()]

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

if A >= mod:
    add_mod = mod
else:
    add_mod = A

print(div * A + add_mod)

Submission status: Accepted

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

t=n//(a+b)

print(t*a+min(a,n-t*(a+b)))

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

# 円周率 pi
"""import math
pi_ = math.pi"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n,a,b = readInts()
  sum_ = a + b
  if n // sum_  == 0:
    if n >= a:
      print(a)
    else:
      print(n)
  else:
    quo = n // sum_ # quotient 商
    if n % sum_ != 0:
      sur = n % sum_
      if sur >= a:
        print(quo * a + a)
      else:
        print(quo * a + sur)
    else:
      print(quo * a)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

N, A, B = MAP()
C = N // (A+B)

if N <= A+B:
  print(min(A, N))
elif N % (A+B) < A:
  print(A*C + N%(A+B))
else:
  print(A*(C+1))

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

c = n // (a+b)

ans += a * c

if n - c * (a+b) >= a:
    ans += a
else:
    ans += (n-c*(a+b))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

v = a//(b+c)
remain = a%(b+c)
if (remain <= b) :
    print(v*b+remain)
else:
    print(v*b+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def myAnswer(N:int, A:int, B:int) -> int:
   counter =(N // (A + B))
   ans = counter * A
   if(N % (A + B) < A):
      ans += N % (A + B)
   else:
      ans += A
   return ans 

def modelAnswer():
   tmp=1
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

num = n//(a+b)
num_a = n%(a+b)

ans = num * a
if num_a >= a:
    print(ans + a)
else:
    print(ans + num_a)

Submission status: Accepted

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

Submission status: Accepted

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

n, a, b = map(int, input().split())
print(n//(a+b)*a + min(n-(n//(a+b)*(a+b)), a))

Submission status: Accepted

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

l=n/(a+b)
l=int(l)
s=n%(a+b)
if s>=a:
    sum=l*a+a
else:
    sum=l*a+s
print(str(sum))

Submission status: Accepted

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

Submission status: Accepted

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

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,b,r = [int(i) for i in input().split()]
k = n // (r+b) * b
l = min(n % (r+b), b)
print(k+l)

Submission status: Accepted

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

    if A == 0 and B == 0:
        print(ans)
        return

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

    print(ans)


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if (N % (A + B)) > A:
    ans += 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 + min(a,n%(a+b))
print(ans)

Submission status: Accepted

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

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

if amari > A:
    print(A*(loop+1))

else:
    print(A*loop+amari)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

div = N//(A+B)
rest = N % (A+B)


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

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

res += min((N % (A+B)), A)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B

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

total = 0

p = N//(A+B)

total += p*A

q = N - p*(A+B)

if q>A:
  total += A
else:
  total += q
print(total)

Submission status: Accepted

Solution code:
import math

inputted = list(map(int, input().split()))

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

AB = A + B
remainder = N % AB

num_of_repeat = math.floor(N / AB) * A
num_of_remainder = min(A, remainder)
total = num_of_repeat + num_of_remainder

print(total)

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())
syo=n//(a+b)
amari=n%(a+b)

if amari>=0 and amari<=a:
    print(syo*a+amari)

else :
    print(syo*a+a)

Submission status: Accepted

Solution code:
N, A, B = list(map(int, input().split()))
ans = ""
# if N == A + B:
#     ans = A   #ans = len(A)とする必要ない
# elif N < (A + B) and N >= A:
#     ans = A
# elif N < (A + B) and N < A:
#     ans = N
x = N // (A + B)
ans1 = A * x
y = N - (A + B) * x
if y >= A:
    ans = A + ans1
elif y < A:
    ans = y + ans1
print(ans)
"""
y < (A + B)を条件に含める必要はない。yは余り部分だから必ずA+Bより小さい

"""

Submission status: Accepted

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

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

if q < A:
    print(p*A + q)
else:
    print(A * (p+1))

Submission status: Accepted

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

Submission status: Accepted

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

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

if(mod <= A):
  number = q*A + mod
elif(mod > A):
  number = q*A + A

print(number)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

C = N // (A + B)#商
D = N % (A + B) #余

if D >= A:
  Blue = C * A + A
else:
  Blue = C * A + D
  
print(Blue)

Submission status: Accepted

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

ans = 0

if n <= a:
    print(n)
else:
    d, m = divmod(n, a+b)

    if m > a:
        print((d+1)*a)
    else:
        print(d*a+m)

Submission status: Accepted

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

roop = A + B

kaisu = N//roop
amari = N % roop

blue = 0
blue = blue + kaisu*A

if amari >= A:
    blue = blue + A
else:
    blue = blue + amari


print(blue)

Submission status: Accepted

Solution code:
# N: number of balls to take, A: blue, B: red
N, A, B = list(map(int, input().split()))

if N == 0:
    print(0)

if A + B < N:
    # want to know how much A + B blocks can we place such that A + B < N (i.e. solve x(A+B) < N)
    blocks = int(N/(A+B))
    # for each block, there are A blue balls, plus potentially some reamining slots to fill the remaining space of N
    remaining_slots = N % (A+B)
    if A <= remaining_slots:
        # if it can fit A, place A more balls in the row
        print(blocks*A + A) 
    else:
        print(blocks*A + remaining_slots)
else:
    if A < N:
        print(A)
    else:
        print(N)

Submission status: Accepted

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

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

s = N // (A + B)
t = N % (A + B)

print(s * A + min(A, t))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

m=n%(b+r)
l=n//(b+r)
x=n-l*(b+r)

if x<b:
    s=m
else:
    s=b

if m==0:
    n_b=l*b
else:
    n_b=l*b+s
print(n_b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = (N//(A+B))*A
 
 
if (N%(A+B)) > A :
    m = s+A
else :
    m = s + (N%(A+B))
    
print(m)

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

Submission status: Accepted

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

if a == 0:
    print("0")
elif n % (a+b) == 0:
    print(s*a)
elif n % (a+b) != 0:
    print(s*a + x)

Submission status: Accepted

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

Submission status: Accepted

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

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


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