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

s = []
flag = True
cnt = 0
while True:
    for i in range(a):
        if cnt > n:
            break
        s.append('b')
        cnt += 1
    for i in range(b):
        if cnt > n:
            break
        s.append('r')
        cnt += 1
    if cnt > n:
        break
print(s[:n].count('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')
    for j in range(b):
        ball_list.append('r')
    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 = 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
    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=map(int, input().split())
a=[]
c=1
y=0
C=int(N/(A+B)+1)
for i in range(A):
	a.append(1)
for j in range(B):
	a.append(0)
b=a.copy()
for k in range(C):
	a.extend(b)
for p in a:
	if N>=c:
		if p==1:
			y+=1
	c+=1
print(y)

Submission status: Time Limit Exceeded

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

if A > N:
  print(N)
  
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:
n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
if a == 0:
    print(0)
    exit(0)
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, bu, re = list(map(int, input().split(" ")))

ttlBu, ttlRe = 0, 0

while True:
    for _ in range(bu):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlBu += 1
    for _ in range(re):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlRe += 1

Submission status: Time Limit Exceeded

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

boals = []
roop = 0
for _ in range(N):
    if roop < A:
        boals.append('B')
        roop += 1
    elif roop < A + B - 1:
        boals.append('R')
        roop += 1
    else:
        boals.append('R')
        roop = 0
print(boals.count('B'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Line = ''

while(N > len(Line)):
  for i in range(B):
    Line += 'b'
  for i in range(R):
    Line += 'r'

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

print(ans)

Submission status: Time Limit Exceeded

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

S = []

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

print(S.count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
l = []
l_a = ['b' for i in range(A)]
l_b = ['r' for i in range(B)]
for val in range(N):
    l += l_a
    l += l_b
cnt = 0
for val in range(N):
    if l[val] == 'b':
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

l = ""
while len(l) < N:
    for i in range(A):
        if len(l) < N:
            l += "b"
    for j in range(B):
        if len(l) < N:
            l += "r"
    

print(l.count("b"))

Submission status: Time Limit Exceeded

Solution code:
N,a,b=map(int,input().split())
sum=0
blue=0
red=0
while sum<N:
    for n in range(a):
        if sum==N:
            break
        blue+=1
        sum+=1
    for m in range(b):
        if sum==N:
            break
        red+=1
        sum+=1
print(blue)

Submission status: Time Limit Exceeded

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

while N > 0:
  if cnt % 2 == 0:	# 青
    i = min(A, N)
    ball += i
  else:				# 赤
    i = min(B, N)
  N -= i
  cnt += 1

print(ball)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ball = []
kaisu = -(-N//(A+B))

for n in range(kaisu):
    for i in range(A):
        ball.append(0)
    for j in range(B):
        ball.append(1)

ball = ball[:N]

print(ball.count(0))

Submission status: Time Limit Exceeded

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

for n in range(N//(A+B) + 2):
    for a in range(A):
        ball_line += "b"
    for b in range(B):
        ball_line += "r"

print(ball_line[0:N].count("b"))

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
    if n != 0:
        for j in range(b):
            n -= 1
            if n == 0:
                break
print(count)

Submission status: Time Limit Exceeded

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

if n == a + b:
    print(a)
    exit()

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


while True:
    

    for i in range(a):
        
        if len(ans) == n:
            print(ans.count("b"))
            exit()
        ans.append("b")
        

    for j in range(b):
        if len(ans) == n:
            print(ans.count("b"))
            exit()
        ans.append("r")

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
tmp = []
while len(tmp) <= n:
  for i in range(a):
    tmp.append('b')
  for j in range(b):
    tmp.append('r')
ans = []
for k in range(n):
  ans.append(tmp[k])
print(ans.count('b'))

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
k=[]
ans=0
count=(n//(a+b))
bb=[]
aa=[]
for j in range(a):
    k.append('b')
for t in range(b):
    k.append('r')
kk=k
for i in range(count):
    for y in range(len(k)):
        kk.append(k[y])
print(kk[:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
import math

N,A,B = list(map(int,input().split()))
tama = []
kaisu = math.ceil(N /(A+ B))
for i in range(kaisu):
    for a in range(A):
        tama.append(0)
    for b in range(B):
        tama.append(1)

print(tama[0:N].count(0))

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
ans=0
count=0
Flag=False
waru=N//(A+B)
amari=N%(A+B)
for i in range (10**18):
    if amari==0:
        break
    for j in range(A):
        ans+=1
        count+=1
        if count==amari:
            Flag=True
            break
    for k in range(B):
        if Flag:
            break
        count+=1
        if count==amari:
            Flag=True
            break
    if Flag:
        break
print(ans+waru*A)

Submission status: Time Limit Exceeded

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

	counter = 1
	ans = 0
	i = 0
	while i <= n:
		if a != 0:
			if counter <= a:
				ans += 1
				counter += 1
				i += 1
			elif i < a+b:
				i += 1
				counter += 1
			else:
				counter = 0
				i += 1
		else:
			i += 1
	print(ans)
	

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-03-07 21:09:01 +0900
# LastModified: 2020-03-07 21:20:17 +0900
#

import collections

def main():
    N,A,B = map(int,input().split())
    S=[]
    for _ in range(10**100):
        for _ in range(A):
            S.append(0)
        for _ in range(B):
            S.append(1)
        if len(S)>N:
            break
    c=collections.Counter(S[:N])
    print(c[0])




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#B
n,a,b=map(int,input().split())
i=0
aa=[]
bb=[]
while n>0:
    if n<a:
        aa.append(n)
        break
    else:
        aa.append(a)
    n-=a
    if n<b:
        bb.append(n)
        break
    else:
        bb.append(b)
    n-=b
print(sum(aa))

Submission status: Time Limit Exceeded

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

c = 0
if A == 0:
    print(0)
    exit()
if B == 0:
    print(N)
    exit()
now = 'b'
b = 0
r = 0
for n in range(N):
    if now == 'b':
        c += 1
        b += 1
    else:
        r += 1
    if b == A:
        now = 'r'
        b = 0
    if r == B:
        now = 'b'
        r = 0
print(c)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = list(map(lambda x: int(x),input().split()))
ball_line = []

for n in range(N//(A+B) + 10):
    for a in range(A):
        ball_line.append("b")
    for b in range(B):
        ball_line.append("r")

print(ball_line[0:N].count("b"))

Submission status: Time Limit Exceeded

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

moji = ''

while len(moji) < N:
    for i in range(A):
        moji += 'b'
    for j in range(B):
        moji += 'r'

moji = moji[:N]

print(moji.count('b'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
st_a,st_b='',''
for i in range(A):
  st_a+='b'
for i in range(B):
  st_b+='r'
sum=0
b=''
while sum<=N:
  b+=st_a
  sum+=A
  if(sum>=N):
    break
  b+=st_b
  sum+=B
c=b[0:N]
print(c.count('b'))

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8

N,A,B=map(int,input().split())
data=[]
for i in range(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:
N, A, B = map(int, input().split())
list = []
count = 0

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:
List = [int(i) for i in input().split()]
bcou = 0
rcou = 0
for i in range(List[0]):
    if bcou < List[1]:
        bcou += 1
    elif rcou < List[2]:
        rcou += 1
    else:
        if bcou != 0:
            bcou += 1
        rcou = 0

print(bcou)

Submission status: Time Limit Exceeded

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

while c<n:
  c=c+a+b
  ans+=a
  
if c==n:
  print(ans)
else:
  if c-n<=b:
    print(ans)
  else:
    print(ans-c+n+b)

Submission status: Time Limit Exceeded

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

while tot > 0:
  tot -= a
  if tot > 0:
    count += a
  else:
    count += a+tot
  tot -= b
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = [int(y) for y in input().split(' ')]
count = 0
while N >= A:
  count += 1
  N -= A+B
if A == 0:
  print(0)
elif N > 0:
  print(count*A + N)
else:
  print(count*A)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=list(map(int,input().split()))
l=[]
for i in range(N):
    for j in range(A):
        l.append('r')
        if len(l) >= N:
            print(l.count(('r')))
            exit()
    for k in range(B):
        l.append('b')
        if len(l) >= N:
            print(l.count(('r')))
            exit()

print(l.count(('r')))

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, b, r = list(map(int, input().split()))
str = ''
loop, cnt = 0, 0
while(cnt <= N):
  if loop%2 == 0:
    for i in range(b):
    	str += 'b'
    cnt += b
  elif loop%2 == 1:
    for i in range(r):
    	str += 'r'
    cnt += r
  loop += 1
cnt = 0
for i in range(N):
  if str[i] == 'b':
    cnt += 1
print(cnt)

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'
    for i in range(b):
        s += 'r'

tmp = s[0:n]

print(tmp.count('b'))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

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

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

print(ans)

Submission status: Time Limit Exceeded

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

b=0
r=0
while b+r<N:
    for i in range(A):
        b+=1
        if b+r==N:
            break
    for j in range(B):
        r+=1
        if b+r==N:
            break
print(b)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
cnt=0
cnt_blue=0
while cnt+A+B<N:
    cnt+=A+B
    cnt_blue+=A
    
print(cnt_blue+min(A,N-cnt))

Submission status: Time Limit Exceeded

Solution code:
nums = input().split(" ")
N = int(nums[0])
A = int(nums[1])
B = int(nums[2])
time = 0

while N > (A + B):
  N -= (A + B)
  time += 1
if N - A <= 0:
  print(N + A*time)
else:
  print(A + A*time)

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
    balls = []
    while count<=N:
        count+=A
        count+=B
        for i in range(A):
            balls.append(1)
        for i in range(B):
            balls.append(0)
    return sum(balls[:N])

print(func())

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
count = 0
bcount = 0
turn = 0
while count <= n:
    if turn % 2 == 0:
        if count + a <= n:
            count += a
            bcount += a
        else:
            bcount += n - count
            count += n - count

    else:
        if count + b <= n:
            count += b
        else:
            count += b
    turn += 1
print(bcount)

Submission status: Time Limit Exceeded

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

    leng = 0
    ans = 0

    while n >= leng:
        if a < (n - leng):
            ans += a
            leng += (a + b)
        else:
            ans += n - leng
            leng += (a + b)

    print(ans)



    # if a >= n:
    #     print(n)
    # else:
    #     print(a)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    if len(l) >= n:
        print(l[0:n].count("r"))
        exit ()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, a, b = map(int, input().split())
    a_count = 0
    a_amari = 0
    while True:
        n = n - a
        if n < 0:
            a_amari = a + n
            break
        a_count += 1
        n = n - b
        if n <= 0:
            break

    print(a_count*a + a_amari)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

while len(list) <= N:
  i = 0
  for i in range(A):
    list.append('b')
  
  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:
N, A, B = map(int, input().split())

boals = []
roop = 0
for _ in range(N):
    if roop < A:
        boals.append('B')
        roop += 1
    elif roop < A + B - 1:
        boals.append('R')
        roop += 1
    else:
        boals.append('R')
        roop = 0
print(boals.count('B'))

Submission status: Time Limit Exceeded

Solution code:
#n,a,b
n,a,b=(int(x) for x in input().split())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    isBlue = True
    ret = []
    for n in range(N):
        for a in range(A):
            if len(ret) == N:
                break
            ret.append('b')

        for b in range(B):
            if len(ret) == N:
                break
            ret.append('r')

        if len(ret) == N:
            break

    print(ret.count('b'))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# n = int(input())
n, a, b = map(int, input().split())
# a = list(map(int, input().split()))
row = []
while len(row) < n:
    i = 0
    while i != a:
        row.append("b")
        # print(i)
        i += 1

    j = 0
    while j != b:
        row.append("r")
        # print(j)
        j += 1

cnt = 0
k = 1
for r in row:
    if k == n+1:
        break
    k += 1

    if r == "b":
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
ans=0
count=0
Flag=False
for i in range (10**100):
    for j in range(A):
        ans+=1
        count+=1
        if count==N:
            Flag=True
            break
    for k in range(B):
        if Flag:
            break
        count+=1
        if count==N:
            Flag=True
            break
    if Flag:
        break
print(ans)

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):
        str.append('b')
    for i in range(B):
        str.append('r')

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

l = ''

while len(l) < N:
    for i in range(A):
        l += 'b'
    for i in range(B):
        l += 'r'

ln = l[:N]

ans = ln.count('b')

print(ans)

Submission status: Time Limit Exceeded

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

x = ''
while True:
  if len(x) >= N:
    break

  for i in range(A):
    if len(x) >= N:
    	break
    x += 'b'

  for i in range(B):
    if len(x) >= N:
    	break
    x += 'a'
    
print(x.count('b'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
l = []
i = 0
res = 0

while i < n:
    save = i
    i += a
    if i < n:
        res += a
        i += b
    elif i > n:
        res += n - save

print(res)

Submission status: Time Limit Exceeded

Solution code:
L = input().split()
N = int(L[0])
A = int(L[1])
B = int(L[2])
blue = 0
for i in range(N):
    if i % (A + B) >= 0 and i % (A + B) <= (A - 1):
        blue += 1
print(blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
d = a+b
i=1
while True:
    if n/(i*d) == 1:
        count = i*a
        break
    elif n//(i*d) == 1 and n%(i*d)<=a:
        count = i*a + n%(i*d)
        break
    elif n//(i*d) == 1 and n%(i*d)>a:
        count = i*(a+1)
    i += 1 
print(count)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

ans =[]

for i in range((n//(a+b)) + 1):
  for j in range(a):
    ans.append("b")
    continue
  
  for k in range(b):
    ans.append("r")
    continue
    

num =0   
for l in range(n):
  if ans[l] == "b":
    num += 1
  
  
  
print(num)

Submission status: Time Limit Exceeded

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

b_counter = 0
total = 0
count = 0
color = "test"


while total < n:
  count += 1
  if (count % 2) == 1: #blue
    color="B"
    b_counter += a
    total += a
  else: #red
    color = "R"
    total += b
    
if color == "B":
  b_counter = b_counter - (total - n)
  print(b_counter)
else:
  print(b_counter)

Submission status: Time Limit Exceeded

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

s=0
c=0
while c+A<N:
    c=c+A+B
    s=s+A

if c>=N:
    print(s)
else:
    print(s+N-c)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
count=0
flag=True
counter=0
ans=0
while flag:
    if counter%2==0:
        if (N-A)<0:
            ans+=N
            N-=N
        else:
            ans+=A
            N-=A

    else:
        if (N-B)<0:
            N-=N
        else:

            N-=B


    if N<=0:
        flag=False
    counter+=1
print(ans)

Submission status: Time Limit Exceeded

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

ans1 = []
ans2 = []
while len(ans1) <= N:
    for i in range(A):
        ans1.append("b")
    for i in range(B):    
        ans1.append("r")
for i in range(N):
    if ans1[i] == "b":
        ans2.append(ans1[i])
print(len(ans2))

Submission status: Time Limit Exceeded

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

al = a
bl = b
cnt = 0
for i in range(n):
    if al != 0:
        cnt += 1
        al -= 1
    elif bl != 0:
        bl -= 1
    
    if al == 0 and bl == 0:
        bl = b
        al = a
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
ans = list()
a = "a"
b = "b"
while N > 0:
    for _ in range(A):
        ans.append(a)
        N = N - 1
        if N == 0:
            print(ans.count(a))
            exit()
    for _ in range(B):
        ans.append(b)
        N = N - 1
        if N == 0:
            print(ans.count(a))
            exit()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

s = 0
t = 0
while t < n:
  for i in range(a):
    s += 1
    t += 1
    if t == n:
      break
  for j in range(b):
    t += 1
    if t == n:
      break
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n, b, r = map(int, input().split())
count = 0
i = 0
while (n>i):
    for bi in range(b):
        count += 1
        i += 1
        if n <= i:
            break
    for ri in range(r):
        i += 1
        if n<=i:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
# N=総数、A=青、B=赤
N, A, B = map(int, input().split())

# 残りボールのカウント
a_r_bal = A
b_r_bal = B
# セットしたボールのカウント
a_s_bal = 0
b_s_bal = 0
for i in range(N):
    # a,bのボールなし
    if(a_r_bal == 0 and b_r_bal == 0):
        a_r_bal = A
        b_r_bal = B

    # aの残りボールあり
    if(a_r_bal > 0):
        a_r_bal -= 1
        a_s_bal += 1
    else:
        b_r_bal -= 1
        b_s_bal += 1
# 出力
print(a_s_bal)

Submission status: Time Limit Exceeded

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

while n_count < n:
    for i in range(a):
        if n_count >= n:
            break
        a_count += 1
        n_count += 1
    n_count += b

print(a_count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
lst = []
i = 0
while i < N:
    for j in range(A):
        lst.append("b")
        i += 1
    for k in range(B):
        lst.append("r")
        i += 1
# print("lst:", lst)
lst = lst[:N]
# print("lst:", lst)
print(lst.count('b'))

Submission status: Time Limit Exceeded

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

Ac = 0
Bc = 0

times = 0
length = 0

while length < N:
    if times % 2 == 0:
        length += A
        Ac += 1
    else:
        length += B
        Bc += 1
    
    times += 1

if times % 2 == 0:
    print(A*Ac)
else:
    print(A*Ac - (length - N))

Submission status: Time Limit Exceeded

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

ans =[]

for i in range(n):
  for j in range(a):
    ans.append("b")
    continue
  
  for k in range(b):
    ans.append("r")
    continue
    

num =0   
for l in range(n):
  if ans[l] == "b":
    num += 1
  
  
  
print(num)

Submission status: Time Limit Exceeded

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

i = 1
cnt = 0
while n > 0:
    if i % 2 != 0:
        if n-a > 0:
            n -= a
            cnt += a
        else:
            cnt += n
            n = 0
    else:
        n -= b
    i += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

lst = []
b = 0
r = 0

while b + r <= N:
  for i in range(0,A):
    lst.append("b")
    b += 1
  for i in range(0,B):
    lst.append("r")
    r += 1
    
print(lst[:N].count("b"))

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

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

Submission status: Time Limit Exceeded

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


balls = []
isFinish = True
count = 0
while isFinish:
    if len(balls) >= N:
        isFinish = False
    
    for i in range(A):

        if len(balls) >= N:
            isFinish = False
            break
        balls.append('b')
        count += 1
        

    for i in range(B):
        if len(balls) >= N:
            isFinish = False
            break
        balls.append('r')
        

print(count)

Submission status: Time Limit Exceeded

Solution code:
a,b,c=map(int,input().split())
d=0
e=0
ok=False
while True:
    for i in range(b):
        if d>=a:
            ok=True
            break
        d+=1
        e+=1
    if ok:
        break
    for i in range(c):
        if d>=a:
            ok=True
            break
        d+=1
    if ok:
        break
print(e)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
l = []
while(True):
    for i in range(a):
        l.append(1)
    for i in range(b):
        l.append(0)
    if len(l) >= n:
        break

print(sum(l[:n]))

Submission status: Time Limit Exceeded

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

while(N > 0):
  if current == "b":
    if N - A > 0:
      result += A
      N = N - A
    else:
      result += N
      N = 0
    current = "r"
  else:
    if N - B > 0:
      N = N - B
    else:
      N = 0
    current = "b"
print(result)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
ans = 0
count = 0
while(count < n):
  if count%(a+b) < a:
    ans+=1
  count+=1
print(ans)