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:
#!/usr/bin/env python3
import sys


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

c = A+B

ans = N//(c)*A

if N%c > A:
    ans += A
else:
    ans += N%c

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a,b = [int(i)for i in input().split()]
cycles = n//(a+b)
remain = n%(a+b)
ans = cycles*a+min(remain,a)
print(ans)

Submission status: Accepted

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

C = A + B

if N - (N//C)*C >= A:
  D = (N//C)*A + A
else:
  D = (N//C)*A + N - (N//C)*C
print(D)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
Q = N // (A + B)
R = N % (A + B)
if R > A:
    R = A

print(Q * A + R)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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


# 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:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, a, b = rli()
    p = n // (a+b)
    ans = p*a+min(n%(a+b), a)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

total= n//(blue+red)*blue

if n%(blue+red)>=blue:
  total+= blue
else:
  total+= n%(blue+red)

print(total)

Submission status: Accepted

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

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

res = div * A
if mod_val <= A:
    res += mod_val
else:
    res += A

print(res)

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    count = 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:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

n, a, b = input_nums()

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

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

Submission status: Accepted

Solution code:
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

mod=10**9+7
#N=int(input())
N,A,B=map(int,input().split())
#A=list(map(int,input().split()))


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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

#import sys
#sinput = sys.stdin.readline

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

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

Submission status: Accepted

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

num = A + B
q, mod = divmod(N, num)
print(A * q + mod if mod <= A else A * (q + 1))

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 += mod
else:
  ans += A
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if mod > A:
    print(shou*A+A)
else:
    print(shou*A+mod)

Submission status: Accepted

Solution code:
from sys import stdin

n, a, b = (int(x) for x in stdin.readline().rstrip().split())
c = a + b
if n % c <= a:
    print((n//c)*a + n%c)
else:
    print((n//c)*a + a)

Submission status: Accepted

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

Submission status: Accepted

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

val =  N // (A+B)
left = N % (A+B)

ans = val * A

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

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

x = N % (A+B)

res += min(x, A)

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(i) for i in input().split()]
res = a * (n // (a+b)) + min(a, n % (a+b))
print(res)

Submission status: Accepted

Solution code:
from sys import stdin
n,a,b = map(int,stdin.readline().rstrip().split())
c = n//(a+b)
d = n%(a+b)
if d > a:
    print(a*(c+1))
else:
    print(a*c+d)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# print(N, A, B)

Sum = A+B

rep = N//Sum

remain = N%Sum


# print(rep, remain)


ad = 0
if A <= remain:
    ad = A
else: ad = remain

result = rep*A + ad
print(result)

Submission status: Accepted

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

if B == 0:
	print(N)
else:
	n = N//(A+B)
	ans = A*n
	ans += min(N%(A+B),A)
	print(ans)

Submission status: Accepted

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

ans = 0

C = A + B
D = N // C
E = N % C

ans += D * A

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

Submission status: Accepted

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

Submission status: Accepted

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

    div = int(N / (A+B))
    sub = N - (A+B)*div

    ans = div*A
    if sub <= A:
        ans += sub
    else:
        ans += A
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, a, b = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

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

units = n//(a+b)
unitsblue = units*a
amari = min(n%(a+b), a)

print(unitsblue+amari)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

resolve()

Submission status: Accepted

Solution code:
# li = [[0] * 4 for i in range(3)]

# A = list.map(int, input().split())


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

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math as m

def main(**kwargs):
    q = n // (a + b) 
    r = n % (a + b)

    if r < a:
        res = q * a + r

    else:
        res = q * a + a
        
    return res

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, a, b, *_ = cin

    cout = main(n=n, a=a, b=b)
    print(cout)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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())
AB = A+B
sp_num = N//AB
ans = A*sp_num + min(A,(N - AB*sp_num))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

#A個のbとB個のrを並べる操作を10^100回行って前からN個数に何個bがあるか

times = A + B

quo = N // times
rem = N % times

if rem >= A:
    print(quo*A + A)
else:
    print(quo*A + rem)

Submission status: Accepted

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

ans = int(n / (b + r)) * b
if n % (b + r) < b:
    ans += n % (b + r)
else:
    ans += b
print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
# @Time    : 2020/3/1 19:59
# @Author  : DIRICHLET
# @File    : main.py
a=[]
def myin(fun=int):
    global a
    a=list(map(fun,input().split()))
#myin(int)
myin()
print(a[0]//(a[1]+a[2])*a[1]+min(a[0]%(a[1]+a[2]),a[1]))
#print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, A, B = (int(i) for i in input().split())
    ans = (N//(A+B)) * A
    less = N - (N//(A+B)) * (A+B)
    print(ans + min(less, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if __name__=='__main__':
  main()

Submission status: Accepted

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

c = a + b

s = n // c
s *= a

_s = n % c
if _s >= a:
    s += a
else:
    s += _s

print(s)

Submission status: Accepted

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

x = n // (a+b)
y = n - x * (a+b)

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

Submission status: Accepted

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

ab = a + b

cnt = n // ab
r = n % ab

if a < r:
    r = a

ans = a * cnt + r
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


if l >= A:
    t = A
else:
    t = l

print(m * A + t)

Submission status: Accepted

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

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

n,a,b = input_multiple_number()

pattern = n //(a+b)
blue = pattern*a
red = pattern*b

rest = n%(a+b)

if rest <= a:
    blue += rest
else:
    blue += a
    red += (rest-a)

print(blue)

Submission status: Accepted

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

Submission status: Accepted

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






print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math

def fast_comb(a,b,mod):
    up = reduce(lambda x,y: x*y%mod, range(a,a-b,-1))
    down = reduce(lambda x,y: x*y%mod, range(1,b+1))
    return (up * pow(down, mod-2, mod)) % mod

def prime(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return is_prime

def readlines(n):
    for _ in range(n):
        map(int, input().split())
        yield

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

    base = (n//(a+b)) * a
    plus = min(n % (a+b), a)

    print(base + plus)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = [int(i) for i in input().split()]
quotient = n // (a+b)
remainder = n % (a+b)
ans = quotient * a + min(remainder, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s=N%(A+B)
if s<=A and s!=0:
  print(s+A*(N//(A+B)))
elif s!=0:
  print(A*(1+N//(A+B)))
else:
  print(A*(N//(A+B)))

Submission status: Accepted

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

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

if A == 0:
    print(0)
elif amari >= A :
    print(sho*A + A)
else:
    print(sho*A + amari)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, A, B):
    m = N // (A+B)
    n = N % (A+B)
    if n < A:
        return A * m + n
    return A * m + A


if __name__ == "__main__":

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

    print(ans)

Submission status: Accepted

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

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

if m > a:
    i = a
else:
    i = m

print(q*a+i)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, A, B = LI()
    cnt = 0
    cnt += (N // (A+B)) * A
    rem = N - (A+B) * (N//(A+B))
    if rem >= A:
        cnt += A
    else:
        cnt += rem
    print(cnt)

main()

Submission status: Accepted

Solution code:
#!python3.4
# -*- coding: utf-8 -*-
# abc158/abc158_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, A, B = i2nn()
    q, mod = divmod(N, A+B)
    blue_sum = q * A + min(mod, A)
    print(blue_sum)
    return

main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from functools import lru_cache
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
d, m = divmod(n, a + b)
ans = d * a + min(m , a)
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:
    ans = q * A + A
else:
    ans = q * A + r

print(ans)

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    print(A * (N // (A+B)) + min(A, N % (A+B)))
    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:
length, blue, red = [int(x) for x in input().split(' ')]

pair_count = int(length / (red + blue))

print(pair_count * blue + min(blue, length - pair_count * (red + blue)))

Submission status: Accepted

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

ab = A + B
num = N//ab
r = N - num*ab

if(r <= A):
  print(A*num + r)
else:
  print(A*num + A)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def LI(): return [int(x) for x in sys.stdin.readline().split()]


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


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    S = input()
    if S == 'AAA' or S == 'BBB':
        print('No')
    else:
        print('Yes')
    return


# B
def B():
    N, A, B = LI()
    ans = N // (A + B) * A + min(N % (A + B), A)
    print(ans)
    return


# C
def C():

    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    B()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = a + b
c_count = n // c
rest = n - c_count * c

print(c_count * a + min(rest, a))

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n,a,b=map(int,input().split())
  print(a*(n//(a+b))+min(n%(a+b),a))
  
if __name__=='__main__':
  main()

Submission status: Accepted

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

syo, amari = n // (a+b), n % (a+b),

plus = min(amari, a)

print(syo*a + plus)

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())
c = n % (a+b)
if b == 0:
    print(n)
else:
    k = n // (a+b)
    l = n % (a+b)
    print(a*k+min(l, a))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    n,a,b = map(int,input().split())
    c_1 = (n // (a + b)) * a
    p = n % (a + b)
    c_2 = min(p,a)
    print(c_1+c_2)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = int(N // (A + B)) * A
mod = N % (A + B)

ans += min(A, mod)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

CB = C * A
DB = min(D, A)

print(CB+DB)

Submission status: Accepted

Solution code:
def main(n,a,b):
    x = a+b
    q,mod = divmod(n,x)
    res = (q*a) + (a if a<=mod else mod)
    return res

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