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:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,A,B = map(int, input().split())
    AB = A+B
    ans = (N//AB) * A
    rem = N%AB
    if rem > A:
        ans += A
    else:
        ans += rem
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

s = (A+B)*k

if N - s <= A:
    print(ans + (N - s))
else:
    print(ans + A)

Submission status: Accepted

Solution code:
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import statistics
import string


def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):#最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

N, A, B = splitintinput()
amari = 0
ans = 0
ans += A * int(N/(A+B))

amari = N%(A+B)

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

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
c = n % (a+b)
d = n // (a+b)
if c <= a:
    print(d*a + c)
else:
    print((d+1)*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())
clus=N//(A+B)
sub=N%(A+B)
if sub<A:
    print(clus*A+sub)
else:
    print(clus*A+A)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

print(result)

Submission status: Accepted

Solution code:
#def main(S, b):

if __name__ == '__main__':
    n, a, b = map(int, input().split())

    c = n // (a + b)

    ans = c * a

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

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

    print(ans)

Submission status: Accepted

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

print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,a,b = list(map(int,input().split()))

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

Submission status: Accepted

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

m=int(n)
ans+=int(n/(a+b))*a
n=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())

r1 = n //(a+b) * a
m1 = n % (a+b)
if m1 >= a:
    r1 += a
else:
    r1 += m1

print(r1)

Submission status: Accepted

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

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


main()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    readline=stdin.readline
    N,A,B=map(int,readline().split())
    s=A+B
    l=N//s
    r=N%s
    res=l*A+min(r,A)
    print(res)
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
x = a + b
ans = n // x * a
ans += min(a, (n % x))
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:
    Y = A
print(X*A +Y)

Submission status: Accepted

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

d, r = divmod(N, A + B)
print(d * A + min(r, A))

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

n_AB = N // (A + B)

N_tmp = N % (A + B)
n_A = min(A, N_tmp)

N_tmp -= n_A
n_B = min(N, N_tmp)

print(n_AB * A + n_A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
    return ret


N, A, B = read_ints()
ab = A + B
syou, amari = divmod(N, ab)
print(syou * A + min(amari, A))

Submission status: Accepted

Solution code:
import sys
import math
import collections
#n = int(input())
n, a, b = map(int, input().split())
#s = input()
#x = list(map(int, input().split()))

c = a + b
d = math.floor(n / c)
e = n % c

ans = d * a
ans += min(e, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

num = N // (A + B)
blue = num * A
blue += min(A, N - (A + B) * num)
print(blue)

Submission status: Accepted

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

K=N//(A+B)

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

Submission status: Accepted

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, A, B = lr()
    r = N%(A+B)
    if r <= A:
        print(N//(A+B)*A+r)
    else:
        print(N//(A+B)*A+A)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = repeat*A

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

print ans

Submission status: Accepted

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

T = A + B
k = N // T
rem =  N % T
print(k * A + min(rem, A))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC158b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n, a, b = map(int, input().split())
    loo = n // (a + b)
    wa = n - loo * (a + b)
    #print(loo, wa)

    print(loo*a+min(wa, a))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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:
N,A,B=map(int,input().split())
ans=0
ans+=N//(A+B)*A
C=N-N//(A+B)*(A+B)
if C>A:
    ans+=A
else:
    ans+=C
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,A,B = inputMap()

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

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

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


groups = N // (A+B)

amari = N % (A+B)


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

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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

def main():
  n,a,b=LI()

  ab=a+b
  c=n//ab

  return c*a+min(n%ab,a)

# main()
print(main())

Submission status: Accepted

Solution code:
def main():
    import numpy as numpy
    import sys
    n,a,b=list(map(int,sys.stdin.readline().split()))

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



main()

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

ans, mod = divmod(N, A + B)
ans *= A

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

print(ans)

Submission status: Accepted

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

    if am < a:
        ans += am
    else:
        ans += a
    print(ans)

Submission status: Accepted

Solution code:


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


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

ans = loops * a
ans += min(amari, a)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

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

div, mod = divmod(N, A+B)
ans = div * A + min(mod, A)

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

print(ans + min(A, c))

Submission status: Accepted

Solution code:
import sys

n, a, b = map(int, sys.stdin.readline().split())

def main():
    c = a + b 
    q, r = divmod(n, c)
    res = a * q + min(a, r)
    return res

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

k = n//(a+b)

ans = k*a

p = n%(a+b)

ans += min(a,p)
print(ans)

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

t = N // (A+B)
b1 = t * A
r = N - (A+B) * t
b2 = min(r, A)
print(b1 + b2)

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())
ANS=N//(A+B)*A
N-=N//(A+B)*(A+B)
ANS+=min(N,A)

print(ANS)

Submission status: Accepted

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

Submission status: Accepted

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

m = A + B
q = N // m
r = N % m

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

Submission status: Accepted

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

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

print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, A, B = iim()
    ans = A * (N // (A+B))
    ans += min(A, N % (A+B))
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    n,a,b=map(int,input().split())
    mato=a+b
    amari=n%mato
    kazu=n//mato
    temp=0
    if amari<=a:
        temp=amari
    else:
        temp=a
    print(kazu*a+temp)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
n, a, b = map(int, input().split())
c = a+b
res = 0
res += math.floor(n / c) * a
d = n % c
res += min(d, a)
print(res)

Submission status: Accepted

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

cnt = (n // (a+b)) * a
ex = n % (a+b)
if a > ex:
    cnt = cnt + ex
else:
    cnt = cnt + a

print(cnt)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
d, p = divmod(N, A+B)
ans = d * A
if p < A:
    ans += p
else:
    ans += A
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())
M=N//(A+B)
K=N%(A+B)
if K>A:
	print(M*A+A)
else:
	print(M*A+K)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

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

if res > a:
    print(num * a + a)
else:
    print(num * a + res)

Submission status: Accepted

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

x = N // s 
y = N % s

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,A,B=MI()
    ans=0
    rep=N//(A+B)
    ans+=rep*A
    res=N-rep*(A+B)
    ans+=min(res,A)
    print(ans)

main()

Submission status: Accepted

Solution code:

N,a,b=map(int,input().split())
num=N//(a+b)
x = N-num*(a+b)
res = num*a
if a<=x:
    res += a
else:
    res += x
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_ints():
    return map(int, input().split())

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,a,b = inpm()
    if n%(a+b) == 0:
        print((n//(a+b))*a)
        return
    print( (n//(a+b)) * a + min(a,n%(a+b)) )
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,A,B = LI()

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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