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

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

Submission status: Accepted

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

ab = a+b
c = n//ab
d = n%ab

ans = c*a + min(a,d)

print(ans)

Submission status: Accepted

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

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

if rem - a <= 0:
    print(a * num + rem)
else:
    print(a * num + a)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

times = n//(a+b)
rest = n - (a+b)*times
print(a*times+min(a,rest))

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
AB = A + B
kai = N // AB
amari = N % AB
# print(kai,amari)
if amari > A:
    nokori = A
else:
    nokori = amari
print(kai*A + nokori)

Submission status: Accepted

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

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

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

#print(sho,amari)

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

if amari < A:
    print(sho * A + amari)
else:
    print(sho * A + A)

Submission status: Accepted

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

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

    comp = n // (a + b)
    uncomp = n - comp * (a + b)

    ans = comp * a + min(a, uncomp)
    # print('comp:{}, uncomp:{}'.format(comp, uncomp))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

# process
t = N%(A+B)
if t > A:
    t = A

# output
print(N//(A+B)*A + t)

Submission status: Accepted

Solution code:
N,A,B=[int(i) for i in input().split(" ")]
ball=(N//(A+B))*A
if N%(A+B)>A:
    ball+=A
else:
    ball+=N%(A+B)

print(ball)

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
N = i[0]
A = i[1]
B = i[2]
Q = A + B
ans = (N // Q) * A + min(N % Q, A) 

print(ans)

Submission status: Accepted

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

set_count  = int(N/(A+B))
if  N % (A+B) != 0:
    ans = set_count * A
    last_ball = N - (A+B)*set_count
    if last_ball <= A:
        ans += last_ball
    else:
        ans += A
else:
    ans = set_count * A
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

amari = min(n,10**100)%(a+b)
wari = min(n,10**100)//(a+b)

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

Submission status: Accepted

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

    tmp = a+b
    ans = 0
    if n>=tmp:
        d = n // tmp
        m = n % tmp
        ans += d * a
        ans += min(a,m)
    else:
        ans += min(a,n)

    print(ans)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
n,a,b = [int(x) for x in stdin.readline().rstrip().split()]
s = a + b
k = n // s
m = n % s
m = min(a,m)
print(k*a + m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


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


def main():
    N, A, B = map(int, input().split())
    r = N // (A + B)
    l = N - r * (A + B)
    cnt = r * A
    if l < A:
        cnt += l
    else:
        cnt += A
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

else:
    print(n//(a+b)*a+a)

Submission status: Accepted

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

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

cnt = 0
cnt += syou * A

if (mod <= A):
    cnt += mod
else:
    cnt += A

print(cnt)

Submission status: Accepted

Solution code:
def main():
    N, A, B= [int(x) for x in input().split()]
    if A == 0:
        print(0)
        return

    count = N // (A + B)
    left = N % (A + B)
    blue = count * A
    blue += A if left >= A else left
    print(blue)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, A: int, B: int):
    p = N// (A + B)
    ans = p * A
    mod = N % ( A + B )
    if mod >= A:
        ans += A
    else:
        ans += mod

    print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if r == 0:
    print(A * q)
elif 1 <= r <= A:
    print(A * q + r)
else:
    print(A * (q + 1))

Submission status: Accepted

Solution code:
x,y,z= map(int,input().split())
M=y+z
k=x//M
j=x-M*k
if j>y:
    print((k+1)*y)
else:
    print(k*y+j)

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

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
blue=0
ans=[]
kouho=N//(A+B)
blue=A*kouho
if A-(N-(A+B)*kouho)>=0:
    blue+=N-(A+B)*kouho
else:
    blue+=A
print(blue)

Submission status: Accepted

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

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

ans = 0
if a == 0 and b == 0:
    print(ans)
    sys.exit(0)

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

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

print(ans)

Submission status: Accepted

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

total = A + B

blue = 0
blue += (N // total) * A
remain = min(N % total,A)
blue += remain

print(blue)

Submission status: Accepted

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, a, b = map(int, input().split())
ans = (n // (a + b)) * a
# print(ans)
if n % (a + b) != 0:
    ans += min(n % (a + b), a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N, A, B = MI()

if A == 0:
    print(0)
else:
    ans = N // (A + B) * A
    tmp = N % (A + B)
    if tmp >= A:
        ans += A
    else:
        ans += tmp

    print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

A_B = A + B
one_loop = min(N//A_B, 10**100)
ext = min(A, N%A_B)
SUM = one_loop*A + ext
print(SUM)

Submission status: Accepted

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

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

ans = kaisu * A

if amari < A:
  ans += amari
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:
    a, b = divmod(N, A+B)
    print(a*A + min(b, A))

Submission status: Accepted

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

S = A+B

P = N//S

Ans = P*A + min((N-S*P),A)

print(Ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[N,A,B] = [int(s) for s in input().rstrip().split(' ')]
m = N //(A+B) #商
k = N - m*(A+B) #余り
if k <= A:
  print(m*A + k)
else:
  print((m+1)*A)

Submission status: Accepted

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

Submission status: Accepted

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

tmp = (N//(A+B)) 
ans = tmp*A + min((N-tmp*(A+B)),A)
print(ans)

Submission status: Accepted

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

div = n // (a+b) * a
mod = n % (a + b)

if mod < a:
  s = div + mod
else:
  s = div + a

print(s)

Submission status: Accepted

Solution code:
d = input().split(" ")
n = int(d[0])
a = int(d[1])
b = int(d[2])
s = a + b
c = (n // s) * a
if n % s > a:
	c += a
else:
	c += n % s
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

if amari > a:
    print((temp + 1) * a)
else:
    print(temp * a + amari)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, A, B = [int(x) for x in stdin.readline().rstrip().split()]
    x = N // (A + B)
    y = N % (A + B)
    print(A * x + min(y, A))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = a*x

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
ans += x*A
ans += max(0, min(N-y, A))
print(ans)

Submission status: Accepted

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, a, b = gi()
ans = (n // (a + b)) * a + min(n % (a + b), a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# abc 158
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

answer = int((N / (A + B))) * A
amari = N % (A + B) 

if amari > A:
    answer += A
else:
    answer += amari

print(answer)

Submission status: Accepted

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

setb = N // (A+B)
amab = N % (A+B)

if amab <= A:
    print(setb*A + amab)
else:
    print(setb*A + A)

Submission status: Accepted

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

    if A == 0:
        print(0)
        return

    z = N % (A + B)

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


if __name__ == "__main__":
    main()

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:
import sys
n, a, b = map(int, input().split())

if n < a:
  print(n)
  sys.exit()

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

print(a * c + min(n, 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:
def main():
    n,a,b=map(int,input().split())
    k=n//(a+b)
    print(a*k+min(n%(a+b),a))
main()

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

Submission status: Accepted

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

if N % (A+B) > A:
    left = A
else:
    left = N % (A+B)
ans = (N // (A+B)) * A + left
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,A,B = MI()
	ans = (N//(A+B))*A
	tmp = N%(A+B)
	if(tmp>A):
		ans += A
	else:
		ans+= tmp

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

if y<=A:
    ans=x*A+y
else:
    ans=x*A+A

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

grouped = n // (a + b)
ungrouped = n % (a + b)

ans = grouped * a

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def Main(N, A, B):
    div = N // (A + B)
    res = N % (A + B)
    res2 = min(res, A)
    return div*A + res2
                     

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

base = syou*a
if amari<a:
    plus = amari
elif amari>=a:
    plus = a
print(base+plus)

Submission status: Accepted

Solution code:
# n=int(input())
# a=[int(i) for i in input().split()]
# a=[int(input()) for i in range(n)]
import math

n,a,b=[int(i) for i in input().split()]
cnt=0
print((n//(a+b))*a+min(n%(a+b),a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#N 合計
#A 先
#B 後

SUM = A + B

LOOP_SUM = int(N / SUM) * A
REST = N % SUM

if REST > A:
	LOOP_SUM += A
else:
	LOOP_SUM += REST

print(LOOP_SUM)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

def main():
    N,A,B=mis()
    S = N // (A+B)
    ans = S*A
    rem = N-S*(A+B)
    if rem > A:
        ans += A
    else:
        ans += rem
    print(ans)

main()

Submission status: Accepted

Solution code:
import math
N, A, B = map(int, input().split(' '))
r = math.floor(N / (A + B))
ans = r * A + min(N - r * (A + B), A)
print(ans)

Submission status: Accepted

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

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

q, r = divmod(n, (a+b))
ans = q * a
if r < a:
    ans += r
else:
    ans += a

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if N < A:
  print(N)

elif A <= N <= A + B:
  print(A)
  
else:
  count = N // (A+B)
  amari = N % (A + B)
  if amari < A:
    print(A*count + amari)
  else:
    print(A*count + A)

Submission status: Accepted

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

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

if A == 0:
    print(0)

elif N % (A + B) == 0:
    print(N // (A + B) * A)

else:
    count = N // (A + B) * A
    rem = min(A, N % (A + B))
    print(count + rem)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    if A == 0:
        print(0)
        exit()
        
    m = N // (A + B)
    ans = m * A

    N -= m * (A + B)

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt = A * (N//(A+B))
x =  N % (A+B)
if x > A:
    cnt += A
else:
    cnt += x
    
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
range = xrange
input = raw_input

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

a = N % (A+B)

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

Submission status: Accepted

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

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

if Q > A:
    Q = A

ans = P*A + Q
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

last = int(N%(A+B))

if last <=A:
    add_ = last
else:
    add_=A
    
ans =int(A*per+add_)
print(ans)

Submission status: Accepted

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

C=A+B

ans=(N//C)*A

if N%C!=0:
    if N%C<A:
        ans+=N%C
    else:
        ans+=A
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,a,b=mii()

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

q, mod = divmod(n, r+b)
if b > mod:
    ans = q*b + mod
else:
    ans = q*b + b
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

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

m = a+b

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

Submission status: Accepted

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

ans = 0
s = N//(A+B)
ans = s * 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())
C=N//(A+B)
D=N%(A+B)
ans=C*A+min(D,A)
print(ans)

Submission status: Accepted

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

number = n // (a+b)

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

Submission status: Accepted

Solution code:
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
INF = 10**15
DD = ((1,0),(0,1),(-1,0),(0,-1))

n,a,b = LI()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a, b = map(int, open(0).read().split())
q, r = divmod(n, a+b)
print(q*a + min(r, a))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

N, A, B = map(int, input().split(' '))
q, mod = divmod(N, A+B)
rest = min(mod, A)
ans = A * q + rest
print(ans)

Submission status: Accepted

Solution code:

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def main(inputs):
	n,blue,red=getIntList(inputs[0])
	s=blue+red
	ans=(n//s)*blue+min(n%s, blue)
	print(ans)

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

Submission status: Accepted

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

Submission status: Accepted

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

rep = n//(a+b)

ans = 0

ans += rep * a

m = n%(a+b)

ans += min(m, a)

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]

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

temp = N%(A+B)
ans = 0

ans += math.floor(N/(A+B))*A
ans += min(A,temp)


print(int(ans))

Submission status: Accepted

Solution code:
i=list(map(int, input().split()))
n=i[0]
a=i[1]
b=i[2]
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())

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

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

Submission status: Accepted

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

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

if s>=a:
    print(a*k+a)
else:
    print(a*k+s)

Submission status: Accepted

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