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:
tmp = input().split()
N =int(tmp[0])
B =int(tmp[1])
R =int(tmp[2])

cnt = 0
bCnt = 0

while cnt < N:
  bCnt = bCnt + B
  cnt = cnt + B + R

if cnt - R >N:
   bCnt = bCnt - (cnt - R - N )

print(bCnt)

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
Aq = [i for i in l if (i == "b")]
print(len(Aq))

Submission status: Time Limit Exceeded

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

print(blue)

Submission status: Time Limit Exceeded

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

l=[]
while len(l) < n:
    for i in range(a):
        if len(l) < n:
            l.append('b')
        else:
            break
    for j in range(b):
        if len(l) < n:
            l.append('r')
        else:
            break

print(l.count('b'))

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
Aq = [i for i in l if (i == "b")]
print(len(Aq))

Submission status: Time Limit Exceeded

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

while ball < N-A-B:
    for i in range(A):
        ball+=1
        ball_b+=1
    for j in range(B):
        ball+=1
        ball_r+=1
x = min(N-ball,A)
print(ball_b+x)

Submission status: Time Limit Exceeded

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


count = 0

while n >= 0:
    if n >=0:
        count += 1
        n -= rb

blue1 = count * A
blue2 = N - count * rb

if blue2 > A:
    print(A+blue1)
else:
    print(blue2+blue1)

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

l=[]
while len(l) < n:
    for i in range(a):
        if len(l) < n:
            l.append('b')
    for j in range(b):
        if len(l) < n:
            l.append('r')

print(l.count('b'))

Submission status: Time Limit Exceeded

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

ans = 0
test = 0
while n > test:
    test += a + b
    if n >= test:
        ans += a
    else:
        x = test - n
        if x > b:
            ans += a - (x - b)
        else:
            ans += a

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
tmp = input().split()
N =int(tmp[0])
B =int(tmp[1])
R =int(tmp[2])

cnt = 0
bCnt = 0

while cnt < N:
  if cnt + B >N:
    bCnt = bCnt + (N -cnt)
  else:
    bCnt = bCnt + B
  cnt = cnt + B + R

print(bCnt)

Submission status: Time Limit Exceeded

Solution code:
n = list(map(int, input().split()))
l = []

cb = ''
balls = ''

for i in range(n[1]):
    cb += 'b'
for i in range(n[2]):
    cb += 'r'

for i in range(n[0]):
    balls += cb
    if len(balls) > n[0]:
        break

bcnt = balls.count('b', 0, n[0])

print(bcnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
s=0
d = 0
sa = 0
flag = False
for i in range(10000000000000000000):
    s = s + A
    d = d + A
    if s >= N:
        flag = True
        break
    s = s + B
    if s >= N:
        break

if flag == True:
    sa = s - N
    d = d - sa
print(d)

Submission status: Time Limit Exceeded

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

blue_count = 0
blue_ball_num = 0
N = take_number - blue_ball
loop = 10 ** 100

for i in range(loop):
  if N < 0:
    N = N * (-1)
    blue_ball_num = blue_ball - 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:
tmp = input().split()
N =int(tmp[0])
B =int(tmp[1])
R =int(tmp[2])

cnt = 0
bCnt = 0

while cnt < N:
  if cnt + B >N:
    bCnt = bCnt + (N -cnt)
  else:
  	bCnt = bCnt + B
  cnt = cnt + B + R

print(bCnt)

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 = [int(x) for x in input().split()]
n = 0
blue = 0
if A == 0:
    print(0)
else:
    for i in range(10**18):
        n = n + A
        blue = blue + A
        if n >= N:
            blue = blue - (n-N)
            break
        else:
            n = n + B
            if n >= N:
                break
    print(blue)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
for i in range(10**9):
    if i*(a+b)==n:
        print(a*i)
        exit()
    elif i*(a+b)>n:
        t = n-(i-1)*(a+b)
        if t>a:
            t = a
        print((i-1)*a+t)
        exit()

Submission status: Time Limit Exceeded

Solution code:
N,A,B = list(map(int, input().split()))
C = []
count = 0
while count < N:
#while True:
  if count >= N:
    break
  for i in range(A):
    C.append("b")
    count += 1
    if count >= N:
      break
  if count >= N:
    break
  for j in range(B):
    C.append("a")
    count += 1
    if count >= N:
      break
  if count >= N:
    break

#D = [C for i in range(N-1)]
#print(C)
P = [i for i in C if i == "b"]
print(len(P))

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]
print(hints.count('b'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
initInput = input()
tmpList = initInput.split()
inputN = int(tmpList[0])
inputA = int(tmpList[1])
inputB = int(tmpList[2])
arrayList = []
num = 0
arrayNum = 0
blueballNum = 0
while len(arrayList)  < inputN:
    if num % 2 == 0:
        for a in range(inputA):
            arrayList = arrayList +  ['a']
            arrayNum = arrayNum + 1
            blueballNum = blueballNum + 1
    else:
        for b in range(inputB):
            arrayList = arrayList +  ['b']
            arrayNum = arrayNum + 1

    num += 1

blueballNum = blueballNum - (len(arrayList) - inputN)
    
print(blueballNum)

Submission status: Time Limit Exceeded

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

cnt=0
ans=0

while cnt<N:
    if cnt%(A+B)<A:
        cnt+=1
        ans+=1
    else:
        cnt+=1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
for i in range(10**18):
    if i*(a+b)==n:
        print(a*i)
        exit()
    elif i*(a+b)>n:
        t = n-(i-1)*(a+b)
        if t>a:
            t = a
        print((i-1)*a+t)
        exit()

Submission status: Time Limit Exceeded

Solution code:
n = list(map(int, input().split()))
l = []

cb = ''
cr = ''

for i in range(n[1]):
    cb += 'b'
for i in range(n[2]):
    cr += 'r'

balls = ''

for i in range(n[0]):
    balls += cb
    balls += cr

bcnt = balls.count('b', 0, n[0])

print(bcnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
n,a,b=map(int,input().split())
count=0
if a==0:
  print('0')
  sys.exit()
else:
  while n>=a:
    n=n-a
    count+=1
    if n>=b:
      n=n-b
    elif n<b:
      n=0
ball=a*count+n
print(ball)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
 
if A == 0:
  ans = 0;
else:
  ans = 0
  i = N
  for i in range(N,0,-(A+B)):
    if i - A <= 0:
      ans += i
      break
    ans += A
    i = i - A
    i = i - B
    if i <= 0:
      break

print(ans)

Submission status: Time Limit Exceeded

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

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])

if( b == 0 ):
  print( 0 )
else:
  cntb = 0
  while( n > 0 ):
    cntb += min( b, n )
    n -= (b + r)
    
  print( cntb )

Submission status: Time Limit Exceeded

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

x = ''
y = ''
z = ''
zz =''
for i in range(a):
  x = x + '0'

for i in range(b):
  y = y + '1'

zz = x + y

for i in range(int(n/len(zz))+1):
  z = z + x + y

print(z[:n].count('0'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if A == 0:
  print(0)
  exit()
  
for _ in range(N):
  for i in range(A):
    if len(str) < N:
      str += 'b'
  for j in range(B):
    if len(str) < N:
      str += 'r'

print(str.count('b'))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
for i in range(10**100):
    if i*(a+b)==n:
        print(a*i)
        exit()
    elif i*(a+b)>n:
        t = n-(i-1)*(a+b)
        if t>a:
            t = a
        print((i-1)*a+t)
        exit()

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
s=0
d = 0
sa = 0
for i in range(10000000000000000000):
    s = s + A
    d = d + A
    if s >= N:
        sa = s - N
        d = d - sa
        break
    s = s + B
    if s >= N:
        break
print(d)

Submission status: Time Limit Exceeded

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

while N >= pair:
  N -= pair
  count += 1

if N <= A:
  ans = count*A + N
else:
  ans = count*A + A

print(ans)

Submission status: Time Limit Exceeded

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

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])

if( b == 0 ):
  print( 0 )
else:
  cntb = 0
  while( n > 0 ):
    cntb += min( b, n )
    n -= (b + r)
  print( cntb )

Submission status: Time Limit Exceeded

Solution code:
initInput = input()
tmpList = initInput.split()
inputN = int(tmpList[0])
inputA = int(tmpList[1])
inputB = int(tmpList[2])
arrayList = []
num = 0
arrayNum = 0
while len(arrayList)  < inputN:
    if num % 2 == 0:
        for a in range(inputA):
            arrayList = arrayList +  ['a']
            arrayNum = arrayNum + 1
    else:
        for b in range(inputB):
            arrayList = arrayList +  ['b']
            arrayNum = arrayNum + 1

    num += 1

blueballNum = 0
for num in range(inputN):
    if arrayList[num] == 'a':
        blueballNum = blueballNum + 1
    
print(blueballNum)

Submission status: Time Limit Exceeded

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

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

x = 0
a = 0

while x < N:
  y = 0
  z = 0
  while y < A and x < N:
    a = a + 1
    y = y + 1
    x = x + 1
  while z < B and x < N:
    z = z + 1
    x = x + 1
    
print(a)

Submission status: Time Limit Exceeded

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

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])

bcnt = min( n, b )

if( b == 0 ):
  print( 0 )
else:
  cntb = 0
  while( n > 0 ):
    cntb += min( b, n )
    n -= (b + r)
  print( cntb )

Submission status: Time Limit Exceeded

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

for i in range(N):
    if flg == 'A' and num < A:
        cnt += 1
        num += 1
        if num == A:
            num = 0
            flg = 'B'
    elif flg == 'B' and num < B:
        num += 1
        if num == B:
            num = 0
            flg = 'A'
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#B
n,a,b=map(int,input().split())
aa=0
for i in range(n//(a+b)+1):
    if n<a:
        aa+=n
        break
    else:
        aa+=a
    n-=a+b
print(aa)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
s=0
d = 0
for i in range(10000000000000000000):
    s = s + A
    d = d + A
    if s >= N:
        sa = s - N
        d = d - sa
        break
    s = s + B
    if s >= N:
        break
print(d)

Submission status: Time Limit Exceeded

Solution code:

def main():
    n, a, b = map(int, input().split())
    flag = True
    res = n
    count = 0
    if a == 0:
        print(0)
        exit(0)
    count = res // (a + b)
    res = n - ( ( a + b ) * count )
    a_count = 0
    while True:
        if a_count == a or res == 0:
            break
        res -= 1
        a_count += 1
           
    print( a_count + a * count)
    
    


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int, input().split())
sum=0
d = 0
for i in range(10000000000000000000):
    sum = sum + A
    d = d + A
    if sum >= N:
        sa = sum - N
        d = d - sa
        break
    sum = sum + B
    if sum >= N:
        break
print(d)

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 22:09:06 +0900
#

import collections

def main():
    N,A,B = map(int,input().split())
    count=0
    k=0
    for _ in range(10**100):
        for _ in range(A):
            k+=1
            count+=1
            if k==N:
                print(count)
                return 0
        for _ in range(B):
            k+=1
            if k==N:
                print(count)
                return 0




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

_N = N

for i in range(pow(10, 100)):
    if A == 0:
        print('0')
        break
    if B == 0:
        print(N)
        break
    if _N <= A:
        print(i * A + _N)
        break
    _N = _N - A
    if _N - B < 0:
        print((i + 1) * A)
        break
    else:
        _N = _N - B

Submission status: Time Limit Exceeded

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

while input_line[0] >= 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)

Submission status: Time Limit Exceeded

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

sum=0
d = 0
while True:
    sum = sum + A
    d = d + A
    if sum >= N:
        sa = sum - N
        d = d - sa
        break
    sum = sum + B
    if sum >= N:
        break
print(d)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
blue = 0
for balls in range(1,N+1):
  if balls <= A:
    blue += 1
  elif A+B < balls <= 2*A + B:
    blue += 1
  elif 2*(A+B) < balls <= 3*A +2*B:
    blue += 1
  elif 3*(A+B) < balls <= 4*A +3*B:
    blue += 1
  elif 4*(A+B) < balls <= 5*A +4*B:
    blue += 1
  elif 5*(A+B) < balls <= 6*A +5*B:
    blue += 1
  elif 6*(A+B) < balls <= 7*A +6*B:
    blue += 1
  elif 7*(A+B) < balls <= 8*A +7*B:
    blue += 1
  balls += 1
print(blue)

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')
"""

while blue+red < N:
    if flag == 0 & b<A:
        b += 1
        blue += 1
    if b == A:
        flag = 1
        b = 0
    if flag == 0 & r<B:
        r += 1
        red += 1
    if r == B:
        flag = 0
        r = 0
"""""

print(blue)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
ball = []
import sys
cnt = 0
while 1:
    for i in range(A):
        ball += [0]
        cnt += 1
        if len(ball)==N:
            print(cnt)
            sys.exit()
    for j in range(B):
        ball += [1]
        if len(ball)==N:
            print(cnt)
            sys.exit()

Submission status: Time Limit Exceeded

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

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

ball=a*count+n

print(ball)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

cnt = 0
_N = N

for i in range(pow(10, 100)):
    if A == 0:
        print('0')
        break
    if B == 0:
        print(N)
        break
    if _N <= A:
        print(cnt * A + _N)
        break
    cnt = cnt + 1
    _N = _N - A
    if _N - B < 0:
        print(cnt * A)
        break
    else:
        _N = _N - B

Submission status: Time Limit Exceeded

Solution code:
N, A, B=map(int,input().split())
llist=[N]
for i in range(N-1):
    if i<A or (i>B+1) and A>1  :
       llist.append("blue")
    else :
        llist.append("red")
print(llist.count("blue"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, b, r = map(int, input().split())
ans = N // (b + r) * b
N = N % (b + r)
for i in range(N):
    if b:
        ans += 1
        b -= 1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

A_list = [1 for i in range(A)]
B_list = [0 for v in range(B)]
S = A+B
S_list = A_list + B_list
total = []
for _ in range(N//S + 1):
  total.extend(S_list)
cnt = 0

for x in range(N):
  cnt = cnt + total[x]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

x=n//(a+b)*a       # (a+b)個までで入っている青の数（入力例1の場合，3個）
y=n%(a+b)       # nを(a+b)で割った余り（入力例1の場合，1個）

for i in range(y):
    x += 1
    cnt += 1
    
    if cnt == a:
        break

print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def red(out,count,N):
    for i in range(count):
        if(len(out)==N):
            break
        out.append("r")
    return out

def blue(out,count,N):
    for i in range(count):
        if(len(out)==N):
            break
        out.append("b")
    return out

NAB=np.array(input().split(" "),dtype=np.int32)

N=NAB[0]
A=NAB[1]
B=NAB[2]

out=[]

while(True):
    if(len(out)==N):
        break
    out=blue(out,A,N)
    out=red(out,B,N)

print(out.count("b"))

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
blue = 0
for balls in range(1,N+1):
  if balls <= A:
    blue += 1
  elif A+B < balls <= 2*A + B:
    blue += 1
  elif 2*A+2*B < balls <= 3*A +2*B:
    blue += 1
  balls += 1
print(blue)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = (int(x) for x in input().split())
x = 0
y = 0
while (1):
    for i in range(a):
        if(y == n):
            break
        x += 1
        y += 1
    for i in range(b):
        if(y == n):
            break
        y += 1
    if(y == n):
        break
print(x)

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:
N, A, B=map(int,input().split())
llist=[N]
for i in range(N-1):
    if i<A:
       llist.append("blue")
    elif (i>B+1) and A>1 :
       llist.append("blue")
    else :
        llist.append("red")

print(llist.count("blue"))

Submission status: Time Limit Exceeded

Solution code:
a,b,c=map(int,input().split())
l=[]
k=0
for i in range(a):
    for g in range(b):
        l.append("1")
    for g in range(c):
        l.append("2")
for j in range(a):
    if l==[]:
        k=0
        break
    elif l[j]== "1":
        k+=1
print(k)

Submission status: Time Limit Exceeded

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

for i in range(N):
    if i < A:
        cnt += 1
        num += 1
    elif i < A + B:
        num += 1
    elif i < A + B + A:
        cnt += 1
        num += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, b, r = map(int, input().split())
x = []
bool = True
while bool:
    for i in range(b):
        if len(x) == n:
            bool = False
        else:
            x.append("b")
    for j in range(r):
        if len(x) == n:
            bool = False
        else:
            x.append("r")

print(x.count("b"))

Submission status: Time Limit Exceeded

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

ball = []
ans = 0
for k in range(N//(A+B)) :
    for i in range(A) :
        ball.append('b')
    for j in range(B) :
        ball.append('r')

mod = N % (A+B)
for l in range(N % (A+B)) :
    for m in range(A) :
        if mod > 0 :
            ball.append('b')
            mod -= 1
        else :
            break
    for n in range(B):
        if mod > 0 :
            ball.append('r')
            mod -= 1
        else :
            break

#print(ball)
ans = ball.count('b')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, b, r = map(int, input().split())
b_tmp, r_tmp = b, r
ans = 0
for i in range(N):
    if b_tmp:
        ans += 1
        b_tmp -= 1
    elif r_tmp:
        r_tmp -= 1
    if b_tmp or r_tmp:
        pass
    else:
        b_tmp, r_tmp = b, r
print(ans)

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 += [0]
        if len(ball)==N:
            break
    if len(ball)==N:
        break
    for j in range(B):
        ball += [1]
        if len(ball)==N:
            break
    if len(ball)==N:
        break

print(ball.count(0))

Submission status: Time Limit Exceeded

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

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


list = []

for t in range(10**100):
	for i in range(A):
  		list.append('b')
	for i in range(B):  
  		list.append('r')
 
count = 0
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()))
N = N_A_B[0]
A = N_A_B[1]
B = N_A_B[2]

count = 0
retu = []
while count < 10 ** 100 and count < N:
    count += 1
    for index in range(A):
        retu.append(1)
    for index in range(B):
        retu.append(0)
retu = retu[0:N]
print(sum(retu))

Submission status: Time Limit Exceeded

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

for i in range(N):
	if N>A:
		C+=A
	elif N<A:
		C+=N
	N=N-(A+B)
	if N<0:
		break
print(C)

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 += [0]
        if len(ball)==N:
            break
    for j in range(B):
        ball += [1]
        if len(ball)==N:
            break
print(ball.count(0))

Submission status: Time Limit Exceeded

Solution code:
n, a, b = list(map(int, input().split()))
extra = n % (a +b)
roop = n // (a +b)
result = a*roop
cycle = [1 for _ in range(a)] +  [0 for _ in range(b)]
if extra != 0:
  for i in range(extra):
    result += cycle[i]
print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

while input_line[0] >= 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
    else:
        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)

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 < 1:
            break
        else:
            n -= 1
            ans += 1
    for i in range(b):
        if n < 1:
            break
        else:
            n -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n, a, b = map(int, input().split(' '))
  a_ = a
  b_ = b
  s = ''
  
  for i in range(n):
    if a_ > 0:
      s += 'b'
      a_ -= 1
    else:
      s += 'r'
      b_ -= 1
      
    if a_ == 0 and b_ == 0:
      a_ = a
      b_ = b
      
  print(s.count('b', 0, n))
  
  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import sys

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

r = bu = 0
bur = a+b
wk = n//bur
bu = wk*a
amari = n%bur
n -= wk*bur

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

Submission status: Time Limit Exceeded

Solution code:
n = list(map(int, input().split()))
N = n[0]
B = n[1]
A = n[2]
 
 
r = 0
while N >=0:
 
    if N <= B:
        print(N+r)
        break
        
    elif N >B and N<= A+B:
        print(B+r)
        break
        
    else:
        N = N -(A+B)
        r +=B

Submission status: Time Limit Exceeded

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

balls= 0
blue = 0

for i in range(10**18):
  if i % 2 == 0:
    if (balls + a) >= n:
      fill = n - balls
      balls = balls + fill
      blue = blue + fill
      break      
    balls = balls + a
    blue = blue + a
  else:
    if (balls + b) >= n:
      fill = n - balls
      balls = balls + fill
      break
    balls = balls + b

print(blue)

Submission status: Time Limit Exceeded

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

count = 0
while(True):
    val = n - a

    if val > 0:
        n = val
        count += a
    else:
        count = count + a  +  val
        break
    n -= b
    if n <= 0:
        break
print(count)