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: Wrong Answer

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

Submission status: Wrong Answer

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

print(n // l * a + min(n % l, 4))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(a*m+s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 + N % (A + B)
    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: Wrong Answer

Solution code:
n,A,B = list(map(lambda x:int(x),input().split(" ")))
x = n%(A+B)
r = min(x,A)
ans = (n-x)*A/(A+B)+r
print(int(ans))

Submission status: Wrong Answer

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

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


if syou>=1:
    syou = syou * A

print(amari+syou)

Submission status: Wrong Answer

Solution code:
n, a, b = input().split()
print(min(n, a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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+(n%(a+b)))

Submission status: Wrong Answer

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+1)*A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 += N % mod
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
print(n if n<=a else a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

t1 = n // (a+b)
t2 = n % (a+b)
ans = t1 * a + t2
print(ans)

Submission status: Wrong Answer

Solution code:
"""
// Author : snape_here - Susanta Mukherjee
     
"""
 
from __future__ import division, print_function
 
import os,sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
 
 
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
    
 
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 
 
 
import math

mod=1000000007 

def main():

    n,a,b=mi()
    s=a+b 
    c=(n//s)*a
    d=n%s 
    print(c+d)

# region fastio#
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
 
if __name__ == "__main__":
    #read()
    main() 
#Comment read()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd
enu = enumerate

sys.setrecursionlimit(10**7)
N, A, B = map(int, input().split())

AB = A+B

cnt = A * (N//AB)
cnt += N % AB

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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, B))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if A>=N:
    print(N)
else:
    if A+B<N:
        print(N-B)
    else:
        print(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

now = 0
cnt = 0

while now < n:
	now += a+b
	cnt += a
	if now+a+b > n:
		cnt += n-now
		break

print(cnt)

Submission status: Wrong Answer

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

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

ans += n - (b+r) * ( n // (b+r))
print(ans if b != 0 else 0)

Submission status: Wrong Answer

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

M = A+B

ans = (N // M) * A + N%M

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(N-N//(A+B)*(A+B)+N//(A+B)*A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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+n%ab

# main()
print(main())

Submission status: Wrong Answer

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

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

resolve()

Submission status: Wrong Answer

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)
print(x*a+y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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*(a+1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,a,b = map(int,stdin.readline().rstrip().split())
if a <= n:
    print(a)
else:
    print(n)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans += n - (b+r) * ( n // (b+r))
print(ans)

Submission status: Wrong Answer

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: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 + N-(num*(A+B)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: int, B: int):
    print(A*N//(A+B)+N%(A+B))
    return



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: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
s = ''
while len(s) < n:
    for _ in range(a):
        s += 'a'
    for _ in range(b):
        s += 'b'

print(s[0:n].count('a'))

Submission status: Time Limit Exceeded

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

ball=[]

while len(ball)<=N:
    for x in range(A):
        ball.append(1)
        if len(ball)>=N:
            break
    for x in range(B):
        ball.append(-1)
        if len(ball)>=N:
            break

print(ball[0:N].count(1))

Submission status: Time Limit Exceeded

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

ball=[]

while len(ball)<=N:
    for x in range(A):
        ball.append(1)
    for x in range(B):
        ball.append(-1)

print(ball[0:N].count(1))

Submission status: Time Limit Exceeded

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

ball=[]

for i in range(N):
    for x in range(A):
        ball.append(1)
    for x in range(B):
        ball.append(-1)

print(ball[0:N].count(1))

Submission status: Time Limit Exceeded

Solution code:
N,A,B= map(int,input().split())
ans = 0
count = 0
while count<=N:
    for i in range(A-1):
        ans += 1
        count += 1
        for j in range(B-1):
            count += 1

print(ans)

Submission status: Time Limit Exceeded

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

sum=0
flag=False
b=0

while True:
  sum=sum+A
  b=b+A
  if sum>N:
    flag=True
    break
  sum=sum+B
  if sum>N:
    break
if flag:
  print(b-(sum-N))
else:
  print(b)

Submission status: Time Limit Exceeded

Solution code:
z = input().split()

al = int(z[0])
blue = int(z[1])
red = int(z[2])

ans = 0
k = 0

while k <= al - blue -red:
    ans += blue
    k += blue
    k += red

while k <= al-1:
    ans += 1
    k += 1

print(ans)

Submission status: Time Limit Exceeded

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

string = ''
count = 0

while len(string) < blue_num:
    for _ in range(b):
        string += 'b'
    for _ in range(r):
        string += 'r'

for x in range(blue_num):
    if string[x] == 'b':
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

string = ''
count = 0

while True:
    if len(string) < blue_num:
        for _ in range(b):
            string += 'b'
        for _ in range(r):
            string += 'r'
    else:
        break

for x in range(blue_num):
    if string[x] == 'b':
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

L = []
i = 0
k = 0
j = 0

for k in range(10**18):
    for i in range(A):
        L.append('b')
        if len(L) >= N:
            L = L[0:N]
            print(L.count('b'))
            exit()
    
    for j in range(B):
        L.append('r')
        if len(L) >= N:
            L = L[0:N]
            print(L.count('b'))
            exit()

Submission status: Time Limit Exceeded

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

L = []
i = 0
k = 0
j = 0

for k in range(10**100):
    for i in range(A):
        L.append('b')
        if len(L) >= N:
            L = L[0:N]
            print(L.count('b'))
            exit()
    
    for j in range(B):
        L.append('r')
        if len(L) >= N:
            L = L[0:N]
            print(L.count('b'))
            exit()

Submission status: Time Limit Exceeded

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

L = []
i = 0
k = 0
j = 0

for k in range(10**100):
    for i in range(A):
        L.append('b')
    for j in range(B):
        L.append('r')

    if len(L) >= N:
        L = L[0:N]
        print(L.count('b'))
        break

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
x,y=0,0
i=0
while(n>0):
    if(i%2==0):
        x+=min(n,a)
        n-=min(n,a)
    else:
        y+=min(b,n)
        n-=min(n,b)
    i+=1
print(x)

Submission status: Time Limit Exceeded

Solution code:
H,A,B=map(int,input().split())
l=[]
s=0
while s!=H:
    for i in range(A):
        if s==H:
            break
        s+=1
        l.append('b')
    for j in range(B):
        if s==H:
            break
        s+=1
        l.append('a')
print(l.count('b'))

Submission status: Time Limit Exceeded

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

l=[]
while len(l)<=n:
  for i in range(a):
    l.append("b")
  for i in range(b):
    l.append("r")
  
print(l[0:n].count("b"))

Submission status: Time Limit Exceeded

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

while(True):
	if n <= a:
		answer += n
		break
	if n < a + b:
		answer += a
		break
	answer += a
	n -= (a + b)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
ans = 0
blue = a
red = b
x = n // (blue+red)
y = n % (blue+red)
lis = []

if y == 0:
  ans = blue * x
else:
  for _ in range(y):
    if a == 0:
      break
    else:
      lis.append("b")
      a -= 1
  ans = (blue*x) + lis.count("b")
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
x = a
y = b
lis = []

for _ in range(n):
  if a > 0:
    lis.append("b")
    a -= 1
  elif b > 0:
    lis.append("r")
    b -= 1
  elif b == 0:
    a = x
    b = y
    if a == 0:
      lis.append("r")
      b -= 1
    else:
      lis.append("b")
      a -= 1

print(lis.count("b"))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':

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

    cnt = 0
    ans = 0

    while cnt < n:
        tmp1 = min(a,n-cnt)
        ans += tmp1
        cnt += tmp1 + b
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
total = 0
out = 0
if a == 0:
    pass
else:
    while True:
        total += a
        out += a
        if total >= n:
            out -= (total - n)
            break
        total += b
        if total >= n:
            break
print(out)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
total = 0
out = 0
while True:
    total += a
    out += a
    if total >= n:
        out -= (total - n)
        break
    
    total += b
    if total >= n:
        break

print(out)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int, input().split()))
ans = 0
for i in range(10 ** 100):
	if N > 0:
		ans += min(N, A)
		N -= A
	else:
		break
	if N > 0:
		N -= B
	else:
		break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n,a,b = list(map(int,input().split()))
  blue=""
  red=""
  for i in range(0,a):
    blue+='b'
  for i in range(0,b):
    red+='r'
  ans=""
  while n>len(ans):
    ans+=blue
    ans+=red
  print(ans[:n].count('b'))
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  n,a,b = list(map(int,input().split()))
  ans=""
  while n>len(ans):
    for i in range(0,a):
      ans+='b'
    for i in range(0,b):
      ans+='r'
  print(ans[:n].count('b'))
main()

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
li = []
for i in range(A):
    li.append('b')
for i in range(B):
    li.append('r')

balls = A+B
an = 0
if N % balls == 0:
    print(int(A * (N/balls)))
else:
    an += A * (N//balls)
    for i in range(N % balls):
        if li[i] == 'b':
            an += 1
    print(an)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
ans = []
while (True):
    for _ in range(a):
        ans.append('b')
    if len(ans) >= n:
        break
    for _ in range(b):
        ans.append('r')
    if len(ans) >= n:
        break
print(ans[:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ABalls = ""
BBalls = ""
for a in range(A):
  ABalls += "B" 
for b in range(B):
  BBalls += "R"

Balls = ABalls + BBalls
AB = A + B
NumBBalls = 0

NumBBalls = N//AB * A

M = N%AB

for m in range(M):
  if Balls[m] == "B":
    NumBBalls += 1
  else:
    break

print(NumBBalls)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ABalls = ""
BBalls = ""
for a in range(A):
  ABalls += "B" 
for b in range(B):
  BBalls += "R"

Balls = ABalls + BBalls
AB = A + B
NumBBalls = 0

while N > AB:
  N -= AB
  NumBBalls += A

for n in range(N):
  if Balls[n] == "B":
    NumBBalls += 1
  else:
    break

print(NumBBalls)

Submission status: Time Limit Exceeded

Solution code:
# B Count Balls

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

cnt = 0
ans = 0
while cnt < N - (A + B):
  cnt += A+B
  ans += A

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

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
num=0
while n>0:
    if (n<a+b) and (n<a):
        num+=n
        break
    if (n<a+b) and (n>a):
        num+=a
        break
    n-=a+b
    num+=a
print(num)

Submission status: Time Limit Exceeded

Solution code:
# ABC158 B - Count Balls

N,A,B = map(int,input().split())
A_A = 0
B_B = 0
for i in range(N):
    if N >= A:
        A_A +=A
        N -=A
    else:
        A_A +=N
        break
    if N >= B:
        B_B +=B
        N -=B
    else:
        B_B +=N
        break
print(A_A)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int,input().split())
ans = 0
x = 0
Ball = []
while x < N:
    x = x + A + B
    for i in range(A):
        Ball.append('b')
    for i in range(B):
        Ball.append('r')
Ball = Ball[0:N]
ans = Ball.count('b')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...

N = 8
[青青青赤赤赤赤青]

return 青 = 4
"""

def count_balls():
    # 入力
    N, A, B = map(int, input().split())
    # 例外
    if A+B == 0:
        return 0
    # N以下の[青*A][赤*B]の組み合わせの個数
    i = 1
    while True:
        if N >= (A+B) * i:
            i += 1
        else:
            break
    # N - ([青*A]+[赤*B])*i
    remainder = N - (A+B) * (i-1)
    if remainder <= A:
        return A * (i-1) + remainder
    else:
        return A * (i-1) + A

result = count_balls()
print(result)

Submission status: Time Limit Exceeded

Solution code:
"""
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...

N = 8
[青青青赤赤赤赤青]

return 青 = 4
"""

def count_balls():
    # 入力
    N, A, B = map(int, input().split())
    # 例外
    if N > (A+B) * (10 ** 100):
        return A * (10 ** 100)
    # N以下の[青*A][赤*B]の組み合わせの個数
    i = 1
    while True:
        if N >= (A+B) * i:
            i += 1
        else:
            break
    # N - ([青*A]+[赤*B])*i
    remainder = N - (A+B) * (i-1)
    if remainder <= A:
        return A * (i-1) + remainder
    else:
        return A * (i-1) + A

result = count_balls()
print(result)

Submission status: Time Limit Exceeded

Solution code:
"""
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...

N = 8
[青青青赤赤赤赤青]

return 青 = 4
"""

def count_balls():
    # 入力
    N, A, B = map(int, input().split())
    # N以下の[青*A][赤*B]の組み合わせの個数
    i = 1
    while True:
        if N >= (A+B) * i:
            i += 1
        else:
            break
    # N - ([青*A]+[赤*B])*i
    remainder = N - (A+B) * (i-1)
    if remainder <= A:
        return A * (i-1) + remainder
    else:
        return A * (i-1) + A

result = count_balls()
print(result)

Submission status: Time Limit Exceeded

Solution code:
a,b,c=map(int,input().split())
n = a // (b+c)
m = a - (b+c)*n
res = n*b
for i in range(m):
  if i < b:
    res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
balls = []
odd = 1
while len(balls)<=N:
    if odd == 1:
        for i in range(1,A+1):
            balls = balls + ["b"]
        odd = 0
    else:
        for i in range(1,B+1):
            balls = balls + ["r"]
        odd = 1
balls = balls[:N]
print(balls.count("b"))

Submission status: Time Limit Exceeded

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

balls = ""
while True:
    for i in range(A):
        balls += "b"
    for i in range(B):
        balls += "r"
    if len(balls) >= N:
        break

print(balls[:N].count("b"))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
ans = 0
q = 0
A = 'Blue'
if a == 0:
  print(0)
  exit()
  
for i in range(n):
  if i % 2 == 0:
    ans += a
    q += a
    A = 'Blue'
  if i % 2 != 0:
    q += b
    A = 'Red'
  if q > n:
    break
    
if A == 'Red':
  print(ans)
  
if A == 'Blue':
  print(ans-(q-n))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
ans = 0
q = 0
A = 'Blue'
if a == 0:
  print(0)
  exit()
  
for i in range(n):
  if i % 2 == 0:
    ans += a
    q += a
    A = 'Blue'
  if i % 2 != 0:
    q += b
    A = 'Red'
  if q > n:
    break
    
if A == 'Red':
  print(ans)
  
if A == 'Blue':
  print(ans-(q-n))

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
red = 0 ; blue = 0
while n >= 0 :
    if n > a :
        n -= a
        blue += a
    else :
        blue += n
        break
    if n > b :
        n -= b
        red += b
    else :
        red += b
        break
print(blue)