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())
amari = n % (a+b)
sho = n // (a+b)
if n <= a:
    print(n)
elif amari == 0:
    print(a*sho)
elif amari < a:
    print(a*sho + amari)
else:
    print(a*sho + a)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

s = b + c

counter = a//s
ans = b*counter
if a - (s * counter) <= b:
  ans += a - (s * counter)
else:
  ans += b

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N,A,B = LMIIS()
    one = A+B
    #all_balls = one * 10**100
    if N%one <= A:
        remain = N%one
    else:
        remain = A
    print(N//one*A+remain)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if A == 0:
  ans = 0
elif N < A:
  ans = N
elif N < A+B:
  ans = A
else:
  x = N // (A+B)
  y = N % (A+B)
  ans = A * x + min(y, A)

print(ans)

Submission status: Accepted

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

answer =0

if A==0:
    answer = 0
elif B==0:
    answer = N
else:
    tail=0
    if N%(A+B) > A:
        tail = A
    else:
        tail = N%(A+B)
    answer = A * (N//(A+B)) + tail

print(answer)

Submission status: Accepted

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

AB = A+B
C = N // AB
n = N - AB * C

if n > A:
    print(C * A + A)
else:
    print(C * A + A - (A - n))

Submission status: Accepted

Solution code:
import math

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

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())
L = []
b = 0
ans = 0

if A == 0:
  ans = 0
elif N < A:
  ans = N
elif N < A+B:
  ans = A
else:
  x = N // (A+B)
  y = N % (A+B)
  ans = A * x + min(y, A)

print(ans)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
cnt = 0
ans = 0
l = (a+b)
if n//l <= 10**100:
    ans += a * (n//l)
    cnt += (n//l)*l
    if n - cnt >= a:
        ans += a
    else:
        ans += max(n - cnt, 0)
else:
    ans += a * 10**100
    cnt += 10**100

print(ans)

Submission status: Accepted

Solution code:
#数値の入力
# スペース区切りの入力
N, A, B = map(int, input().split())


q = N // (A+B)  #Nを(A+B)で割った時の商
mod = N % (A+B) #Nを(A+B)で割った時の余り

if (mod >= A):  
    ans = (q * A) + A
    print(ans)

elif (mod < A):
    ans = (q*A) + mod
    print(ans)

Submission status: Accepted

Solution code:
import math
n, a, b =map(int,input().split())
x=a+b
#yはn/(a+b)の商
quotient=math.floor(n/x)
#zはn/(a+b)の余り
rmd=n%x
if rmd==0:
  blue=quotient*a
  print(blue)
elif rmd<=a:
  blue=quotient*a+rmd
  print(blue)
else:
  blue=quotient*a+a
  print(blue)

Submission status: Accepted

Solution code:
N, b, r = list(map(int, input().split()))
if b==0 and r==0:
  print(0)
  exit()
  
c = N//(b+r)
if N%(b+r) == 0:
  print(b*c)
else:
  if N%(b+r) <= b:
    print(c*b + N%(b+r))
  else:
    print(b*c + b)

Submission status: Accepted

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

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

else:
  print( a*d + a )

Submission status: Accepted

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

Submission status: Accepted

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

q = int(n/(a+b))
r = n - (a+b)*(q)
ans = q*a
ans += min([a,r])
print(ans)

Submission status: Accepted

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

if a == 0 and b == 0:
    print("0")
elif a >= n:
    print(n)
else:
    x = n // (a + b)
    if x == 0:
        print(a)
    else:
        if (n - ((a + b) * x)) >= a:
            print(a * x + a)
        else:
            print((a * x + (n - (a + b) * x)))

Submission status: Accepted

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

Submission status: Accepted

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

division = N // (A + B)
count = division * A

count += N - division * (A + B) if A > N - division * (A + B) else A
print(count)

Submission status: Accepted

Solution code:
lst = [int(i) for i in input().split()]
ball = lst[0]
blue = lst[1]
red = lst[2]

red_blue = int(ball / (red + blue))
shokichi = red_blue * blue
amari = ball - (red_blue * (red + blue))

if amari < blue:
    nokori = amari
elif amari > blue:
    nokori = blue
else:
    nokori = 0

if blue == 0:
    print(0)
else:
    print(shokichi + nokori)

Submission status: Accepted

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

c=a+b
if a==0:
    print(0)
if c!=0 and a!=0:
    d=n//c
    num=a*d
    if n%c<=a:
        print(num+n%c)
    elif n%c>a:
        print(num+a)

Submission status: Accepted

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

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

if Y < A:
    Z = Y
else:
    Z = A

print(X + Z)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

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

if A == 0:
    print(0)
else:
    if Y <= A:
        print(A * X + Y)
    else:
        print(A * X + A)

Submission status: Accepted

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

all = a + b

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

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

# a > 0
c = math.floor(N / all)
d = N % all

roundCnt = a * c
amariCnt = 0

if d != 0:
    if d <= a :
        amariCnt = d
    else:
        amariCnt = a

print(roundCnt + amariCnt)


#a = 0 print 0
#a > 0
# N <= a print N
# N > a
#  N/(a+b)=c     が割り切れる  a * c
#  N/(a+b)=c...d が余りが出る  a * c
#    d <= a のとき a * c + d
#    d >  a のとき a * c + a
#

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,B,R = map(int,input().split())
k = N % (B + R)
k2 = int(N / (B + R))
#s = ("b"*B + "r"*R)

#s1 = s[:k]
if k <= B:
	print(k2*(B) + k)
else:
	print(k2*(B) + B)

Submission status: Accepted

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


def check(N,A,B):
    if A == 0:
        return 0
    r  = N//(A+B)
    x = N-r*(A+B)
    if x > A:
        return r*A+A
    else:
        return r*A+x
print(check(N,A,B))

Submission status: Accepted

Solution code:
import math
num, blue, red = map(int, input().split())

line = math.floor(num / (blue + red))
amari = num % (blue + red)

b1 = line * blue


if blue > amari:
    print(b1 + amari)
else:
    print(b1 + blue)

Submission status: Accepted

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

c = math.floor(n/(a+b))
ans1 = c*a

if n - (a+b)*c <= a:
    ans2 = n - (a+b)*c
else:
    ans2 = a
print(ans1 + ans2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

x = n // (b + r)

if n % (b + r) > b:
    print(x * b + b)
   
else:
    print((x * b) + (n % (b + r)))

Submission status: Accepted

Solution code:
import sys
n, a, b = map(int, input().split())
if a == 0 or n == 0:
    print(0)
    sys.exit()
j = n //(a + b)

if n - (a + b) * j >= a:
    print(a * j + a)
    sys.exit()
else:
    print(a * j + n- (a + b)*j )
    sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
ans += n // (a + b) * a
rem = n % (a + b)
if a == 0:
    pass
elif rem > a:
    ans += a
elif rem <= a:
    ans += rem
print(ans)

Submission status: Accepted

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

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

if 0 <= D and D <= A:
    print(C + D)
else:
    print(C + A)

Submission status: Accepted

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

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

if sa > a:
  ans = syou * a + a
else:
  ans = syou * a + sa
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:

n,a,b = map(int,input().split())
ans = 0
c = n % (a + b)

if a == 0 and b == 0:
    print(0)
else:
    ans = int(n / (a + b)) * a
    if 0 <= c <= a:
        print(ans + c)
    elif a <= c <= a + b:
        print(ans + a)
    else:
        print("What??")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
M=N
if A==0:
    print(0)
    exit()
if A+B>=N:
    print(min(A,N))
    exit()
cnt=N//(A+B)
ans=cnt*A
N=N-cnt*(A+B)
if N<=A+B and N>A:
    ans+=A
    print(ans)
    exit()
elif N<=A:
    ans+=M-cnt*(A+B)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, A, B = [int(i) for i in input().strip().split()]
q, r = divmod(N, A+B)
if r <= A:
  print(A*q + r)
else:
  print(A*q + A)

Submission status: Accepted

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

l=a+b
sub=int(n//l)
ans=sub*a
zan=n-sub*l
ans+=min(a,zan)
print(ans)

Submission status: Accepted

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

a = int(B+R)
b = int(N/a)
c = int(N%a)

if b <= 0:
    if R ==0:
        print(N)
    else:
        if B > N:
            print(N)
        else:
            print(B)
else:
    if R == 0:
        print(N)
    else:
        if B == 0:
            print(0)
        else:
            if c > B:
                print((b*B)+B)
            else:
                print((b*B)+c)

Submission status: Accepted

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

count = N // (A + B)
amari = N%(A+B)
sum_blue = A * count + min(A, amari)

print(sum_blue)

Submission status: Accepted

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

Submission status: Accepted

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

if r + 1 < 10 ** 18:
    x = res if res <= a else a
    print((a * r) + x)
else:
    print(a*r)

Submission status: Accepted

Solution code:
NAB = list(map(int, input().split()))
N = NAB[0]
A = NAB[1]
B = NAB[2]
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())
import math
sets = math.floor(N/(A+B))
res = A * sets
res += min(N - (A+B)*sets, A)
print(res)

Submission status: Accepted

Solution code:
import math

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

result = 0

a = math.floor(N / (A + B))
r = N % (A + B)

if r > A:
    ad = A
else:
    ad = r

result = A * a + ad
print(result)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
ctpossible=A*(N//(A+B))#ペアでカウント可能
if N%(A+B)<=A:
    adding=N%(A+B)
else:
    adding=A
print(ctpossible+adding)

Submission status: Accepted

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

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

print(num)

Submission status: Accepted

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

#Process
nokori = 0
na = int(N / (A + B))
if((A+B)*na + A > N):
    nokori = N % (A + B)
else:
    nokori = A
Ans = A * na + nokori

#Output
print(Ans)

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().split()

n, a, b = map(int, s)
res = (n // (a+b)) * a + min(a, n%(a+b))
print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


ans1 = (N//(A+B))*A
ans2 = (N%(A+B))
if ans2 > A:
    ans2 = A

ans = ans1 + ans2

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

sum = a+b
n_num = math.floor(n/sum)
n_amari = n%sum

result = 0

if a != 0:
    result = a*n_num
    if n_amari != 0 and n_amari < a:
        result += n_amari
    elif n_amari != 0 and n_amari > a:
        result += a
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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


def count_num_of_blue():
    global N, A, B

    total = 0
    division = int(N / (A+B))
    remainder = int(N % (A+B))
    if division > 0:
        total += A * division

    if remainder < A:
        total += remainder
    else:
        total += A

    print(total)


count_num_of_blue()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
N = a[0]
A = a[1]
B = a[2]

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

print(ans)

Submission status: Accepted

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

block = a + b

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

number = n // block

remaining = n - number*block

print(number*a + min(a, remaining))

Submission status: Accepted

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

m = n % (a + b)

if (m <= a):
    v = m
else:
    v = a

print(int(n / (a + b)) * a + v)

Submission status: Accepted

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

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

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())
if N <= A:
    print(N)
else:
    if N <= (A+B):
        print(A)
    else:
        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:
import math

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:
N,A,B = map(int,input().split())
RepNum = int(N/(A+B))
Atotal = A * RepNum
amari = N-RepNum*(A+B)
if amari > 0:
  if amari >= A:
    amari = A
print([0,Atotal + amari][A!=0])

Submission status: Accepted

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

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

Submission status: Accepted

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

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

m=c*a
if d>a:
    m+=a
else:
    m+=d

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,A, B = map(int, input().split())

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

if mod<A:
    Y=mod
else:
    Y=A

print(X+Y)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n, a, b = i2()

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

Submission status: Accepted

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

Submission status: Accepted

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

if A==0:
    print(0)
    exit()
else:
    b=N//(A+B)
    x=N%(A+B)

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

Submission status: Accepted

Solution code:
import math

if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ret =  math.floor(N / (A + B)) * A
    if N % (A + B) >= A:
        ret = ret + A
    else:
        ret = ret +  N % (A + B)
    print(ret)

Submission status: Accepted

Solution code:
line = input().rstrip().split(' ')
n = int(line[0])
a = int(line[1])
b = int(line[2])

i = 0
ans = 0

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,a,b = na()

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

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

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

Submission status: Accepted

Solution code:
import sys
 
N, A, B = map(int,input().split())
 
ans = 0
 
if N < A:
  print(N)
  sys.exit()
 
if N < A+B:
  print(A)
  sys.exit()
 
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:
N, B, R = map(int, input().split())

ans = (N // (B+R)) * B
rest = N % (B+R)

if rest <= B:
  print(ans+rest)
else:
  print(ans+B)

Submission status: Accepted

Solution code:
n, a, b = input().split()
N, A, B = int(n), int(a), int(b)

q, mod = divmod(N, A+B)
ans = q*A + min([A, mod])

print(ans)

Submission status: Accepted

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

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

if (rest > A):
    result = A*(num_move+1)
else:
    result = A*num_move+rest

print(result)

Submission status: Accepted

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

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

print(a*A+b)

Submission status: Accepted

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

c = n // (a + b)
d = n - (a+b) * c
ans = a * c

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = list(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())
period = A + B
times = N//period
k = N%period
N =  A if k >A else k
print(times*A + N)

Submission status: Accepted

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

Submission status: Accepted

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

print(x*A + add)

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Sat Mar  7 12:01:50 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
 
from math import ceil
 
N, A, B = na()
C = N % (A + B)
if C == N:
    print(min(A, N))
else:
    print(A * (N // (A + B)) + (C if C <= A else A))

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
if a==0 and b==0:
    print(0)
    exit()
if n<=a:
    print(n)
elif n<=a+b:
    print(a)
else:
    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:
import math
n,a,b = map(int,input().split())
hako = a+b
hako_include = math.floor(n/hako)

nokori = n-hako_include*hako
if nokori >= a:
  print(hako_include*a + a)
else:
  print(hako_include*a + nokori)

Submission status: Accepted

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

Submission status: Accepted

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

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

sum = 0

if n <= a:
    sum = n

elif n <= (a + b):
    sum = a

else:
    p = n // (a + b)
    sum += a * p
    n -= p * (a + b)

    if n <= a:
        sum += n

    elif n <= (a + b):
        sum += a


#出力
print(sum)

Submission status: Accepted

Solution code:

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

    span_len = A+B
    # span中に何回繰り返しがあるか
    span_count = N // span_len

    span_remain = N % span_len
    # print(span_count, span_remain)
    if (span_remain == 0) :
        ans = span_count * A
        print(ans)
    elif (span_remain < A) :
        ans = span_count * A + span_remain
        print(ans)
    else :
        ans = span_count * A + A
        print(ans)


main()

Submission status: Accepted

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


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

x = n // (b + r)

if n % (b + r) > b:
    print(x * b + b)
   
else:
    print((x * b) + (n % (b + r)))

Submission status: Accepted

Solution code:
n,a,b = input().split()
N = int(n)
A = int(a)
B = int(b)

sum = A + B
yakusuu = int(N / sum)
amari = N % sum
num = 0

if amari >= A:
    num = A
else:
    num = amari

ans = (yakusuu*A) + num

print(ans)

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 + A)
else:
    print(C*A + D)

Submission status: Accepted

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

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

if y >= A:
    x += A
else:
    x += y

print(x)

Submission status: Accepted

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

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

flg = True
if A == 0:
    print(0)
    flg = False

if B == 0:
    print(N)
    flg = False

if flg:

    zentai_num = N // (A + B)
    zentai_b = zentai_num * A

    # print(zentai_b)
    amari_num = N % (A + B)


    amari_b = 0
    if amari_num >= A:
        amari_b = A
        # print(amari_num,A,amari_b)
    else:
        amari_b = amari_num

    # print(amari_b)

    # amari_b = max(amari_num - B,0)

    # print(amari_num,amari_b)

    print(zentai_b + amari_b)

Submission status: Accepted

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

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

if a == 0:
    print(a)
elif mod >= a:
    print((a*q)+a)
elif mod < a:
    print((a*q)+mod)

Submission status: Accepted

Solution code:
char = input().split(" ")
n = int(char[0])
blue = int(char[1])
red = int(char[2])

num = blue + red

ans = n // num

res = n % num

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

Submission status: Accepted

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

c = a + b
num = int(n / c) * a
if (n % c) <= a:
  num = num + (n % c)
else:
  num = num + a

print(num)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    blue = (N // (A+B)) * A

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

    return blue


print(main())

Submission status: Accepted

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

s = q * A

if mod - A > -1:
    print(s + A)
else:
    print(s + mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
k = a + b
i = 0
res = 0

y = n // k  
res += y * a

x = k * y

if x + a <= n:
    res += a
elif x + a > n:
    res += n - x
    
print(res)

Submission status: Accepted

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

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

if A>=N:
    print(N)
else:
    if A+B>=N:
        print(A)
    else:
        s, a = divmod(N, A+B)
        print(s*A+min(A, a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c=map(int,input().split())
list=[]
a_true=a//(b+c)
a_true2=a%(b+c)
k=b*a_true
if b>=a_true2:
  k+=a_true2
  print(k)
else:
  k+=b
  print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

q, mod = divmod(n, a + b)

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

Submission status: Accepted

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