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 collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

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

Submission status: Accepted

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

Kurikaeshi = N // (A + B) 
Amari = N % (A + B)
Aoi = 0 

if Amari >= A:
    Aoi = A
else:
    Aoi = Amari

result = Aoi + Kurikaeshi * A


print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#  = input()
#a  = int(input())
n, a, b = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

if a == 0:
  print(0)
elif n < (a + b):
  print(min(n, a))
else:
  nab = n // (a + b)
  ans = nab * a
  mod = n % (nab * (a + b))
  ans += min(mod, a)
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

syo = n // (a+b)
amari = n % (a+b)
if a>amari :
    amari = amari
else:
    amari = a

print(syo * a + amari)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
Loop = N//(A+B)
Rest = N%(A+B)
if Rest >= A :
    Last = A 
else :
    Last = Rest

ans = Loop*A + Last

print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,a,b = [int(i) for i in readline().split()]

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

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

t = n//(a+b)
c=0

if t == 0 and n < a:
    c += n
    print(c)
elif t == 0 and n >= a:
    c += a
    print(c)
elif t > 0:
    c += t * a
    r = n%(a+b)
    if r == 0:
        print(c)
    elif r < a:
        c += r 
        print(c)
    elif r > a:
        c += a
        print(c)

Submission status: Accepted

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

n,a,b = readInts()
x = math.floor(n/(a+b))
y = n-(a+b)*x
ans=a*x+min(y,a)
print(ans)

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

loop_count = n // (a + b)
amari = n % (a + b)
amari_a = a
if amari < a:
  amari_a = amari

print(a * loop_count + amari_a)

Submission status: Accepted

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

Submission status: Accepted

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

if d>a:
    d = a
print(a*c+d)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if diff > a:
    blue += a
else:
    blue += diff

print(blue)

Submission status: Accepted

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

NumberOfRotations = int(n/(a+b))
surplus = n%(a+b)

ans = 0

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

ans = a*NumberOfRotations
if a > n - ((a+b)*NumberOfRotations):
    print(ans+surplus)
else:
    print(ans+a)

Submission status: Accepted

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

NumberOfRotations = int(n/(a+b))
surplus = n%(a+b)

ans = 0

if NumberOfRotations == 0:
    if a > n:
        print(surplus)
    else:
        print(a)
else:
    ans = a*NumberOfRotations
    if a > n - ((a+b)*NumberOfRotations):
        print(ans+surplus)
    else:
        print(ans+a)

Submission status: Accepted

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

NumberOfRotations = n//(a+b)
surplus = n%(a+b)

ans = 0

if NumberOfRotations == 0:
    if a > n:
        print(surplus)
    else:
        print(a)
else:
    ans = a*NumberOfRotations
    if a > n - ((a+b)*NumberOfRotations):
        print(ans+surplus)
    else:
        print(ans+a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,a,b = MAP()

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

ans = q*a
if(rem>a):
    print(ans + a)
else:
    print(ans + rem)

Submission status: Accepted

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

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

if N- (A+B)*ans <= A:
    print(A*ans + N- (A+B)*ans)

else:
    print(A*ans+A)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if a == 0:
  print("0")
elif b == 0:
  print(n)
else:
  ab = a + b
  sets = n // ab
  mods =  n % ab
  mods = min (a, mods)
  print(sets*a + mods)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if A == 0:
    print(0)
    exit()
P = A + B
X = N//P
x = N%P

if x >= A:
    ans = A*X+A
elif x < A:
    ans = A*X+x

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,A,B=map(int,input().split())
if divmod(N,A+B)[1]<=A:
  print(math.floor(N/(A+B))*A+(N-(A+B)*math.floor(N/(A+B))))
else:
  print(math.ceil(N/(A+B))*A)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

t1 = n // (a+b)
t2 = n % (a+b)
if t2 >= a :
    t3 = a
else :
    t3 = t2

print(t1*a + t3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x=N//(A+B)

y=N%(A+B)

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

Submission status: Accepted

Solution code:
N ,A ,B = map(int,input().split())
r = divmod(N,A+B)
if r[1] >= A :
    print(A * (r[0] + 1))
else:
    print(A*r[0]+r[1])

Submission status: Accepted

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

Submission status: Accepted

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

num=N//(A+B)
amari=N%(A+B)
tasu=0
if amari<=A:
  tasu=amari
else:
  tasu=A

print(num*A+tasu)

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:
import sys
N, A, B = map(int,input().split())
AB = A + B
n = N//AB
amari = N%AB
if A >= N:
  print(N)
  sys.exit()
if AB > N:
  print(A)
  sys.exit()
add = min(amari, A)
print(n*A + add)

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:
n,a,b = map(int,input().split())
x = n // (a + b)
y = n % (a + b)

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

Submission status: Accepted

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

cycles = n//(a+b)
count = 0
count += a*cycles
rest = n - (a+b)*cycles
if rest > a:
    count += a
else:
    count += rest
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

period = N // (A + B)
number = N % (A + B)

if number >= A:
  print(A * period + A)
else:
  print(A * period + number)

Submission status: Accepted

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

Submission status: Accepted

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

cycle = A + B
cyclecount =  N // cycle
blueincycle = A * cyclecount
amari = N % cycle

if amari < A:
    print(blueincycle + amari)
else:
    print(blueincycle + A)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter

import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

#N = int(input())
N, A, B = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入


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

count=div*A
count+=min(mod,A)

print(count)

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())
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().split())
q,mod=divmod(n,(a+b))
if mod>a:
  mod=a
print(q*a+mod)

Submission status: Accepted

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

Submission status: Accepted

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

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

Q = N //(A+B)
r = N -(A+B)*Q

if r < A:
    ans = Q*A + r
else:
    ans = Q*A + A

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

pattern = N // (A + B)

ans = 0
ans += A * pattern
ans += min(N - (A + B) * pattern, A)

print(ans)

Submission status: Accepted

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

if zan <= B:
    print(num * A)
else:
    print(num * A + B - zan)

Submission status: Accepted

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

Submission status: Accepted

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

set = a + b

set_num = n // set
remain = n%set

if remain <= a:
    blue = a * set_num + remain
else:
    blue = a * (set_num + 1)

print(blue)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

block = N//(A + B)
other_balls = N%(A + B)

if other_balls >= A :
    print((block*A)+A)
elif other_balls < A :
    print((block*A)+other_balls)
else :
    print(0)

Submission status: Accepted

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

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

if amari > a:
    ans += a
else:
    ans += amari

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if A == 0:
    print(0)
elif B == 0:
    print(N)
else:
    br_block = A + B
    pre_b = (N - 1) // br_block
    if (N - 1) % br_block < A:
        b = (N - 1) % br_block + 1
    else:
        b = A
    print(A * pre_b + b)

Submission status: Accepted

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

Submission status: Accepted

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

if n % (a+b) == 0:
  ans += n//(a+b) *a
  
else:
  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())
m=A+B
x=int(N/m)
y=int(N%m)
if y<=A:
    print(x*A+y)
else:
    print(A*(x+1))

Submission status: Accepted

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

if n>=(a+b):

    k=int(n/(a+b))

    l=int(n%(a+b))

    if l>=a:

        print(a*k+a)

    else:
        print(a*k+l)

else:

    if n>=a:

        print(a)

    else:
        print(n)

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)
elif N%(A+B) !=0:
  ans += A
print(ans)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
m=A+B
x=int(N/m)
y=int(N%m)
if y<=A:
    print(x*A+y)
else:
    print((x+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 = map(int, input().split())
s = n//(a+b)
rest = n%(a+b)
print(s*a+min(a,rest))

Submission status: Accepted

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

remainBalls = 0
if N % oneSet > A: remainBalls = A
else: remainBalls = N % oneSet

blue = math.floor(N / oneSet) * A + remainBalls

print(blue)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

# check
if A == 0:
    print(0)
else:
    cnt = int(N / (A + B))
    amr = N % (A + B)
    ans = A * cnt
    if amr >= A:
        ans += A
    else:
        ans += amr
        
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

mod = N % (A+B)
ans = 0
if 0 < mod and mod <= A:
    ans = mod
elif mod != 0:
    ans = A

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

sum = n//(a+b)*a
res = n%(a+b)
sum += min(res,a)

print(sum)

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().strip().split())
q = n // (a + b)
r = n % (a + b)

if r > a:
    res_b = a
else:
    res_b = r

ans = q * a + res_b
print(ans)

Submission status: Accepted

Solution code:
Str = input().split()
N = int(Str[0])
A = int(Str[1])
B = int(Str[2])
answer = A*(N//(A+B))
res = N % (A+B) 
if res <= A:
  answer+= res
else:
  answer+= A

print(answer)

Submission status: Accepted

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

l=a+b

if n%l>=a:
  print(math.floor(n/l)*a+a)
else:
  print(math.floor(n/l)*a+n%l)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N,A,B = map(int,input().split())
a = math.floor(N/(A+B))
if(N-a*(A+B)>=A):
  print(A*(a+1))
else:
  print(A*a+(N-a*(A+B)))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

brset = A + B
inside = N // (A+B)
count = inside*A

if inside*brset + A <= N:
    count += A
else:
    count += N - (inside*brset)

print(count)

Submission status: Accepted

Solution code:
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
  n,a,b=ints()
  print(((n-1)//(a+b))*a+min(a,(n-1)%(a+b)+1))

if __name__ == '__main__':
  main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

m = a + b
n_set = n // m
n_mod = n % m

ans = a * n_set

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

s = a + b

amari = n % s
syou = n // s

if amari == 0:
    print(a*syou)
    sys.exit()

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

Submission status: Accepted

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

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

print(pre)

Submission status: Accepted

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

Submission status: Accepted

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

# import collections

# blues = 'b' * A
# reds = 'r' * B

# set_balls = blues + reds

# all_balls = set_balls * ( N // ( A + B ) + 1 )

# balls_N = all_balls[:N]

# c = collections.Counter(balls_N)
# print(c['b'])

p = N//(A+B)

if N - p*(A+B) < A:
    print(A*p + N - p*(A+B) )
else:
    print(A*p+A)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(sets*a + min(amari, a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import sys

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

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

res = cnt*A

if amari <= A:
    print(res+amari)
else:
    print(res+A)

Submission status: Accepted

Solution code:

n,a,b = map(int,input().split())
num = 0
num = n // (a+b)

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

Submission status: Accepted

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

if a==0:
    blue = 0

else:
    brset = n // (a+b)
    blue1 = a * brset
    n -= (a+b) * brset
    blue2 = min(n, a)
    blue = blue1 + blue2

print(blue)

Submission status: Accepted

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

n = N // (A + B)
mod = N % (A + B)
 
if mod >= A:
    print(A * n + A)
else:
    print(A * n + mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import module
import sys
import math
import numpy as np

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

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

if y > A:
    print(x*A+ A)
else:
    print(x*A + y )

Submission status: Accepted

Solution code:
import sys
n, a, b = map(int, sys.stdin.readline().split())
balls = n // (a+b) * a
if n % (a+b) <= a:
  balls += n % (a+b)
else:
  balls += a
print(balls)

Submission status: Accepted

Solution code:
import sys
n, a, b = map(int, sys.stdin.readline().split())
balls = n // (a+b) * a
if n % (a+b) <= a:
  balls += n % (a+b)
else:
  balls += a
print(balls)

Submission status: Accepted

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

if (A+B)>0 and A>0:
  n=N//(A+B)
  AB=N%(A+B)
  A_cnt=AB//A
  if A_cnt>0:
    print((n+1)*A)
  else:
    print(n*A+AB)
elif A==0:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    n, a, b = map(int, rl().split())
    c = n // (a + b)
    d = n % (a + b)
    ans = c * a
    if a > d:
        ans += d
    else:
        ans += a
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

if mod >= A:
    print(A * n + A)
else:
    print(A * n + mod)

Submission status: Accepted

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