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

li = []
while len(li) <= n:
  for i in range(a):
    li.append('b')
  for i in range(b):
    li.append('a')

ans = li[:n].count('b')

print(ans)

Submission status: Time Limit Exceeded

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

total = 0
blue = 0

for i in range(int(10e100)):
    if i % 2 == 0:  # blue
        total += a
        blue += a
        if total >= n:
            mod = total - n
            print(blue - mod)
            break
    else:  # red
        total += b
        if total >= n:
            print(blue)
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while len(lst) < N:
    for i in range(A):
        if len(lst) == N:
            break
        else:
            lst.append('b')
    for j in range(B):
        if len(lst) == N:
            break
        else:
            lst.append('r')

print(lst.count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split(' '))
blue = ''
red = ''
count = int(N / (A + B))

for i in range(A):
    blue = blue + 'b'
for i in range(B):
    red = red + 'r'
one_roop = blue + red
string = ''
for i in range(count):
    string = string + one_roop

if N % (A + B) != 0:
    string = string + one_roop[0:N % (A + B)]

print(string.count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split(' '))
blue_balls = 0
red_balls = 0
flag = 0
count = 0
while count < N:
    if flag == 0:
        if count + A > N:
            blue_balls += N - count
            count += A
            flag = 1
        else:
            blue_balls += A
            count += A
            flag = 1
    if flag == 1:
        red_balls += B
        count += B
        flag = 0

print(blue_balls)

Submission status: Time Limit Exceeded

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

cnt_blue = 0
# cnt_red = 0
total = 0

while(True):
    cnt_blue += A
    total += A
    if N <= total:
        cnt_blue = cnt_blue - (total - N)
        break 
#     cnt_red += B
    total += B
    if N <= total:
#         cnt_red = cnt_red - (total - N)
        break
print(cnt_blue)

Submission status: Time Limit Exceeded

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

cnt_blue = 0
cnt_red = 0
total = 0

while(True):
    cnt_blue += A
    total += A
    if N <= total:
        cnt_blue = cnt_blue - (total - N)
        break 
    cnt_red += B
    total += B
    if N <= total:
        cnt_red = cnt_red - (total - N)
        break
print(cnt_blue)

Submission status: Time Limit Exceeded

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

s = 0
t = 0
for i in range(10**100):
    t = t+b+r
    s += 1
    if N<=t:
        if (t-N)<r:
            print(s*b)
            exit()
        else:
            print((s-1)*b+N-t+b+r)
            exit()

Submission status: Time Limit Exceeded

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

while len(s) < n:
    for i in range(a):
        s += "b"
        if len(s) >= n :
            break
    for i in range(b):
        s += "a"
        if len(s) >= n :
            break
            
print(s.count("b"))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = [int(i) for i in input().split()]
#k=n//(a+b)
#ans=a*k+a*(n-(a+b))
ans=0
while n >= 0:
    ans+=min(a,n)
    n-=(a+b)
print(ans)

Submission status: Time Limit Exceeded

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

x = []
cnt = 0
flag = True
while cnt < n:
    if flag:
        for j in range(a):
            if cnt + j >= n:
                break
            x.append(1)
        cnt += a
        flag = False
    else:
        for j in range(b):
            if cnt + j >= n:
                break
            x.append(0)
        cnt += b
        flag = True

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

print(cnt)

Submission status: Time Limit Exceeded

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

ball = [0,0]
#左が青, 右が赤
while True:
    ball[0] += a
    if sum(ball) == n:
        print(ball[0])
        exit()
    elif sum(ball) > n:
        ball[0] -= sum(ball) - n
        print(ball[0])
        exit()
    
    ball[1] += b
    if sum(ball) >= n:
        print(ball[0])
        exit()

Submission status: Time Limit Exceeded

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

ball = [0,0]
#左が青, 右が赤
while True:
    for i in range(a):
        ball[0] += 1
        if sum(ball) == n:
            print(ball[0])
            exit()
    for i in range(b):
        ball[1] += 1
        if sum(ball) == n:
            print(ball[0])
            exit()

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
ans = 0
for i in range(n):
    if n - a >= 0:
        n -= a
        ans += a
    else:
        ans += n
        break
    if n - b >= 0:
        n -= b
    else:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
a = 0
b = 0
C = 0
while N > 0:
    C = N
    N = N - A
    if N > 0:
        a = a + A
    else:
        a = a + C
    N = N - B
print(a)

Submission status: Time Limit Exceeded

Solution code:
N,A,B =map(int,input().split())
D =[]
for i in range(N):
    for j in range(A):
        D.append("A")
    for k in range(B):
        D.append("B")

#print(D)

F =D[0:N]
#print(F)
print(F.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("b")
        if len(ball) >= n:
            break
    for x in range(b):
        ball.append("r")
        if len(ball) >= n:
            break

print(ball.count("b"))

Submission status: Time Limit Exceeded

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

ans=0
total=0

while True:
  total+=A
  ans+=A
  if total>=N:
    ans-=total-N
    break
  total+=B
  if total>=N:
    break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while n > 0:
    ans += min(n, b)
    n -= b + r

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
a=[]
while len(a) < N:
    for i in range(A):
        a.append("x")
    for j in range(B):
        a.append("y")
ans=a[:N]
print(ans.count("x"))

Submission status: Time Limit Exceeded

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

ans = 0

while N > 0:
    red = min(N, A)
    ans += red
    N -= red
    blue = min(N, B)
    N -= blue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
tama = 0
blue = 0
for i in range(10**100):
    if tama <= n:
        if tama + a >= n:
            blue += (n - tama)
            break
        tama += a
        blue += a

    if tama <= n:
        if tama + b >= n:
            break
        tama += b



print(blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
full=[]
while len(full)<n:
    for _ in range(a):
        full.append("b")
    for _ in range(b):
        full.append("r")
if len(full)>n:
    del full[n:-1]
print(full.count("b"))

Submission status: Time Limit Exceeded

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

for i in range(N):

  if count == A+B:
      count=0

  if A!=0 and count < A :
      blue+=1
      count+=1
  elif count < A + B:
      red+=1
      count+=1

print(blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
x=a
y=b
ct=0
while n>0:
  while n>0 and x>0:
    x=x-1
    n=n-1
    ct=ct+1
  while n>0 and y>0:
    y=y-1
    n=n-1
  x=a
  y=b
print(ct)

Submission status: Time Limit Exceeded

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

while True:
    if N <= 0:
        break
    C += min(N, A)
    N -= A + B

print(C)

Submission status: Time Limit Exceeded

Solution code:
n, b, r = map(int,input().split())
l = list()
k = 0
for i in range(0,n,b+r):
  for j in range(b):
    l.append('b')
  for j in range(r):
    l.append('r')
for j in range(b):
  l.append('b')
for j in range(r):
  l.append('r')
print(l[0:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
n, b, r = map(int,input().split())
l = list()
k = 0
for i in range(0,n):
  for j in range(b):
    l.append('b')
  for j in range(r):
    l.append('r')   
print(l[0:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:

N, A, B = list(map(int, input().split()))
i = 0
b = 0
r = 0
while i < N:
    if (i+A <= N):
        b += A
        i += A
    elif(i+A > N):
        b += N-i
        break
    if (i+B <= N):
        r += B
        i += B
    elif(i+B > N):
        r += N-i
        break        
print(b)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
su = 0
blue = 0
nn = 5**100

for i in range(nn):
    for x in range(0,a):
        if su < n:
            su += 1
            blue += 1
    for y in range(0,b):
        if su >= n:
            break
        su += 1
    else:
        continue
    break

print(str(blue))

Submission status: Time Limit Exceeded

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

while True:
    for x in range(0,a):
        if su < n:
            su += 1
            blue += 1
    for y in range(0,b):
        if su >= n:
            break
        su += 1
    else:
        continue
    break


print(str(blue))

Submission status: Time Limit Exceeded

Solution code:
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
l = ''
boll_a = ''
boll_b = ''
for j in range(0, a):
  boll_a += 'b'
for k in range(0, b):
  boll_b += 'r'
while n >= len(l):
  l += boll_a
  l += boll_b

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

Submission status: Time Limit Exceeded

Solution code:
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
boll_a = ''
boll_b = ''
count = ''
for j in range(0, a):
  boll_a += 'b'
for k in range(0, b):
  boll_b += 'r'
for i in range(0, n):
  count += boll_a
  count += boll_b
  if len(count) >= n: break
c = 0
for i in count[:n]:
  if i == 'b':
    c += 1
print(c)

Submission status: Time Limit Exceeded

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

for i in range(N):
  if A != 0:
    for _ in range(A):
      arr.append('b')
  if B != 0:
    for _ in range(B):
      arr.append('r')
print(arr[0:N].count('b'))

Submission status: Time Limit Exceeded

Solution code:
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
count = ''
for i in range(0, n):
  for j in range(0, a):
    count += 'b'
  for k in range(0, b):
    count += 'r'
  if len(count) >= n: break
c = 0
for i in count[:n]:
  if i == 'b':
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
l=[]
n,a,b=map(int,input().split())
for i in range(n):
    for i in range(a):
        l.append("b")
    for i in range(b):
        l.append("r")
#print(l)
count=0
retu=l[:n]
#print(retu)
count=retu.count("b")
print(count)

Submission status: Time Limit Exceeded

Solution code:
l=[]
n,a,b=map(int,input().split())
while len(l)<=n:
        for i in range(a):
            l.append("b")
        for i in range(b):
            l.append("r")
#print(l)
count=0
retu=l[:n]
#print(retu)
count=retu.count("b")
print(count)

Submission status: Time Limit Exceeded

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

count=0

count_blue=0

while count<N-(A+B):
    count_blue+=A
    count+=A+B

if N-count<A:
    count_blue+=N-count
    
else:
    count_blue+=A
    
print(count_blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
s=0
if n>=(a+b):

    while True:

        n=n-(a+b)

        s+=1

        if n-(a+b)<=0:

            break
        else:pass

    if n>=a:

        print(a*(s+1))
    else:
        print(a*s+n)

else:

    if n>=a:

        print(a)

    else:
        print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

numlist=[]

while len(numlist) <=N:
    for i in range(A):
        numlist.append(1)
    for i in range(B):
        numlist.append(0)
ans= 0
for i in range(N):
    if numlist[i] == 1:
        ans +=1
    else:
        continue
print(ans)

Submission status: Time Limit Exceeded

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


sum = 0
while(n > a):
    n = n-a-b
    sum += a
if n < 0:
    print(sum)
else:    
    print(sum+n)

Submission status: Time Limit Exceeded

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

List=[]

while len(List) < N:
    for i in range(A):
        List.append("b")
    for i in range(B):
        List.append("r")

for i in range (len(List)-N):
    del List[N]

print(List.count("b"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ans = 0
while N > 0 :
    for b in range(A) :
        ans += 1
        N -= 1
        if N == 0 :
            break
    for r in range(B):
        N -= 1
        if N == 0 :
            break
print(ans)

Submission status: Time Limit Exceeded

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

while N > 0:
  if N >= A + B:
    count += A
  else:
    count += min(A, N)
  N -= A + B

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input().split(" ")
n = int(s[0])
a = int(s[1])
b = int(s[2])
answer = []
blue = 0

for i in range(n+1):
  for j in range(a):
    answer.append(1)
  for j in range(b):
    answer.append(-1)
  
for i in range(n):
  if answer[i] == 1:
  	blue += 1
  
print(blue)

Submission status: Time Limit Exceeded

Solution code:
n , a , b = map(int , input().split())
s = []
while n > len(s):
    for i in range(a):
        s.append("a")
    for i in range(b):
        s.append("b")
del s[n::]
print(s.count("a"))

Submission status: Time Limit Exceeded

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

cnt = []
for n in range(10 ** 100):
    if len(cnt) == N:
        break
    for i in range(A):
        if len(cnt) == N:
            break
        cnt.append("b")
    for j in range(B):
        if len(cnt) == N:
            break
        cnt.append("r")
ans = collections.Counter(cnt)
print(ans["b"])

Submission status: Time Limit Exceeded

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

cnt = []
for n in range(10 ** 100):
    if len(cnt) == N:
        break
    for i in range(A):
        if len(cnt) == N:
            break
        cnt.append("b")
    for j in range(B):
        if len(cnt) == N:
            break
        cnt.append("r")
print(cnt.count("b"))

Submission status: Time Limit Exceeded

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

ans = 0

while n >= a+b:
    ans = ans + a
    n = n - (a+b)

if n >= a:
    ans = ans + a
else:
    ans = ans + n

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
capacity = N
is_a = True
cnt = 0

while capacity > 0:
    if is_a:
        ball = A
        cnt += min(capacity, ball)
    else:
        ball = B

    is_a = not is_a
    capacity -= min(capacity, ball)

print(cnt)

Submission status: Time Limit Exceeded

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

current_n = N
b_cnt = 0
flag = True
while current_n != 0:
    if flag:
        if current_n - A > 0:
            current_n = current_n - A
            b_cnt += A
        else:
            b_cnt += current_n
            current_n = 0
        flag = False
    else:
        if current_n - B > 0:
            current_n = current_n - B
        else:
            current_n = 0
        flag = True

print(b_cnt)

Submission status: Time Limit Exceeded

Solution code:
class atcoder:
    N,A,B= map(int,input().split())
    ans=0
    x=0
    i=0
    while(1):
        i+=1
        if x<N:
            if i<=A:
                ans+=1
                x+=1
            elif i>A and i<=A+B:
                x+=1
            else:
                i=0
        else:
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, A ,B =map(int,input().split())
blue =0
while N >0:
    blue += min(A,N)
    N -= min(A,N)
    N = max(N-B,0)
print(blue)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
N, A, B = map(int, input().split())
List = []

for z in range(ceil(N/(A+B))):
    for i in range(A):
        List.append('b')
    i = 0
    for i in range(B):
        List.append('r')

ans = ''.join(List)
ans = ans.count('b',0,N)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N, A, B = map(int, input().split())
List = []

for z in range(math.ceil(N/(A+B))):
    for i in range(A):
        List.append('b')
    i = 0
    for i in range(B):
        List.append('r')

ans = ''.join(List)
ans = ans.count('b',0,N)
print(ans)

Submission status: Time Limit Exceeded

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

c = 0


for i in range(0, n//(a+b)):
    c = a * (n//(a+b))

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

Submission status: Time Limit Exceeded

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

flag = True
count = 0
counts = 0
while flag == True:
  for i in range(b):
    count += 1
    counts += 1
    if counts == n:
      flag = False
      break
  for i in range(r):
    counts += 1
    if counts == n:
      flag = False
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
sum=0
while n>sum:
    sum+=(a+b)
x=sum//(a+b)-1
left=n-x*(a+b)
if left<=a:
    print(a*x+left)
else:
    print(a*x+a)

Submission status: Time Limit Exceeded

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

ans = 0
while n > 0:
    if n >= a:
        ans += a
        n -= a
    else:
        ans += n
        break
    n -= b

print(ans)

Submission status: Time Limit Exceeded

Solution code:
date=input().rstrip().split(" ")
num=int(date[0])
list0=[]
for i in range(num):
  j=0
  k=0
  for j in range(int(date[1])):
    list0.append("b")
  for k in range(int(date[2])):
    list0.append("r")
sum=0
for m in range(num):
  if list0[m]=="b":
    sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

num_blue = 0
num_all = 0
while 1:
    num_blue += A
    num_all += A
    if N <= num_all:
        num_blue -= num_all - N
    num_all += B
    if N <= num_all:
        break
    

print(num_blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
blues = []
reds = []
balls = []
for i in range(a):
  blues.append("b")
for i in range(b):
  reds.append("r")
while len(balls) < n:
  if a <= n-len(balls):
    balls.extend(blues)
  else:
    for i in range(n-len(balls)):
      balls.append("b")
  if b <= n - len(balls):
    balls.extend(reds)
  else:
    for i in range(n-len(balls)):
      balls.append("r")
print(balls.count("b"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Y,X = map(int,input().split())
lis = []
A = 1
while A == 1:
  for i in range(Y):
    if len(lis) == N:
      A = 0
      break
    lis.append("b")
  for i in range(X):
    if len(lis) == N:
      A = 0
      break
    lis.append("r")
  
print(lis.count("b"))

Submission status: Time Limit Exceeded

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

que = []

for i in range(N//(A+B)+1):
    for j in range(A):
        que.append('b')
    for j in range(B):
        que.append('r')

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
totalBalls, blueBalls, redBalls= list(map(int,input().split()))
currentBalls=0
countBlueStack=0
answer=0
countStack=0
totalStack=blueBalls + redBalls
while currentBalls<totalBalls:
  currentBalls+=totalStack
  countStack+=1

if currentBalls>totalBalls:
  answer = (countStack-1) * blueBalls
  before=totalStack*(countStack-1)
  difference = totalBalls-before
  if difference>= blueBalls: answer+=blueBalls
  else: answer+=difference
else: answer=(countStack)*blueBalls
print(answer)

Submission status: Time Limit Exceeded

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

for _ in range(0, N):
    for _ in range(0, A):
        list.append('b')
    for _ in range(0, B):
        list.append('r')

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
trig=True
reds=0
blues=0
while N>0:
	if trig:
		if N<A:
			blues+=N
		else:
			blues+=A
		N-=A
		trig=False
	else:
		reds+=B
		N-=B
		trig=True

print(blues)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, A, B = (int(x) for x in input().split())
s = ""
while True:
    for i in range(A):
        if len(s) != N:
            s += "b"
        else:
            break

    for j in range(B):
        if len(s) != N:
            s += "r"
        else:
            break
    if len(s) == N:
        break

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

n, a, b = map(int, input().split())
l = []
while len(l) <= n:
    for _ in range(a):
    	l.append("b")
    for _ in range(b):
        l.append("r")

print(l[:n].count("b"))

Submission status: Time Limit Exceeded

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

list = []
for _ in range(N):
    [list.append('b') for i in range(A)]
    [list.append('c') for j in range(B)]

a = list[:N:]
print(a.count("b"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

num = 0
blue = 0
red = 0
for i in range(10**18):
    if i % 2 == 0 and N >= num:
        num += A
        blue += 1
    elif i % 2 == 1 and N >= num:
        num += B
        red += 1

    else:
        break
# print(num)
# print(blue)
# print(red)

if blue > red:
    aa = N - A * blue - B * red
    ans_b = A * blue + aa
else:
    aa = N - A * blue - B * red
    ans = B * red + aa
    ans_b = N - ans

print(ans_b)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
for i in range(N):
    if i*(A+B) < N <= (i+1)*(A+B):
        print(min(N-i*B, (i+1)*A))

Submission status: Time Limit Exceeded

Solution code:
n, a, b = input("").split()
n = int(n)
a = int(a)
b = int(b)
inc = 0
result = 0
BOOL = True
while inc < n:
    if BOOL is True:
        if (n - inc) >= a:
            result += a
            inc += a
            BOOL = False
        else:
            result += (n - inc)
            break
    else:
        if (n - inc) >= b:
            inc += b
            BOOL = True
        else:
            break

print(result)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = input("").split()
n = int(n)
a = int(a)
b = int(b)
inc = 0
result = 0
BOOL = True
while inc < n:
    if BOOL is True:
        if (n-inc) >= a:
            result += a
            inc +=a
            BOOL = False
        else:
            result += (n-inc)
            break
    if BOOL is False:
        if (n-inc) >= b:
            inc += b
            BOOL = True
        else:
            break

print(result)

Submission status: Time Limit Exceeded

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

while (len(l) < N):
  tmp  = ['b' for i in range(A) if (len(l) + i) < N]
  tmp2 = ['r' for i in range(B) if (len(l) + len(tmp) + i) < N]
  l += (tmp + tmp2)

print(l.count('b'))

Submission status: Time Limit Exceeded

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

while (len(l) < N):
  tmp  = ['b' for i in range(A) if (len(l) + i) < N]
  tmp2 = ['r' for i in range(B) if (len(l) + len(tmp) + i) < N]
  l.extend(tmp)
  l.extend(tmp2)
print(l.count('b'))

Submission status: Time Limit Exceeded

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

blue = [1 for _ in range(A)]
red = [0 for _ in range(B)]
tkhs = []
while len(tkhs) < N:
    tkhs += (blue + red)
print(sum(tkhs[: N]))

Submission status: Time Limit Exceeded

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

while boolean:
    if n - a > 0:
        n -= a
        cnt += a
    else:
        cnt += n
        boolean = False
    if n - b > 0:
        n -= b
    else:
        boolean = False
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
x=input().split(" ")
n=int(x[0])
a=int(x[1])
b=int(x[2])
t=0
i=0
while t<=n:
    if t+a>n:
        i+=n-t
        break
    i+=a
    t+=a
    t+=b
print(i)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
n=0
while True:
    N-=A
    if N<=0:
        print(n+(A+N))
        break
    n+=A
    N-=B
    if N<=0:
        print(n)
        break

Submission status: Time Limit Exceeded

Solution code:
# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = map(int, input().split())
rmult = 0
bmult = 0
total = 0
it = 1
ended = ''
while n > total:
    total += a
    bmult += 1
    ended = 'b'
    if n > total:
        total += b
        rmult += 1
        ended = 'r'
if ended == 'b':
    numofb = a * bmult - (total - n)
else:
    numofb = a * bmult
print(numofb)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
count=0
while N>0:
  for i in range(A):
    if N>0:
      count+=1
      N-=1
    else:
      break
  for i in range(B):
    if N>0:
      N-=1
    else:
      break
print(count)

Submission status: Time Limit Exceeded

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

while n>0:
  for i in range(a):
    count+=1
    n-=1
    if n==0:
      break
  for i in range(b):
    n-=1
    if n==0:
      break

if a==0:
  print(0)
else:
  print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.readline().split()))
a = LI()
sum = a[0]
b = 0
while sum > 0:
  if sum - a[1] >= 0:
    b += a[1]
    sum -= a[1]
  else:
    b += sum
    sum = 0
  sum -= a[2]
print(b)

Submission status: Time Limit Exceeded

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.readline().split()))
a = LI()
sum = a[0]
b = 0
while sum >= 0:
  if sum - a[1] >= 0:
    b += a[1]
    sum -= a[1]
  else:
    b += sum
    sum = 0
  sum -= a[2]
print(b)

Submission status: Time Limit Exceeded

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

ans = 0
while n > a+b:
    ans += a
    n -= a+b

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

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
N,A,B = (int(x) for x in input().split(" "))

# 赤と青を並べる
retu = ""
for j in range(N//(A +B) + 1):
    for i in range(A):
        retu += "b"
    for i in range(B):
        retu += "r"

b_num = retu[:N].count("b")
print(b_num)

Submission status: Time Limit Exceeded

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

ans = 0

while n > 0:
  if n >= a:
    n -= a
    ans += a
    n -= b
  else:
    ans += n
    n = -1
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

while n > 0:
  for i in range(a):
    if n > 0:
      n-=1
      ans+=1
  n -= b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def detect_collor(num, blue_ball, red_ball):
    string = ''
    while len(string) < num:
        for i in range(blue_ball):
            string += 'b'
        for i in range(red_ball):
            string += 'r'
    return string[:num]

nums, blue_balls, red_balls = map(int, input().split())

ans = detect_collor(nums, blue_balls, red_balls)
print(ans.count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = input().rstrip().split(' ')
N = int(N)
A = int(A)
B = int(B)
n = int(N / (A+B)) * A
m = N % (A+B)

b = ''
r = ''
br = ''
for _ in range(A):
    b += 'b'
for _ in range(B):
    r += 'r'
br = b+r
print(n + br[:m].count('b'))

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
x=[]
for i in range(1,N+A+B):
  for j in range(A):
    x.append("a")
  for k in range(B):
    x.append("b")
   
x=x[:N]
print(x.count("a"))

Submission status: Time Limit Exceeded

Solution code:
input_lines=list(map(int,input().split()))
balls=[]
count=0
for i in range(10**100):
    for j in range(input_lines[1]):
        balls.append('b')
    for j in range(input_lines[2]):
        balls.append('r')
    if len(balls)>input_lines[0]:
        break
for i in range(input_lines[0]):
    if balls[i]=='b':
        count+=1
print(count)