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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from sys import stdin

n, a, b = [int(x) for x in stdin.readline().rstrip().split()]

result = int(n / (a + b)) * a
temp = n % (a + b)

if temp > a:
    result += a
else:
    result += temp

print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n,blue,red = [int(a.strip()) for a in input().strip().split(' ')]
    length = blue + red
    a= n / length
    sho = int(a)
    amari = n % length

    if amari >= blue:
        chibi = blue
    else:
        chibi = amari
        
    print(sho*blue+chibi)

Submission status: Accepted

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

last = n % (a + b)
if last > a:
    last = a

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

print(loop * a + last)

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

count = A + B
hoge1 = N // count
hoge2 = N % count

ans1 = A * hoge1

if hoge2 < A:
    print(ans1 + hoge2)
else:
    print(ans1 + A)

Submission status: Accepted

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

Submission status: Accepted

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

nab = 0
if N % AB != 0:
    nab = N % AB
    nab = nab if nab < A else A

print(((N // AB) * A) + nab)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

number, blue, red = map(int, input().split())

many = math.floor(number / (blue + red))

count = many * blue

number = number - (blue + red)*many

if number <= blue:
    count += number
else:
    count += blue

print(count)

Submission status: Accepted

Solution code:
import math

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

mod = N % (A+B)
n = math.floor(N/(A+B))

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

print(a*q + aaa)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if A == 0:
  print(0)
else:
  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,b,r = map(int, input().split())		# 5 7 2

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

number_blue = A * (N // value_size)
## print(number_blue)

resid = N % value_size
## print(resid)

if resid > A:
    resid = A
print(number_blue + resid)

Submission status: Accepted

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

tot = A+B

if N%tot > A:
    print(N//tot * A + A)
else:
    print(N//tot * A + N%tot)

Submission status: Accepted

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

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

len = A + B
c = int(N/len)
m = N%len
sum = c * A

if A < m:
    sum += A
else:
    sum += m
print(sum)

Submission status: Accepted

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

ab = a+b

i = 0

r = n//ab
m = n%ab

if m>a:
  m=a

ans = a*r + m

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

X = N // (A+B)

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

print(X*A+Y)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.buffer.readline

def inn(func=int):
    return list(map(func,input().split()))

def ins():
    return input().split()

n,a,b = inn()
mon = int(n/(a+b))
las = n%(a+b)
print(mon*a+min(las,a))

Submission status: Accepted

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

full_a = n // (a+b)
n_r = n % (a+b)
rest_a = min(n_r,a)

print(full_a*a+rest_a)

Submission status: Accepted

Solution code:

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

if y <=a:
    z=y
else:
    z=a

print(x*a+z)

Submission status: Accepted

Solution code:
import math

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

X = math.floor(N/(A+B))
Y = N%(A+B)

if(Y>A):
  print(X*A+A)
else:
  print(X*A+Y)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n,a, b = map(int, input().split())
    sum = 0
    if (a+b)*10 ** 100 > n:
        mod = n %(a+b)
        ans = n // (a+b)
        sum = ans * a
        if mod > a:
            sum =sum + a
        else:
            sum = sum + mod
    else:
        sum = b * (10 ** 100)
    print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Blue = 0
Blue += A*(N//(A+B))

amari = N%(A+B)
if(amari < A ):
    Blue += amari
else:
    Blue += A

print(Blue)

Submission status: Accepted

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

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

ans += X*A+min(A,Y)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

times = math.floor(N / (A+B))

amari = N - times * (A + B)
if amari > A:
  amari_a = A
else:
  amari_a = amari 

print(times * A + amari_a)

Submission status: Accepted

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

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 = [int(item) for item in input().split()]

unit_num = A + B

unit_b = (N // unit_num) * A

temp_num = min(A, N % unit_num)

print(unit_b + temp_num)

Submission status: Accepted

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

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

Submission status: Accepted

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

c = a+b

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

print(ans)

Submission status: Accepted

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

def main():
    n, a, b = map(int, input().split())
    c = n // (a + b)
    n -= (a + b) * c

    count = a * c

    if n < a:
        count += n
    else:
        count += a

    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

c = a + b
m = n % c
mn = n // c

if m > a:
    result = mn * a + a
else:
    result = mn * a + m
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, a, b) = [int(e) for e in lines[0].split(" ")]

    return (n, a, b)


def solve(n, a, b):

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

    d = min([r, a])
    
    result = c*a + d

    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Accepted

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

    print(sum_blue)

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

waku = n//(a+b)
amari = n % (a+b)
kisu = waku * a

if amari >= a:
    print(kisu + a)
elif amari < a:
    print(kisu + amari)

Submission status: Accepted

Solution code:
info = [int(i) for i in input().split()]
print(int(info[0]/(info[1]+info[2]))*info[1] + min(info[1], info[0]%(info[1]+info[2])))

Submission status: Accepted

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

times, m = divmod(N, A + B)

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

Submission status: Accepted

Solution code:
#At coder 2020/3/8 B
#import collections

I = list(map(int, input().split())) 
N=I[0]
A=I[1]
B=I[2]
K=N%(A+B)
L=N//(A+B)
ans=A*L+min(A,K)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
div, mod = divmod(n, (a+b))
print(div*a + [mod, a][mod > a])

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

AB = A+B

if AB >= N:
    if A <= N:
        print(A)
    else:
        print(N)
else:
    amari = N % AB
    if amari > A:
        ans = A * (N//AB) + A
    else:
        ans = A* (N//AB) + amari
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

# List of ints
def LI(): return list(map(int, sys.stdin.readline().split()))

# Single int
def I(): return int(sys.stdin.readline())

# List, which contains Lists of chars (not strings)
def LS():return list(map(list, sys.stdin.readline().split()))

# Single List of chars (not strings)
def S(): return list(sys.stdin.readline())[:-1]

# List of "n" integers from "n" lines.
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
# List of "n" Lists of integers
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l


# Runtime Complexity: O(?)
# Space Complexity: O(?)
# Solution
N, blue, red = LI()

blue_red_count = N // (blue + red)
blue_balls = blue_red_count * blue

remaining = N - blue_red_count * (blue + red)
blue_balls += min(remaining, blue)
print(blue_balls)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())
r1 = n // (a+b)
r2 = min(n % (a+b), a)

print(a * r1 + r2)

Submission status: Accepted

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

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

if n%(a+b) < a:
    count += n%(a+b)
else:
    count += a

print(count)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
a, r = divmod(N, A+B)
ans = a * A
#print(a * A + max(r - B, 0))
if r > A:
    ans += A
else:
    ans += r
print(ans)

Submission status: Accepted

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

c = 0
c = n//(a+b)
mod = n%(a+b)

ans = c*a
if mod > a :
  print(ans + a)
else :
  print(ans + mod)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
N, A, B = map(int, input().split())
sum = 0
sum += (N//(A+B))*A
sum += min(A, N%(A+B))

print(sum)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N,A,B = map(int, input().split())
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:
def main():
    n, a, b = map(int, input().split(" "))
    if a == 0:
        print("0")
        return
    count = (n // (a + b))
    ans = count * a
    if count * (a + b) != n:
        remain = n - (count * (a + b))
        if remain < a:
            ans += remain
        else:
            ans += a
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(c + e)

Submission status: Accepted

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

Submission status: Accepted

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

paired = blue + red

ans = (limit // paired) * blue
additional = limit % paired

ans += min(additional, blue)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, A, B = read_int()

def solve():
    ans = (N // (A + B)) * A
    r = (N % (A + B))
    ans += r if r < A else A
    return ans

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

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,a,b = inm()
c = a+b
k = n//c
r = n%c
print(k*a + min(r,a))

Submission status: Accepted

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

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

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

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 = list(map(int, input().split()))

P = N // (A + B)
Q = min(N % (A + B), A)

print(P * A + Q)

Submission status: Accepted

Solution code:
n, a, b = map(int,input().split())
q, mod = divmod(n, a+b)
ans = a*q + min(a, mod)
print(str(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:
n,a,b=map(int,input().split())
ans=0
ans=n//(a+b)*a
n%=a+b
if(n>a):
    ans+=a
else:
    ans+=n

print(ans)

Submission status: Accepted

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

cnt = int(n//(a+b))
res = int(n%(a+b))
if res <= a:
    print(cnt*a+res)
else:
    print((cnt+1)*a)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

x1 = N // (A+B) * A
mod = N % (A+B)

print(x1 + mod) if mod < A else print(x1 + A)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
m1 = n // (a + b)
m2 = n - m1 * (a + b)

if m2 == 0 or m2 <= a:
    print(m1 * a + m2)
else:
    print(m1 * a + a)

Submission status: Accepted

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

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

if (N - (repeat * (A + B))) <= A:
    print(repeat * A + (N - (repeat * (A + B))))
else:
    print((repeat + 1) * A)

Submission status: Accepted

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

Submission status: Accepted

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

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

result = waru * A

if(amari > A):
  result += A
else:
  result += amari

print(result)

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

d, m = divmod(N, (A+B))
ans = 0
# print(d)
# print(m)
if m >= 0:
    if m <= A:
#         print(d)
#         print(A)
#         print(m)
        ans = d*A + m
    else:
        ans = d*A + A
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

count = 0
t1 = (N // (A + B)) * A
t2 = N % (A + B)

count += t1
count += min(t2, A)

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

rb = a[1] + a[2]
n = a[0] // rb
n = n * a[1]
m = a[0] % rb
if m > a[1]:
  l = a[1]
else:
  l = m

#print(l)
#print(n)
print(n+l)

Submission status: Accepted

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

c = a + b
ama = N % c
times = N // c

if ama > a:
    ama = a

ans = times * a + ama
print(ans)

Submission status: Accepted

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

if __name__=='__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

amari = N - syou*(A+B)

if amari <= A:
    answer = syou * A + amari
else:
    answer = syou * A + A

print(answer)

Submission status: Accepted

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

ans = 0

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

ans += set_count*A

nokori = N%(A+B)

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

print(ans)

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:

def main():
    n,blue,red = map(int,input().split())
    total = blue+red
    answer = 0
    answer += (n // total) * blue
    amari = min(blue,(n % total))
    answer += amari
    print(answer)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = div * a
if mod <=a:
    ans += mod
else:
    ans += a

print(ans)

Submission status: Accepted

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

t = a+b
q = n%t
p = (n-q)//t
print(min(a*p+q,a*p+a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    N, A, B = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

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

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


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """8 3 4"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8 0 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6 2 4"""
        output = """2"""
        self.assertIO(input, output)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

Solution code:
n, a,b = map(int,input().split())
num = n // (a + b)
if n % (a + b) == 0:
    ans = a * num
elif n % (a + b) >= a:
    ans = a * num + a
else:
    ans = a * num + n % (a + b)
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:
N, A, B = map(int, input().split())

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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