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

Submission status: Accepted

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

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

if n % (a + b) == 0:
  print(a * s)
else:
  rem = n % (a + b)
  if rem <= a:
    ans = a * s + rem
  else:
    ans = a * s + a
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b =map(int, input().split())
ans=0
if n%(a+b)==0:
    ans=n//(a+b)*a
elif n%(a+b)>0 and 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 = list(map(int, input().rstrip().split()))

remainder=N%(A+B)

if remainder <= A:
  cnt = ( N//(A+B) )*A + remainder
else:
  cnt = ( N//(A+B) )*A + A
  
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8

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

part = n//(a+b)
aa = a*part
rest = n%(a+b)
if rest >= a:
    print(aa+a)
else:
    print(aa+rest)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, b, r = map(int,input().split())
count = math.floor(n / (b + r))
amari = n % (b + r)
print(count * b + min(b, amari))

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
# end=True
# while end:
#     if n>=a:
#         n-=a
#         ans+=a
#         if n>b:n-=b
#         else:end=False
#     else:
#         ans+=n
#         end=False

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

Submission status: Accepted

Solution code:
n, a, b = input().split() # a = blue, b = red
n, a, b = int(n), int(a), int(b)

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

Submission status: Accepted

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

c = n // (a+b)

res = c*a +(n%(a+b) - max(n%(a+b) - a ,0))

print(res)

Submission status: Accepted

Solution code:
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, A, B = MAP()



sets = N // (A+B) 
remain = N % (A+B)

blues = sets * A + min(remain, A)
print(blues)

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20


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

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

Submission status: Accepted

Solution code:
#R,B

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

#print N,A,B

matmari = A + B

times = N / matmari

#print times , matmari

amari = (N - matmari * times)

if amari > A:
    remain = A
else:
    remain = amari

print (times * A) + remain

Submission status: Accepted

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

Submission status: Accepted

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

br = b + r

a = int(n / br)
a_ = n % br

print(a * b + (b if a_ >= b else a_))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

# print(N, A, B)

f1 = N // (A + B) * A
# print(f1)
f2 = N % (A + B)
# print(f2)

if f2 > A:
  print(f1 + A)
else:
  print(f1 + f2)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = n //(a+b)

if n%(a+b) >= a:
  ans2 = a
elif n%(a+b) <a:
  ans2 = n%(a+b)
  
  
print(ans*a+ans2)

Submission status: Accepted

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

if a==0:
    print("0")
    exit()
elif b==0:
    print(n)
    exit()

t1=(n//(a+b))
t2=(n%(a+b))

if t2>a:
    print((t1*a)+a)
else:
    print((t1*a)+t2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def conv(a):
    for i in range(len(a)):
        a[i] = int(a[i])
    return a
def main(n,blue,red):
    blueall = int(n/(blue + red))*blue
    n = n - (int(n/(blue + red))*(blue+red))
    if n >= blue:
        return blueall + blue
    else:
        return blueall + n
n,a,b = conv(input().split())
print(main(n,a,b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

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

    # k = n // (a+b): 完璧にループがおわったぶん
    # ここにあるBlueはa*k
    # n -( k*(a+b)) : 端数
    # ここにあるBlueはmin(n-(k*(a+b)), a)
    k = n // (a+b)
    eprint(k)
    eprint(min(n-(k*(a+b)), a))
    print(a*k + min(n-(k*(a+b)), a))
    return 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a, b , c = input().split()
ans = 0

n = int(a)
blue = int(b)
red = int(c)

if blue == 0:
  print("0")
elif red == 0:
  print(n)
else:
  if n%(blue+red) >= blue:
  	ans += (n//(blue+red))*blue + blue
  else:
  	ans += (n//(blue+red))*blue + n%(blue+red)
  print(ans)

Submission status: Accepted

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

c = a+b
S1 = n//c*a

S2 = n%c

if S2 > a:
    ans = a
else:
    ans = S2

print(S1+ans)

Submission status: Accepted

Solution code:
import math
a = input().split(" ")
res = int(a[0])
div = int(a[1])+int(a[2])
mult = math.floor(res/div)
plus = res%div
answer = int(a[1])*mult + min([plus,int(a[1])])
print(answer)

Submission status: Accepted

Solution code:
s=raw_input()
s=s.split(" ")
n=int(s[0])
a=int(s[1])
b=int(s[2])
q=n/(a+b)
r=n%(a+b)
if(r<a):print q*a+r
else:print (q*a+a)

Submission status: Accepted

Solution code:
n,a,b=[int(v) for v in input().split()]
try:
    loop=n//(a+b)
except:
    loop=0
try:
    remainder=n%(a+b)
except:
    remainder=0
print(loop*a+min(remainder,a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

alpha = A if mod >= A else mod

print(q * A + alpha)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f = [int(i) for i in input().split()]
n = f[0]
a = f[1]
b = f[2]

m = n // (a+b)
tmp = m * a
mod = n%(a+b)
print(tmp+min(mod,a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_extra = 0
amari = N%(A+B)
if amari > A:
  a_extra = A
else:
  a_extra = amari

goukei = N//(A + B)*A + a_extra
print(goukei)

Submission status: Accepted

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

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

if y > a:
  y = int(a)
  

print(int((x*a)+y))

Submission status: Accepted

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

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

AB = A + B

if AB == 0:
    print(0)
    sys.exit()

ans = A * (N // AB)
ans_mod = N % AB 

if ans_mod == 0:
    print(ans)
    sys.exit()

if ans_mod >= A:
    ans += A
elif ans_mod < A:
    ans += ans_mod

print(ans)

Submission status: Accepted

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

if a == 0:
  print(0)
else:
  c = n % (a+b)  
  d = min(c, a)

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

bl = int(n / (a + b))
m = n % (a + b)

if m >= a:
    m = a

r = (bl * a) + m
print(r)

Submission status: Accepted

Solution code:
n, a, b = [int(x) for x in input().split()]
if a == 0:
    print(0)
else:
    o = n // (a+b)
    r = n % (a+b)
    print(o*a + min(r, a))

Submission status: Accepted

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

def solve():
    N, A, B = list(map(int, input().split()))
    ans = (N//(A+B))*A
    N -= (N//(A+B))*(A+B)

    if A >= N:
        ans += N
    else:
        ans += A
    print(ans)



if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

D = N - (A+B) * C

if D > A:
    E = A
    F = D - A
else:
    E = D
    F = 0

ans = C * A + E

print(ans)

Submission status: Accepted

Solution code:
nab = list(map(int, input().split())) 
s=0

s  = nab[0]//(nab[2]+nab[1])*nab[1]
am = nab[0]%(nab[1]+nab[2])

if am>nab[1]:
    s +=  nab[1]
elif nab[1]==0 :
    s = 0
else:
    s+= am

print(int(s))

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
n = N // (A+B)
r = N - (A+B)*n

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

Submission status: Accepted

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

set_num = A + B
set_iter_num = N // set_num
r = N % set_num

if r >= A:
    r_blue = A
else:
    r_blue = r

blue = set_iter_num *  A + r_blue
print(blue)

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:
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
import bisect
import heapq as hq

def main():
    try:
        n,a,b=In()
        temp=a+b
        t=n//temp
        t=(a*t)
        n=n%temp
        if n<=a and n>0:
            t+=(n)
        elif n>a:
            t+=(a)
        print(t)
    except:
        pass
def add(a, b, c):
    res = a + b;
    if (res >= c):return res - c;
    else:return res;
def mod(a, b, c):
    res = a * b
    if (res >= c):return res % c
    else:return res
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    w = a // gcd(a, b)
    return w * b
def expo(a, b):
    x, y = 1, a
    while (b > 0):
        if (b & 1):
            x = x * y
        y = y * y
        b >>= 1
    return x
def power(a, b, m):
    x, y = 1,
    while (b > 0):
        if (b & 1):x = mod(x, y, m)
        y = mod(y, y, m)
        b >>= 1
    return x
def L():
    return list(map(int, stdin.readline().split()))
def In():
    return map(int, stdin.readline().split())
def I():
    return int(stdin.readline())
P = 1000000007


if __name__ == '__main__':
    main()

Submission status: Accepted

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

num_ball = A + B
sets = N // (A + B)

# print(f"N:{N} A:{A} B:{B} num_ball:{num_ball} sets:{sets}")

last_balls = min(A, N % num_ball)

result = sets * A + last_balls

print(result)

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    count = int(N/(A + B))
    print(A * count + min(N-(A+B)*count, A))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

C = A + B

ans = 0

syou = N // C
amari = N % C

ans = syou * A


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

Submission status: Accepted

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

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b:
        a, b = b, a%b
    return a

def lcm(a: int, b: int):
    return a * b // gcd(a, b)


def main():
	N,A,B = map(int, input().split())
	#S = input().rstrip()
	#vA = list(map(int, input().split()))
	#vX = [input().rstrip() for _ in [0,]*N]
	
	C = A+B

	res = 0
	
	if N<C:
		res = min(A,N)
	else:
		res = (N//C) * A
		res += min(N%C, A)
	
	#res = "No" if (S=="AAA" or S=="BBB") else "Yes"
	#res = -(-N//M)
	#res = gcd(N,M)
	print(res)
	
if __name__ == "__main__":
    main()

Submission status: Accepted

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

#print(N,A,B)

if A == 0 and B == 0:
    ans = 0
else:
  sho = N // (A+B)
  mod = N % (A+B)
  if mod > A:
  	ans = A * sho + A
  else:
  	ans = A * sho + mod

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

Submission status: Accepted

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

k = int(n / (blue + red))
kk = n % (blue + red)
print(k*blue + min(blue, kk))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N,A,B = (int(x) for x in 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:
N, A, B = map(int, input().split())
print(A*(N//(A+B))+min(A,N-(A+B)*(N//(A+B))))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

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

print(result)

Submission status: Accepted

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

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

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

print(int(res))

Submission status: Accepted

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


d = a[1]*b + e

print(d)

Submission status: Accepted

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

cnt = int(N / (A + B))
rest = N % (A + B) 
if A == 0:
    print(0)
elif rest > A:
    print(cnt*A + A)
else:
    print(cnt*A + rest)

Submission status: Accepted

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

waru = n // (a + b)

amari = n % (a + b)

ans = a * waru

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

if a == 0:
    print(a)
else:
    print(ans)

Submission status: Accepted

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

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

if mod >= a:
    ans = num * a + a
elif mod < a:
    ans = num * a + mod

print(ans)

Submission status: Accepted

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

u = n // (a+b)
z = n % (a+b)
c = u * a
if a > z:
    ans = c + z
else:
    ans = c + a

print(ans)

Submission status: Accepted

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

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

ans = A*r

if s <= A:
    ans += s
elif s > A:
    ans += A


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 157: B (2020/03/07)
N, A, B = map(int, input().split())
X = N // (A+B)
Y = N %  (A+B)
if Y > A:
    print(A*X+A)
else:
    print(A*X+Y)

Submission status: Accepted

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

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

loops = n // (a + b)
ans = loops * a
remain = n - loops * (a + b)

if remain <= a:
    ans += remain
else:
    ans += a

print(ans)

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:
#for _ in range(int(input())):
n,a,b = input().split(' ')
n = int(n)
a = int(a)
b = int(b)

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

Submission status: Accepted

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

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

if D >= A:
    ans += A
else:
    ans += D
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    x = N // (A+B)
    r = N % (A+B)

    ans = A * x + r
    if r >= A:
        ans -= (r - A)

    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

x = n // (a+b)
c = a * x
n -= (a+b)*x
while n > 0:
    n = n - a
    if n > 0:
        c += a
    else:
        c += a+n
    n = n - b
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

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

if(irest>A):
    print((i+1)*A)
else:
    print(i*A+irest)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    dev = N // (A+B)
    rem = N % (A+B) if N % (A+B) <= A else A
    return A*dev + rem


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(N, A, B))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b = [int(x) for x in input().split()]
answer = n//(a+b)*a
if n%(a+b) < a:
  answer = answer + n%(a+b)
elif n%(a+b) >= a:
  answer = answer + a
print(answer)

Submission status: Accepted

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

d = n // (a + b)
mod = n % (a + b)
# print(d, mod)

ans = a * d

# print(ans, a, mod)

if a >= mod:
    # print(a, mod)
    ans += mod
else:
    ans += a

print(ans)

Submission status: Accepted

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

#if a+b > n:
#    print(a)
#    exit()

taba = a+b

sho = n//taba
amari = n%taba
if amari >= a:
    amari = a
else:
    amari = amari
ans = sho*a + amari

print(ans)

Submission status: Accepted

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

repeat_num = n // (a+b)
bluenum = repeat_num*a
if a != 0:
  over = (n - (a+b)*repeat_num)
  if over > a:
    bluenum += a
  else:
    bluenum += over
print(bluenum)

Submission status: Accepted

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

Submission status: Accepted

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

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

amari = N%(A+B)

if amari > A:
    print(A*div + A)
else:
    print(A*div + amari)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

res = 0
if N >= (A + B) * pow(10, 100):
  print(A * pow(10, 100))
else:
  tmp1 = N // (A + B) * A
  if N % (A + B) >= A:
    tmp2 = A
  else:
    tmp2 = N % (A + B)

print(tmp1 + tmp2)

Submission status: Accepted

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

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


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


all_set, mod_ = divmod(N, (A+B))
#print(all_set, mod_)
if mod_ == 0:
	print(all_set*A)
elif mod_ - A >= 0:
	print(all_set*A + A)
else:
	print(all_set*A + mod_)

Submission status: Accepted

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

q, m = divmod(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())
x = n//(a+b)
y = n%(a+b)
if y < a:
	print(x*a+y)
else:
	print(x*a+a)

Submission status: Accepted

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

if A == 0 and B == 0:
    cnt = 0
    print(cnt)
elif A != 0 or B != 0:
    m = N // (A+B)
    n = N % (A+B)

    cnt = A * m
    if n <= A:
        cnt += n
    elif n > A:
        cnt += A
    print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N, A, B = map(int,input().split())
N,A,B=int(N),int(A),int(B)
AB=A+B
x=int(N/AB)
y=int(N%AB)
if y>=A:
    print(A*x+A)
else:
    print(A*x+y)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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

Submission status: Accepted

Solution code:
# Problem B

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

# initialization
num_sa = N // (A+B)
num_amari = N % (A+B)

# process
ans_1 = num_sa * A
if num_amari>A:
    num_amari = A
ans_2 = ans_1 + num_amari

# output
print(ans_2)

Submission status: Accepted

Solution code:
import math
import sys


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

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

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

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

Submission status: Accepted

Solution code:
import sys
#import math
#import numpy as np
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
N,a,b= map(int,input().split())
ans=0
ju=0
ans=N%(a+b)
ju=N//(a+b)
if ans<=a:
  print(a*ju+ans)
else:
  print(a*ju+a)

Submission status: Accepted

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

sum = 0
if a == 0:
  print(0)
elif n <= a:
  print(n)
elif int(n / (a + b)) == 0:
  print(a)
else:
  nn = int(n / (a + b))
  na = n % (a + b)
  sum = nn * a + min(na,a) 
  print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def count_ball(n, a, b):
    if n%(a+b) < a:
        print((n//(a+b))*a + n%(a+b))
    else:
        print((n//(a+b))*a + a)

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

count_ball(n, a, b)

Submission status: Accepted

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

S = N // (A + B)
n = N - S * (A + B)

if n >= A:
  n_a = A
else:
  n_a = n

print(S * A + n_a)