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:
# 入力の取得
i = list(map(int, input().split()))
kazoeru = i[0]
ao = i[1]
aka= i[2]
kaisuu = i[0]/(i[1]+i[2])

number = 0
list = []

# リスト作成
while number <= kaisuu:
    # 青いボールを追加
    ball = 0
    while ball < ao:
        list.append("ao")
        ball += 1

    # 赤いボールを追加
    ball = 0
    while ball < aka:
        list.append("aka")
        ball += 1
    #回数加算
    number += 1

# 青ボールを数える
number = 0
aonokazu = 0
while number < kazoeru:
    if list[number] == "ao":
        aonokazu += 1
    number += 1

print(aonokazu)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while a_b<n:
    for i in range(a):
        if a_b<n:
            a_b += 1
            blue_ball += 1
    
    for i in range(b):
        if a_b < n:
            a_b += 1
      
print(blue_ball)

Submission status: Time Limit Exceeded

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

while a_b<n:
    for i in range(a):
        if a_b<n:
            a_b += 1
            blue_ball += 1
    
    for i in range(b):
        if a_b < n:
            a_b += 1
      
print(blue_ball)

Submission status: Time Limit Exceeded

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

for i in range(len(l)-n):
    l.pop(-1)
print(l.count("b"))

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
L = []
if 1<=N<=(10**18):
    if A >= 0 and B >= 0:
        if 0 < (A+B) <= (10**18):
            for k in range(0,N):
                for i in range(0,A):
                    L.append("b")
                for j in range(0,B):
                    L.append("r")
K = []
for h in range(0,N):
        K.append(L[h])
print(K.count("b"))

Submission status: Time Limit Exceeded

Solution code:
i = list(map(int, input().split()))

N = int(i[0])
A = int(i[1])
B = int(i[2])

l = []

while len(l) < N:
    for i in range(A):
        if len(l) == N:
            break
        l.append(0)

    for i in range(B):
        if len(l) == N:
            break
        l.append(1)
        
print(l.count(0))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = input().split()
s = []
gokei = 0
b_sum = 0
n = int(n)
a = int(a)
b = int(b)
while gokei < n:
  b_sum += a
  gokei += a
  if gokei > n:
    b_sum = b_sum - (gokei - n)
    break
  gokei += b
print(b_sum)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = input().split()
s = []
gokei = 0
b_sum = 0
n = int(n)
a = int(a)
b = int(b)
while gokei < n:
  b_sum += int(a)
  gokei += int(a)
  if gokei > n:
    b_sum = b_sum - (gokei - n)
    break
  gokei += int(b)
print(b_sum)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = input().split()
res = 0
n = int(n)
a = int(a)
b = int(b)
ab = a+b
sul = 0
sub = 0

while res < n:
  res += ab
  sul += a
if res > n:
  if res-n > b:
    sub = (res-n) - b
print(sul-sub)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = input().split()
s = []
gokei = 0
b_sum = 0
n = int(n)

while gokei < n:
  b_sum += int(a)
  gokei += int(a)
  if gokei > n:
    b_sum = b_sum - (gokei - n)
    break
  gokei += int(b)
  
print(b_sum)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = input().split()
s = []
a_cnt = 0
b_cnt = 0
b_sum = 0
flag = 'a'
s = []

for i in range(int(n)+2):
  if flag == 'a':
      if a_cnt == int(a):
          flag = 'b'
          a_cnt=0
      else:
        s.append('a')
        a_cnt += 1
        b_sum += 1
  else:
    if b_cnt == int(b):
      flag='a'
      b_cnt = 0
    else:
      s.append('b')
      b_cnt += 1
print(b_sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
rem = N
blue_cnt = 0
while rem >= 0:
    rest = rem - A
    if rest >= 0:
        blue_cnt += A
        rem -= A
        rest = rem - B
        if rest < 0:
            print(blue_cnt)
            exit()
        else:
            rem -= B
    else:
        blue_cnt += rem
        print(blue_cnt)
        exit()

Submission status: Time Limit Exceeded

Solution code:
n,b,r=map(int,input().split())
blue=True
c=0
while n>0:
    if blue:
        x=b if n>b else n
        c+=x
        n-=x
    else:
        n-=r if n>r else n
    blue=(not blue)
print(c)

Submission status: Time Limit Exceeded

Solution code:
input_line = list(input("").split(" "))
N = int(input_line[0])
A = int(input_line[1])
B = int(input_line[2])
sum_of_ball = 0
prev_sum = 0
count = 0
while sum_of_ball < N:
  prev_sum = int(sum_of_ball)
  sum_of_ball += A + B
  count += 1
rest = N -prev_sum
if rest <= A:
  print(A*(count-1) + rest)
else:
  print(A*count)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
res=0
N1=N//(A+B)
N2=N%(A+B)+1
if A==0:
    res=0
elif B==0:
    res=N
else:
    res1=(N1)*A
    res2=0
    for n in range(1,N2):
        if n<=A:
            res2+=1
    res=res1+res2
print(res)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
res=0
if A==0:
    res=0
else:
    res1=(N//(A+B))*A
    res2=0
    for n in range(1,N%(A+B)+1):
        if n<=A:
            res2+=1
    res=res1+res2
print(res)

Submission status: Time Limit Exceeded

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

for k in range(0,n):
  for i in range(0,a):
    ikd.append("b")
  for j in range(0,b):
    ikd.append("r")
ikd2=[0]*n
for l in range(0,n):
  ikd2[l]=ikd[l]

g=ikd2.count("b")
print(g)

Submission status: Time Limit Exceeded

Solution code:
n,b,r=map(int,input().split())
alist=[]
count=0

while len(alist)<n:
  for i in range(b):
    alist.append('b')
  for i in range(r):
    alist.append('r')

del alist[n:]

for i in alist:
  if i=='b':
    count+=1

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Aball = ""
for i in range(a):
    Aball+="b"
Bball = ""
for i in range(b):
    Bball+="a"

t = ""
while len(t) <= n:
    t+=Aball
    if len(t)>n:
        t = t[:n]
        break
    t+=Bball
    if len(t)>n:
        t = t[:n]
        break
count = t.count("b")
print(count)

Submission status: Time Limit Exceeded

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

N, A, B = input().split() 
balls = []
bBalls = []
rBalls = []

for i in range(int(A)):
    rBalls.append("b")

for i in range(int(B)):
    rBalls.append("r")

answer = 0
isBreak = False
for i in range(10**100):
   balls = bBalls + rBalls + balls
   if( len(balls) > int(N) ) :
       for c in range(int(N)):
           if(balls[c] == "b") :
               answer = answer +1
               isBreak = True
       isBreak = True
   if( isBreak ) :
       break

print(answer)

Submission status: Time Limit Exceeded

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

array = []

for t in range(10 ** 18):
    if len(array) >= n:
        break
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(f * a + g)
    
else:
    print(f * (a+1))

Submission status: Time Limit Exceeded

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

array = []

for t in range(10 ** 100):
    if len(array) >= n:
        break
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')

f = n // (a+b)
g = n % (a+b)

if g <= a:
    print(f * a + g)
    
else:
    print(f * (a+1))

Submission status: Time Limit Exceeded

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

array = []

for t in range(10 ** 100):
    if len(array) >= n:
        break
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')

x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Submission status: Time Limit Exceeded

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

array = []

for t in range(10 ** 100):
    if len(array) < n:
        for p in range(a):
            array.append('blue')
        for q in range(b):
            array.append('red')
    else:
        break

x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Submission status: Time Limit Exceeded

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

array = []

for t in range(10 ** 100):
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')
    if len(array) > n:
        break
    
x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Submission status: Time Limit Exceeded

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

array = []

t = 0

while t < 10 ** 100:
    for p in range(a):
        array.append('blue')
    for q in range(b):
        array.append('red')
    t += 1
    
x = 0

for i in range(n):
    if array[i] == 'blue':
        x += 1

print(x)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
# n, a, b = 8, 3, 4
ans = ""
for i in range(n):
    for k in range(a):
        if len(ans) == n:
            break
        ans += "b"
    for j in range(b):
        if len(ans) == n:
            break
        ans += "r"
print(ans.count("b"))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, input().split()))

n = s[0]
blue = s[1]
red = s[2]

temp = []

while n >= 0:
    for i in range(blue):
        temp.append(1)
    for i in range(red):
        temp.append(0)
    n -= (blue + red)

print(sum(temp[:n]))

Submission status: Time Limit Exceeded

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

a = 0
while N > 0:
  N -= A
  if N >= 0:
  	a += A
  else:
    a += A + N
  N -= B

print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

Result = 0
Count_Blue = 0
if 1<=N<=10**18 and A >= 0 and B >= 0 and \
   0< A + B <= 10**18:
    for Count in range(10**100):
        Result = Result + (1 * A)
        Count_Blue += (1 * A)
        if Result > N:
            Count_Blue = Count_Blue - (Result - N)
            print(Count_Blue)
            sys.exit()
        Result = Result + (1 * B)
        if Result > N:
            print(Count_Blue)
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys

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

Result = 0
Count_Blue = 0
if 1<=N<=10**18 and A >= 0 and B >= 0 and \
   0< A + B <= 10**18:
    for Count in range(1,10**100+1):
        for i in range(A):
            if Result < N:
                Result = Result + 1
                Count_Blue += 1
            else:
                print(Count_Blue)
                sys.exit()
        Result = Result + 1 * B

        if Result > N:
            print(Count_Blue)
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys

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

Result = 0

Count_Blue = 0
if 1<=N<=10**18 and A >= 0 and B >= 0 and \
   0< A + B <= 10**18:
    for Count in range(1,10**100+1):
        if Result < N:
            Mod = Count % 2
            if Mod==1:
                for i in range(A):
                    if Result < N:
                        Result = Result + 1
                        Count_Blue += 1
            elif Mod==0:
                Result = Result + 1 * B
        else:
            print(Count_Blue)
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
n,blue,red = (int(x) for x in input().split())
ls = []
total = 0
while total < n:
    bu = 0
    while bu < blue:
        if total >= n:
           break
        ls.append("b")
        bu += 1
        total += 1

    re = 0
    while re < red:
        if total >= n:
           break
        ls.append("r")
        re += 1
        total +=1

answer = ls.count("b")
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int, input().split()))
char_num = 0
counter = 0
while char_num < N:
  for a in range(A):
    if char_num >= N:
      break
    counter += 1
    char_num += 1
  for b in range(B):
    if char_num >= N:
      break
    char_num += 1
print(counter)

Submission status: Time Limit Exceeded

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

rcnt = 0
bcnt = 0
while True:
    if bcnt + rcnt + A >= N:
        bcnt += N-(bcnt+rcnt)
        break
    else:
        bcnt += A
        
    if bcnt + rcnt + B >= N:
        rcnt += N-(bcnt+rcnt)
        break
    else:
        rcnt += B

print(bcnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
ans=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:
n, a, b = map(int, input().split())
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
            if len(l) == n:
                break
        flag = False
    else:
        for y in range(b):
            l += "r"
            if len(l) == n:
                break
        flag = True

    if len(l) >= n:
        break

         
for c in l:
    if c == "b":
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
        flag = False
    else:
        for y in range(b):
            l += "r"
        flag = True

    if len(l) >= n:
        break
    
for c in range(n):
    if l[c] == "b":
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
while True:
    n, a, b = map(int, input().split())
    if 1 <= n <= 10**18 and 0 <= a + b <= 10**18:
        break
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
        flag = False
    else:
        for y in range(b):
            l += "r"
        flag = True

    if len(l) >= n:
        break
    
for c in range(n):
    if l[c] == "b":
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
while True:
    n, a, b = map(int, input().split())
    if 1 <= n <= 10**18 and 0 <= a + b <= 10**18:
        break
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
        flag = False
    else:
        for y in range(b):
            l += "r"
        flag = True

    if len(l) >= n:
        for c in range(n):
            if l[c] == "b":
                count += 1
        break

print(count)

Submission status: Time Limit Exceeded

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

l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
        flag = False
    else:
        for y in range(b):
            l += "r"
        flag = True

    if len(l) >= n:
        for c in range(n):
            if l[c] == "b":
                count += 1
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
# N, A, B
num, greenNum, redNum = map(lambda x: int(x), input().split(' '))

# output
totalGreen = 0
while (num > 0):
  if (num <= greenNum):
    totalGreen += num
    num = 0
  else:
    totalGreen += greenNum
    num -= (greenNum + redNum)
    
print(totalGreen)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

lst = []
is_blue = True
count = 0
for i in range(n):
    if is_blue:
        lst.append('b')
        count += 1
        if count == a:
            is_blue = False
            count = 0
    else:
        lst.append('r')
        count += 1
        if count == b:
            is_blue = True
            count = 0

result = list(filter(lambda x:x == 'b', lst))
print(len(result))

Submission status: Time Limit Exceeded

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

i = 0
while num - (i * (blue + red)) > 0:
    i += 1


if num - ((i - 1) * (blue + red)) > blue:
    print(blue * (i - 1) + blue)
else:
    print(blue * (i - 1) + (num - (i - 1) * (blue + red)))

Submission status: Time Limit Exceeded

Solution code:
import sys
N, A, B = map(int, input().split())
count = 0
while True:
    for i in range(A):
        N -= 1
        count += 1
        if N == 0:
            print(count)
            sys.exit()
    for j in range(B):
        N -= 1
        if N == 0:
            print(count)
            sys.exit()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

num = input().split()
num = [int(N) for N in num]

answer = 0
num[0] -= num[1]
answer += num[1]

while num[0]>num[2]:
    num[0] -= num[2] + num[1]
    answer += num[1]
if num[0]<0:
    answer -= 0 - num[0]
    
print(answer)

Submission status: Time Limit Exceeded

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

ball_n = [0, 0]

while sum(ball_n) != n:
    for _ in range(a):
        ball_n[0] += 1
        if sum(ball_n) == n:
            break
    
    if sum(ball_n) == n:
        break
    
    for _ in range(b):
        ball_n[1] += 1
        if sum(ball_n) == n:
            break

print(ball_n[0])

Submission status: Time Limit Exceeded

Solution code:
import math
N, A, B = (int(x) for x in input().split(' '))
ans = 0
#
for i in range(N):
  if i % (A+B) < A:
    ans += 1
#結果出力
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,blue,red = list(map(int, input().split()))
b=("")
r=("")
count=0
for j in range (blue):
    b=str(b)+"b"
    j+=1

for i in range (red):
    r=str(r)+"r"
    i+=1
while (1):
       count+=1
       M=N-(blue+red)*count
       if M < 0:
        break
if  M+blue+red>blue:
    print(blue*(count-1))
else:print((count-1)*blue+M+blue+red)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = int(S.split(' ')[0])
A = int(S.split(' ')[1])
B = int(S.split(' ')[2])
 
b_count = 0
for i in range(0, N):
  if i % (A+B) < A:
    b_count = b_count + 1
print(b_count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = int(S.split(' ')[0])
A = int(S.split(' ')[1])
B = int(S.split(' ')[2])
#print(A+B)
 
b_count = 0
for i in range(0, N):
  #print('i')
  #print(i)
  if i % (A+B) < A:
    #print(b_count)
    b_count = b_count + 1
print(b_count)

Submission status: Time Limit Exceeded

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

while i < N:
	for x in range(A):
		if i >= N:
			break
		blue += 1
		i += 1
	for y in range(B):
		if i >= N:
			break
		red += 1
		i += 1
print(blue)

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int,input().split())
n=0
S=''
flag=False
while True:
    for i in range(A):
        S+='b'
        n+=1
        if n==N:
            flag=True
            break
    if flag:
        break
    
    for i in range(B):
        S+='r'
        n+=1
        if n==N:
            flag=True
            break
    if flag:
        break
    
cnt=0
for i in S:
    if i=='b':
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, A, B = list(map(int,input().split()))
t = np.array([],dtype=np.int16)
for _ in range(A):
  t = np.append(t,1)
for _ in range(B):
  t = np.append(t,0)
  
L = len(t)

if N == L:
  print(np.sum(t))
elif N < L:
  print(np.sum(t[0:N]))
elif N > L:
  Q = N // L
  R = N % L
  ANS = Q*(np.sum(t))+np.sum(t[0:R])
  print(ANS)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int,input().split()))
t = []
for _ in range(A):
  t.append(1)
for _ in range(B):
  t.append(0)
  
L = len(t)

if N == L:
  print(sum(t))
elif N < L:
  print(sum(t[0:N]))
elif N > L:
  Q = N // L
  R = N % L
  ANS = Q*sum(t)+sum(t[0:R])
  print(ANS)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int,input().split()))
t = []
for _ in range(A):
  t.append(1)
for _ in range(B):
  t.append(0)
  
L = len(t)

if N == L:
  print(sum(t))
elif N < L:
  for _ in range(L-N):
    del t[-1]
    print(sum(t))
elif N > L:
  Q = N // L
  R = N % L
  ANS = Q*sum(t)
  for _ in range (L-R):
    del t[-1]
  ANS = ANS + sum(t)
  print(ANS)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B_fix
# CreatedDate:  2020-03-07 22:34:34 +0900
# LastModified: 2020-03-07 22:46:29 +0900
#




def main():
    N,A,B=map(int,input().split())
    s=int(N/(A+B))
    tmp = s*(A+B)
    count=A*s
    for i in range(A):
        if(tmp==N):
            break
        tmp+=1
        count+=1
    print(count)




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
a = list(map(int,input().split()))
N = a[0]
A = a[1]  #blue
B = a[2]  #red

blue = 0
red = 0
b = 0
r = 0
flag = 0



for i in range(1, N):
    if flag == 0 and b < A:
        b = b + 1
        blue = blue + 1
        #print(blue)
        #print('b')
    if b == A:
        #blue = blue + 1
        flag = 1
        b = 0
        #i -= 1
        #print(blue)
        #print('blue')
    if flag == 1 and r < B:
        r = r + 1
        #print('r')
        #print(r)
    if  r == B:
        flag = 0
        r = 0
        i -= 1
        #print('red')

print(blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
blue = ''.join(['b' for i in range(a)])
red = ''.join(['r' for i in range(b)])
s = str()
while len(s) < n:
    s += blue
    if len(s) >= n:
        break
    s += red
    
print(s[:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
blue = ''.join(['b' for i in range(a)])
red = ''.join(['r' for i in range(b)])
s = str()
while len(s) < n:
    s += blue + red
    
print(s[:n].count('b'))

Submission status: Time Limit Exceeded

Solution code:
N, B, R = map(int, input().split())
sum_B = (N // (B+R)) * B
n = N % (B+R)
if n == 0:
  print(sum_B)
elif n > B:
  sum_B += B
  print(sum_B)
else:
  for _ in range(n):
    sum_B += 1
  print(sum_B)

Submission status: Time Limit Exceeded

Solution code:
N, B, R = map(int, input().split())
sum_B = 0
sum = 0
while 1:
  sum += (B + R)
  sum_B += B
  if sum > N:
    if (sum - N) > R:
      sum_B -= ((sum - N) - R)
      print(sum_B)
      break
    else:
      print(sum_B)
      break

Submission status: Time Limit Exceeded

Solution code:
N,A,B=map(int, input().split())
C=0
D=int(N/(A+B))
 
for i in range(D):
	C+=A
	N=N-(A+B)
if N>=A:
	C+=A
else:
	C+=N
print(C)

Submission status: Time Limit Exceeded

Solution code:
class CountBalls:
    def __init__(self):
        self.result = 0
    def calculate(self, total_num, a, b):
        for i in range(total_num):
            result = a*i + b*i
            if result >=total_num:
                diff = total_num - a*(i-1) - b*(i-1) 
                if diff >=a:
                    self.result = a*(i-1) + a
                    break
                else:
                    self.result = a*(i-1) + diff
                    break
        return self.result

if __name__ == '__main__':
    N, A, B=list(map(int, input().split()))
    cb = CountBalls()
    result =cb.calculate(N, A, B)
    print(str(result))

Submission status: Time Limit Exceeded

Solution code:
class CountBalls:
    def __init__(self):
        self.result = 0
    def calculate(self, total_num, a, b):
        for i in range(total_num):
            result = a*i + b*i
            if result >=total_num:
                diff = total_num - a*(i-1) - b*(i-1) 
                if diff >=a:
                    self.result = a*(i-1) + a
                    break
                else:
                    self.result = a*(i-1) + diff
                    break
        return self.result

if __name__ == '__main__':
    R=list(map(int, input().split()))
    N = int(R[0])
    A = int (R[1])
    B = int (R[2])
    cb = CountBalls()
    result =cb.calculate(N, A, B)
    print(str(result))

Submission status: Time Limit Exceeded

Solution code:
S = input().split(" ")

n = int(S[0])
blue = int(S[1])
countB = 0
red = int(S[2])
countR = 0
shuki = blue + red
sh = 0
for i in range(1,n+1):
  amari = i % shuki
  if amari >=1 and amari <= blue:
    countB = countB +1
  else:
    countR = countR + 1
print(countB)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = [int(i) for i in input().split()]
s = []
for _ in range(n//(a+b)+1):
    s += [1 for _ in range(a)] + [0 for _ in range(b)]
print(sum(s[:n]))

Submission status: Time Limit Exceeded

Solution code:
n, a, b = [int(i) for i in input().split()]
c = 0
s = []
while c < n:
  s += [1 for _ in range(a)]
  s += [0 for _ in range(b)]
  c = len(s)
print(sum(s[:n]))

Submission status: Time Limit Exceeded

Solution code:
x, y, z = map(int, input().split())
blist = []
while len(blist) <= x:
    for i in range(y):
        blist.extend("b")
    for j in range(z):
        blist.extend("r")
blist = blist[:x]
num = blist.count("b")
print(num)

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(a):
        ans.append("b")
        cnt += 1
        if cnt == n:
            print(ans.count("b"))
            exit()
    for k in range(b):
        ans.append("r")
        cnt += 1
        if cnt == n:
            print(ans.count("b"))
            exit()

Submission status: Time Limit Exceeded

Solution code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

# print(Line)

N,a,b = Line[0],Line[1],Line[2]


x = 0
text = ""

# print(a)

while x*a+x*b < N:
    x += 1
    for i in range(a):
        text += "a"
    for i in range(b):
        text += "b"
# print(text)

text = text[:N]

print(text.count('a'))

Submission status: Time Limit Exceeded

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

balls = []

for i in range(10**100):
  for a in range(A):
    if len(balls) < N:
      balls.append('b') 
    else:
      break

  for b in range(B):
    if len(balls) < N:
      balls.append('r')
    else:
      break
      
  if len(balls) >= N:
    break

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

Submission status: Time Limit Exceeded

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

x = 0
a = 0

while x < N:
  x = x + A
  a = a + A
  x = x + B
  
if x > N + B:
  a = a - (x - B - N) 
    
print(a)

Submission status: Time Limit Exceeded

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

x = 0
a = 0

while x < N - A:
  x = x + A
  a = a + A
  x = x + B
  
while x < N:
  x = x + 1
  a = a + 1
    
print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

blue_count = 0
blue_ball_num = 0
N = take_number - blue_ball

for i in range(10 ** 100):
  if blue_ball == 0:
    break
  if N < 0:
    blue_ball_num = blue_ball - abs(N)
    break
  else:
    blue_count = blue_count + 1
    N = N - red_ball
    if N <= 0:
      break
    else:
      N = N - blue_ball
  
num = (blue_ball * blue_count) + blue_ball_num
print(num)

Submission status: Time Limit Exceeded

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

for i in range(input_line[0]):
    if input_line[1] > 0:
        for i in range(input_line[1]):
            input_line[0] -= 1
            blue += 1
            if input_line[0] == 0:
                break
        if input_line[0] == 0:
            break
        if input_line[2] > 0:
            for n in range(input_line[2]):
                input_line[0] -= 1
                red += 1
                if input_line[0] == 0:
                    break
            if input_line[0] == 0:
                    break
    else:
        if input_line[2] > 0:
            for n in range(input_line[2]):
                input_line[0] -= 1
                red += 1
                if input_line[0] == 0:
                    break
            if input_line[0] == 0:
                    break
print(blue)