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

Solution code:
def resolve():
    n, a, b = map(int, input().split())
    lis = []
    while True:
        for i in range(a):
            lis.append("b")
        if len(lis) >= n:
            break
        for j in range(b):
            lis.append("r")
        if len(lis) >= n:
            break
    print(lis[0:n].count("b"))


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

#for i in range(N):
while N>=0:
	for j in range(A):
		if N==0:
			break
		C+=1
		N-=1
	for k in range(B):
		N=N-1
print(C)

Submission status: Time Limit Exceeded

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

C = N // (A + B) + (0 if N % (A + B) == 0 else 1)

blue = 0
total = 0

while total < N:
    addition = min(N - total, A + B)
    total += addition
    blue += min(addition, A)

print(blue)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 何個目のボールを持ってくる？青いボールは何個？赤いボールは何個？
take_number, blue_ball, red_ball = input().split()
take_number = int(take_number)
blue_ball = int(blue_ball)
red_ball = int(red_ball)

ball_list = []
take_list = []

for i in range(10 ** 100):
  for b in range(blue_ball):
    ball_list.append("b")
  for r in range(red_ball):
    ball_list.append("r")
    
for n in range(N):
  take_list.append(balllist[n])
  
print(take_list.counter("b"))

Submission status: Time Limit Exceeded

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

if a != 0:
    while n > 0:
        if n < a+b:
            if n < a:
                for j in range(a):
                    if n != 0:
                        result += 1
                        n -= 1
            else:
                result += a
                n -= a
                for j in range(b):
                    if n != 0:
                        result += 1
                        n -= 1
        else:
            result += a
            n -= a+b
else:
    result = 0

print(result)

Submission status: Time Limit Exceeded

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

num = 0
res_b = 0
cnt = n//2 + n%2

for _ in range(cnt):
  num += b
  if num > n:
    res_b += b - (num - n)
  else:
    res_b += b
      
  num += r

  if num > n:
    break
  
print(res_b)

Submission status: Time Limit Exceeded

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

s = b + c
counter = 1
ans = 0
while True:
  if a < s * counter:
    ans = b*(counter-1)
    if a - (s * (counter-1)) <= b:
      ans += a - (s * (counter-1))
    else:
      ans += b
    break
  else:
    counter += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
total=(10 ** 100) + 1

for i in range(total):
  if N <= i*A + i*B :
    if N >= i*A + (i-1)*B :
      ans=i*A
      break
    else :
      ans=i*A - (i*A+(i-1)*B - N)
      break
print(ans)

Submission status: Time Limit Exceeded

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

C = N // (A + B) + (0 if N % (A + B) == 0 else 1)

blue = 0
total = 0
for n in range(C):
    addition = min(N - total, A + B)
    total += addition
    blue += min(addition, A)

print(blue)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = [int(x) for x in input().split()]
n = 0
blue = 0
for i in range(10**100):
    if A == 0:
        break
    n = n + A
    blue = blue + A
    if n >= N:
        blue = blue - (n-N)
        break
    else:
        n = n + B
        if n >= N:
            break
print(blue)

Submission status: Time Limit Exceeded

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

count=1
ans = 0
while (a+b)*count<=n:
    ans +=a
    count+=1
    # print(count)
r = n - (a+b)*(count-1)
# print(r)
if not r == 0:
    ans += min([a,r])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
s=[]
x=[]
for i in range(a):
    s.append('b')
for i in range(b):
    s.append('r')
for i in range(10**100):
    x.append(s)

x=list(x)
ans=0
for i in range(n):
    if x[i]=='b':
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
lst = [int(i) for i in input().split()]

ball = lst[0]
blue = lst[1]
red = lst[2]
blue_red = int(ball / (red + blue)) + 1

blue_str = ''
for i in range(blue): blue_str += 'b'
red_str = ''
for i in range(red): red_str += 'r'

mojiretu = ''
for i in range(blue_red): mojiretu += (blue_str + red_str)
print(mojiretu[:ball].count('b'))

Submission status: Time Limit Exceeded

Solution code:
l = list(map(int, input().split()))
n,a,b=l[0],l[1],l[2]
count=0
while True:
  for i in range(a):
    if n == 0:
      break
    count += 1
    n -= 1	
  for i in range(b):
    if n == 0:
      break
    n -= 1
  if n == 0:
    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = input().split()
N = int(N)
A = int(A)
B = int(B)
C = A + B
T = int(N / C + 1)
l = []
j = 0
k = 0
for i in range(T):
    while j < A:
        l.append('b')
        j += 1
        k = 0
    while k < B:
        l.append('r')
        k += 1
        j = 0
lenght = len(l)
del l[N : lenght + 1]
print(l.count('b'))

Submission status: Time Limit Exceeded

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

if a==0:
  print('0')
  exit()
else:
  while n>=a:
    n=n-a
    count+=1
    if n>=b:
      n=n-b
    elif n<b:
      n=0
      

ball=a*count+n

print(ball)

Submission status: Time Limit Exceeded

Solution code:

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

    ans = 0
    a = 0
    b = 0
    for _ in range(N + 1):
        if (a < A) and (b == 0):
            ans += 1
            a += 1
        elif (a == A) and (b == 0):
            a = 0
            b += 1
        elif b < B:
            b += 1
        elif b == B:
            b = 0
    print(ans)
    return 0
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

aa = a
bb = b

blue_ball = a
red_ball = b

n_bai = n // (a + b)
n_amari = n % (a + b)
balls = ''


while len(balls) < n_amari:
    while aa > 0:
        balls += 'b'
        aa -= 1
    while bb > 0:
        balls += 'r'
        bb -= 1
    aa = a
    bb = b


amari_balls = balls[:n_amari]

ans = (n_bai) * blue_ball + amari_balls.count('b')

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
	n,a,b = map(int, input().split())
	if a==0:
		print(0)
	else:
		if n<a:
			print(n)
		# elif a<=n:
			# print(a)
		else:
			for i in range(1,10**50):
				if n < (a+b)*i and (a+b)*(i-1)<=n:
						if n-(a+b)*(i-1)<a:
							print(a*(i-1)+n-(a+b)*(i-1))
						else:
							print(a*i)
						break
main()

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
li=[]
for i in range(n//(a+b)+1):
  for k in range(a):
    li.append('b')
  for m in range(b):
    li.append('r')
print(li[:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  # リストに重複した要素があるか判定（要素にリストがある場合）
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


n, a, b = map(int, input().split())
x = []
while(len(x) < n):
    for i in range(a):
        x.append('b')
    for i in range(b):
        x.append('r')
# print(x[:n])
# print(x)
xx = x[:n]
print(xx.count('b'))

Submission status: Time Limit Exceeded

Solution code:
def main():
	n,a,b = map(int, input().split())
	if a==0:
		print(0)
	else:
		if n<a:
			print(n)
		# elif a<=n:
			# print(a)
		else:
			for i in range(1,10**100):
				if n < (a+b)*i and (a+b)*(i-1)<=n:
						if n-(a+b)*(i-1)<a:
							print(a*(i-1)+n-(a+b)*(i-1))
						else:
							print(a*i)
						break
main()

Submission status: Time Limit Exceeded

Solution code:
li=[]
N,A,B=map(int,input().split())
for i in range((N//(A+B))):
    for i in range(A):
        li.append("b")
    for i in range(B):
        li.append("r")
ctpossible=li.count("b")#ペアでカウント可能
if N%(A+B)<=A:
    adding=N%(A+B)
else:
    adding=A
print(ctpossible+adding)

Submission status: Time Limit Exceeded

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

total_list = []
count = 0
break_flag = False
for i in range(int(10e100)):
    if break_flag:
        break
    for i in range(A):
        total_list.append("b")
        if len(total_list) <= N:
            count += 1
        else:
            break_flag = True
            break
    for i in range(B):
        total_list.append("r")
        if len(total_list) >= N:
            break_flag = True
            break
    if len(total_list) >= N:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

r = bu = 0
while n >= 0:
    for i in range(a):
        if n <= 0:
            print(bu)
            sys.exit()
        else:
            bu += 1
            n -= 1
            
    for j in range(b):
        if n <= 0:
            print(bu)
            sys.exit()
        else:
            r += 1
            n -= 1

Submission status: Time Limit Exceeded

Solution code:
N, a, b = map(int, input().split())
x = (N//(a+b)) *a
l=[]
for i in range(a):
  l.append('b')
for i in range(b):
  l.append('r')
y = l[0:int(N%(a+b))]
print(x + y.count('b'))

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
L = []
b = 0
ans = 0
cnt = 0

while True:
  if A == 0: break

  L.append(A)
  b += A
  cnt += A
  if cnt > N:
    ans = b - (cnt - N)
    break

  L.append(B)
  cnt += B
  if cnt > N:
    ans = b
    break

print(ans)

Submission status: Time Limit Exceeded

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

b_count = 0
n_count = 0
while n_count < N:
    if n_count + A < N:
        b_count += A
    else:
        b_count += N - n_count
        break
    n_count += A + B
print(b_count)

Submission status: Time Limit Exceeded

Solution code:
import math
N,A,B=map(int, input().split())
t=[]
while True:
  for i in range(A):
    t.append('b')
  for i in range(B):
    t.append('a')
  if len(t)>=N:
    break
c=t[0:N]
print(c.count('b'))

Submission status: Time Limit Exceeded

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

aa = a
bb = b

blue_ball = a
red_ball = b

n_bai = n // (a + b)
n_amari = n % (a + b)
balls = ''


while len(balls) < (a + b):
    while aa > 0:
        balls += 'b'
        aa -= 1
    while bb > 0:
        balls += 'r'
        bb -= 1
    aa = a
    bb = b


amari_balls = balls[:n_amari]

ans = (n_bai) * blue_ball + amari_balls.count('b')

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int, input().split())
mode = 0
cnt = 0
tmp = 0
for i in range(1,n+1):
    if a == 0: break
    if a+b == n: 
        cnt += a
        break
    if mode == 0 and tmp <= a:
        cnt += 1
        tmp += 1
    elif tmp == a and mode == 0:
        tmp = 0
        mode = 1

    if mode == 1 and tmp <= b:
        tmp += 1
    elif tmp == b and mode == 1:
        tmp = 0
        mode = 0
print(cnt)

Submission status: Time Limit Exceeded

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

num = 0
count = 0
res_b = 0
res_r = 0

for _ in range(n):
  if count % 2 == 0:
    num += b
    if num > n:
      res_b += b - (num - n)
    else:
      res_b += b
      
  else:
    num += r

  count += 1

  if num > n:
    break
  
print(res_b)

Submission status: Time Limit Exceeded

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

s = []
while len(s) <= n:
  for _ in range(a):
    s.append('a')
  for _ in range(b):
    s.append('b')
print(s[:n].count('a'))

Submission status: Time Limit Exceeded

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

total_list = []
count = 0
for i in range(int(10e100)):
    for i in range(A):
        total_list.append("b")
        if len(total_list) <= N:
            count += 1
        else:
            break
    for i in range(B):
        total_list.append("r")
    if len(total_list) >= N:
        break

print(count)

Submission status: Time Limit Exceeded

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

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

E = 0
for i in range(D):
    if 0 < (i + 1) % (A + B) <= A:
        E += 1
        
print(C+E)

Submission status: Time Limit Exceeded

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

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

if n <= blue:
    print(n)
    exit()
    
if n <= blue + red:
    print(blue)
    exit()

cnt = 0

while True:
    if n > blue:
        cnt += blue
        n -= blue
        if n <= red:
            break
        elif n > red:
            n -= red
    else:
        cnt += n
        break
print(cnt)

Submission status: Time Limit Exceeded

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


def main():
    blue = red = 0

    for i in range(10 ** 100):
        blue += A

        if blue + red > N:
            blue -= blue + red - N
            break

        red += B

        if blue + red > N:
            red -= blue + red - N
            break

    return blue


print(main())

Submission status: Time Limit Exceeded

Solution code:
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  # リストに重複した要素があるか判定（要素にリストがある場合）
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# s = input()
# n = len(s)
# m = int(s)


# def check(l):
#     x = int("".join(list(map(str, l))))
#     return m >= x and (3 in l) and (5 in l) and (7 in l)


# def solve(l):
#     if len(l) == n:
#         if check(l):
#             # print(int("".join(list(map(str, l)))))
#             return 1
#         else:
#             return 0
#     a = solve(l+[3])
#     b = solve(l+[5])
#     c = solve(l+[7])
#     d = 0
#     if len(l) == 0 or l[-1] == 0:
#         d = solve(l+[0])
#     return a+b+c+d


# print(solve([]))

#n = readints()[0]
#
#ans = 0
#
# for i in range(n+1):
#    s = list(str(i))
#    a = s.count("3")
#    b = s.count("5")
#    c = s.count("7")
#    if a != 0 and b != 0 and c != 0 and a+b+c == len(s):
#        ans += 1
# print(ans)

n, a, b = map(int, input().split())
x = []
while(len(x) < n):
    for i in range(a):
        x.append('b')
    for i in range(b):
        x.append('r')
# print(x[:n])
# print(x)
xx = x[:n]
print(xx.count('b'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, a ,b = map(int, input().split())
ans = 0
length = 0
while length <= n:
  length += a + b
  ans += a
over = length - n
if (over == 0):
  print(ans)
else:
  if (over <= b):
    print(ans)
  else:
    over -= b
    ans -= over
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
# print(N)
List = []
n = 0
while n < N:
    for a in range(A):
        List.append('b')
        n = n + 1
        if n >= N:
            break
    for b in range(B):
        if n >= N:
            break
        List.append('r')
        n = n + 1
        if n >= N:
            break
# print(List)
# リストの先頭からN個番目に'b'が何個あるかをカウントする
print(List.count('b'))

Submission status: Time Limit Exceeded

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

def add(i,j):
  while(i<A):
    list.append("b")
    i+=1

  while(j<B):
    list.append("r")
    j+=1

while(m<N):
    i=0
    j=0
    add(i,j)
    m+=A
    m+=B

l=list[0:N]
r=l.count("b")
print(r)

Submission status: Time Limit Exceeded

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

def main():
    countb = 0
    count = 0
    while(1):
        for i in range(A):
            count+=1
            countb+=1
            if count >=N:
                return countb
        for i in range(B):
            count+=1
            if count >=N:
                return countb
a = main()

print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
line = input().rstrip().split(' ')
n = int(line[0])
a = int(line[1])
b = int(line[2])

i = 0
ans = 0
while i <= n:
    if i + a <= n:
        ans += a
    else:
        t = n - i
        ans += t
    i += a + b

print(ans)

Submission status: Time Limit Exceeded

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

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

sum = 0

if n <= a:
    sum = n

elif n <= (a + b):
    sum = a

else:
    while n >= (a + b):
        sum += a
        n -= (a + b)

    if n <= a:
        sum += n

    elif n <= (a + b):
        sum += a

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
i_str = input()
N,A,B = map(int,i_str.split())


all_count = 0
b_count = 0
maxnum =pow(10,100) 
for i in range(maxnum):
    if all_count + A >= N:
        tmp_b = b_count + (N - all_count)
        print(tmp_b)
        break
    all_count += A
    b_count += A
    all_count += B
    if all_count >= N:
        print(b_count)
        break

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
flag = True
a_count = 0
while n > 0:
    if flag:
        n -= a
        if n < 0:
            a_count += a + n
            break
        a_count += a
        flag = False
    else:
        n -= b
        flag = True
print(a_count)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
if a == 0:
    print(0)
elif n % (a+b) == 0:
    print(a*(n // (a+b)))
elif n % (a+b) == a:
    print(a*(n // (a+b)+1))
else:
    while count < 10**100:
        n -= a
        tmp += a
        if n <= 0:
            print(tmp + n)
            break
        n -= b
        if n <= 0:
            print(tmp)
            break

Submission status: Time Limit Exceeded

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

c = 0
bc = 0

while True:
    if c > N:
        ans = bc
        break
    c += A
    bc += A
    if c > N:
        ans = bc - (c - N)
        break
    c += B

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main(n, a, b):
    ans = 0
    i = 0
    while i <= n:
        if n - i < a:
            ans += n - i
            break
        else:
            ans += a
            i += a

        i += b

    print(ans)


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

    main(n, a, b)

Submission status: Time Limit Exceeded

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

def add_ball(a, b):
    ball_list = []
    for i in range(a):
        ball_list.append('b')
        if len(ball_list) == n:
            return ball_list
    for j in range(b):
        ball_list.append('r')
        if len(ball_list) == n:
            return ball_list
    return ball_list


for i in range((n // (a + b)) + 1):
    ball_list = add_ball(a, b)
    ans += ball_list

print(ans[:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = [int(i) for i in input().strip().split()]
res = 0
cnt = 0
AorB = "A"
while True:
  if AorB == "A":
    if cnt + A < N:
      res += A
      cnt += A
      AorB = "B"
    else:
      res += (N - cnt)
      break
  else:
    cnt += B
    AorB = "A"
    if cnt >= N:
      break

print(res)

Submission status: Time Limit Exceeded

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

num = 0
i = 0
while num <= n:
    num = num + a + b
    i = i + 1
br_num = a + b
if ((a + b)*i) - n <= b:
    print(a * i)
else:
    num1 = ((a + b)* i) - n
    num2 = a * i
    num3 = num1 - b
    print(num2 - num3)

Submission status: Time Limit Exceeded

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


while True:
    if boalsLen > N:
        break
    
    tmpBoalsLen = boalsLen + A
    if tmpBoalsLen > N:
        addBoals = N - boalsLen
        count += addBoals
        break
    
    boalsLen = tmpBoalsLen
    boalsLen += B
    count += A

print(count)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
b = ''
while True:
    for i in range(A):
        if len(b) == N:
            print(b.count('b'))
            exit()
        b += 'b'
    for i in range(B):
        if len(b) == N:
            print(b.count('b'))
            exit()
        b += 'r'

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
total=(10 ** 100) + 1
lengthCnt=0
lengthA=0
lengthB=0
for i in range(total):
  if i % 2 == 0:
    lengthCnt += A
    lengthA += A
    if lengthCnt >= N :
      ans = lengthA - (lengthCnt - N)
      break
  else :
    lengthCnt += B
    lengthB += B
    if lengthCnt >= N :
      ans = lengthA
      break
      
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
flag = True
list = ''
if A + B == N:
    ans = A
elif A == 0:
    ans = 0
else:
    while flag == True:
        for a in range(A):
            ans = ans + 1
            list += 'b'
            if len(list) == N:
                flag = False
                break
        for b in range(B):
            list += 'r'
            if len(list) == N:
                flag = False
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
k=0
while (A+B)*k<N:
  k+=1


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

Submission status: Time Limit Exceeded

Solution code:
l = list(map(int, input().split()))
n = l[0]
b = l[1]
a = l[2]
s = []
count = 0
for i in range(n):
  for blue in range(b):
    s.append(0)#0==blue
  for red in range(a):
    s.append(1)
for i in range(n):
  if s[i] == 0:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
x=n%(a+b)
if x in list(i for i in range(1,a+1)):
    print(a*(n//(a+b))+x)
elif x==0:
    print(a*(n//(a+b)))
else:
    print(a*((n//(a+b))+1))

Submission status: Time Limit Exceeded

Solution code:

N, A,B = map(int, input().split())
str = []
for j in range(N//(A+B)+1):
    for i in range(A):
        if len(str)>N:
            break
        str.append('b')

    for i in range(B):
        if len(str)>N:
            break
        str.append('r')
    if len(str)>N:
        break

count = 0
for k in range(N):
    if str[k] == 'b':
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    (n,a,b) = [int(e) for e in input().split()]
    bs = ['b' for e in range(a)]
    rs = ['a' for a in range(b)]
    unit = []
    while len(unit) < n:
        unit.extend(bs)
        unit.extend(rs)
    print(len([e for e in unit[:n] if e == 'b']))

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
ans,i=0,0
for i in range(N):
    if (i+1)%(A+B)<=A and (i+1)%(A+B)!=0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n, a, b = map(int, input().split())
if a == 0 or n == 0:
    print(0)
    sys.exit()
for i in range(n //(a + b) + 1):
    if (a + b) * i <= n < (a + b) * (i + 1):
        j = i
        break
if n - (a + b) * j >= a:
    print(a * j + a)
    sys.exit()
else:
    print(a * j + n- (a + b)*j )
    sys.exit()

Submission status: Time Limit Exceeded

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

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

sum = 0

if n <= a:
    sum = n

elif n <= (a + b):
    sum = a

else:
    while n >= (a + b):
        sum += a
        n -= (a + b)

    if n <= a:
        sum += n

    elif n <= (a + b):
        sum += a

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Line = ''

Appended_line = ''
for i in range(B):
  Appended_line += 'b'
for i in range(R):
  Appended_line += 'r'

while(N > len(Line)):
  Line += Appended_line

ans = Line[:N].count('b')

print(ans)

Submission status: Time Limit Exceeded

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

list = ''
while len(list) < N :
  for i in range(A):
    if len(list) < N:
      list += 'b'
    else:
      print(list[0:N].count('b'))
      sys.exit()
  
  for i in range(B):
    if len(list) < N:
      list += 'r'
    else:
      print(list[0:N].count('b'))
      sys.exit()

print(list[0:N].count('b'))

Submission status: Time Limit Exceeded

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

def func():
    if A==0 and B == 0:
        return 0
    
    count = 0
    blue = 0
    red = 0
    balls = []
    while count<N:
        count+=A
        count+=B
        blue+=A

    if count>N:
        remain = count-N-B
        if remain>0:
            blue = blue - remain
    return blue


print(func())

Submission status: Time Limit Exceeded

Solution code:
N, b, r = list(map(int, input().split()))
str = ''
loop, cnt, bcnt = 0, 0, 0
while(cnt <= N):
  if loop%2 == 0:
    cnt += b
    bcnt += b
    if N - cnt < 0:
      bcnt += (N-cnt)
  elif loop%2 == 1:
    cnt += r
  loop += 1

print(bcnt)

Submission status: Time Limit Exceeded

Solution code:

N, A,B = map(int, input().split())
str = []
for j in range(N//(A+B)+1):
    for i in range(A):
        if len(str)==N+1:
            break
        str.append('b')

    for i in range(B):
        if len(str)==N+1:
            break
        str.append('r')
    if len(str)==N+1:
        break

count = 0
for k in range(N):
    if str[k] == 'b':
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

for i in range(10**100):
  blue += a
  total += a
  if total == n:
    print(blue)
    exit(0)
  elif total > n:
    print(blue - (total - n))
    exit(0)
    
  total += b
  if total >= n:
    print(blue)
    exit(0)

Submission status: Time Limit Exceeded

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

num = 0
count = 0
res_b = 0
res_r = 0

while num <= n:
  if count % 2 == 0:
    num += b
    if num > n:
      res_b += b - (num - n)
    else:
      res_b += b
      
  else:
    num += r
#    if num > n:
#      res_r += r - (num - n)
#    else:
#      res_r += r

  count += 1

print(res_b)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
 
if A == 0:
  ans = 0;
else:
  ans = 0
  while(N > 0):
    if N - A <= 0:
      ans += N
      break
    ans += A
    N = N - A
    N = N - B
    if N <= 0:
      break
  
print(ans)

Submission status: Time Limit Exceeded

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

x = []

while len(x)<n:
    for i in range(a):
        x.append(0)
    if len(x) < n:
        for i in range(b):
            x.append(1)

count = 0

for i in range(n):
    if x[i] == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8

N,A,B=map(int,input().split())
data=[]
while len(data) < N:
  for r in range(A):
    data.append(1)
  for b in range(B):
    data.append(2)

list=data[0:N]
print(list.count(1))

Submission status: Time Limit Exceeded

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

#Process
cnt = 0
Ans = 0
flag_AB = True 
while cnt < N:
    if(flag_AB):
        flag_AB = False
        if(cnt + A < N):
            Ans = Ans + A
        else:
            Ans = Ans + A - (cnt + A - N)
        cnt = cnt + A
    else:
        flag_AB = True
        cnt = cnt + B

#Output
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int, input().split()))
C=0
for i in range(N):
    if 0 < (i + 1) % (A + B) <= A:
        C += 1
print(C)

Submission status: Time Limit Exceeded

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

if A > N:
  print(N)
  
if A < N and A+B > N:
  print(A)
  
else:
  while len(list) <= N:
    i = 0
    for i in range(A):
      list.append('b')
      
    if len(list) <= N:
      i = 0
      for i in range(B):
        list.append('r')

  for i in range(N):
    if list[i] == 'b':
      count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
n, a, b = map(int, input().split())
# 計算

s = ''
i = 0
while i < n:
  for j in range(a):
    if i >= n: break
    s += 'b'
    i += 1 
  for k in range(b):
    if i >= n: break
    s += 'r'
    i += 1

# 出力
print(s.count('b'))

Submission status: Time Limit Exceeded

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

loop, m = divmod(N, A + B)
cnt_b = 0
cnt_all = 0
for _ in range(loop):
    cnt_b += A
if m < A:
    cnt_b += m
else:
    cnt_b += A
print(cnt_b)

Submission status: Time Limit Exceeded

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

b=0
r=0
while N>0:
    N-=A
    b+=A
    if N<=0:
        b+=N
        break

    N-=B
    r+=B
    if N<=0:
        break

print(b)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
if a == 0:
    print(0)
else:
    while count < 10**100:
        n -= a
        tmp += a
        if n <= 0:
            print(tmp + n)
            break
        n -= b
        if n <= 0:
            print(tmp)
            break

Submission status: Time Limit Exceeded

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

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

if n <= blue:
    print(n)
    exit()

cnt = 0

while True:
    if n > blue:
        cnt += blue
        n -= blue
        if n <= red:
            break
        elif n > red:
            n -= red
    else:
        cnt += n
        break
print(cnt)