Problem:


Score : 400 points

Problem Statement

Snuke has one biscuit and zero Japanese yen (the currency) in his pocket.
He will perform the following operations exactly K times in total, in the order he likes:

Hit his pocket, which magically increases the number of biscuits by one.

Exchange A biscuits to 1 yen.

Exchange 1 yen to B biscuits.

Find the maximum possible number of biscuits in Snuke's pocket after K operations.

Constraints

1 \leq K,A,B \leq 10^9

K,A and B are integers.

Input

Input is given from Standard Input in the following format:

K A B

Output

Print the maximum possible number of biscuits in Snuke's pocket after K operations.

Sample Input 1

4 2 6

Sample Output 1

7

The number of biscuits in Snuke's pocket after K operations is maximized as follows:

Hit his pocket. Now he has 2 biscuits and 0 yen.

Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.

Hit his pocket. Now he has 1 biscuits and 1 yen.

Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.

Sample Input 2

7 3 4

Sample Output 2

8

Sample Input 3

314159265 35897932 384626433

Sample Output 3

48518828981938099



Sample input:
4 2 6


Sample output:
7

Submission status: Wrong Answer

Solution code:
a=input()
b=a.split()
k=int(b[0])
A=int(b[1])
B=int(b[2])
count=1
coin=0
for i in range(k):
    if coin==1:
        count+=B
        coin-=1
    elif count<=A and i!=k:
        count+=1
    else:
        count-=A
        coin+=1

print(count)

Submission status: Wrong Answer

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

cnt = 1

if K < A:
    cnt += K + 1
    print(cnt)
    exit()

rest = K - (A - 1)
cnt += (A - 1)

if (B - A) > 2:
    if (rest%2 == 0):
        cnt += (B - A) * (rest / 2)
    else:
        cnt += (B - A) * ((rest - 1) / 2)
        cnt += 1
else:
    cnt += rest

print(int(cnt))

Submission status: Wrong Answer

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

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

if a+2>b|k<=a+1:
    print(k+1)
else:
    s=k-a+1
    print(int(s/2)*(b-a)+a+(s%2))

Submission status: Wrong Answer

Solution code:
k,a,b=map(int,input().split())
if b-a>1:
  k=k-(a-1)
  if k%2 == 0:
    print(int(a+k/2*(b-a)))
  else:
    print(int(a+(k-1)/2*(b-a)+1))
else:
  print(1+k)

Submission status: Wrong Answer

Solution code:
KAB = [int(x) for x in input().split()]
K = KAB[0]
A = KAB[1]
B = KAB[2]
count = 1
if (A - B <= 1) or K <= A:
    print(K + 1)
else:
    count = A
    K = K - A + 1
    if K % 2 == 1:
        print(B - A, K // 2)
        count = count + 1 + (B - A) * (K // 2)
    else:
        count += (B - A) * K // 2
    print(count)

Submission status: Wrong Answer

Solution code:
k,a,b = map(int,input().split())
if a>=b-2:
    print(1+k)
elif a==1 and k>=2:
    print(1+(b-a)*(k//2)+(k%2))
elif k<=a+1:
    print(1+k)
else:
    alpha = k-(a+1)
    print(b+(b-a)*(alpha//2)+(alpha%2))

Submission status: Wrong Answer

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

if B<=A+2 or K<=A+1 :
    print(K+1)
else:
    if (K-(A-1))%2==0:
        print(A+(B-A)*((K-(A-1))//2))
    else:
        print(A+(B-A)*((K-(A-1))//2)+1)

Submission status: Wrong Answer

Solution code:
import math

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


if(b>a+2):

	rem = k-a+1
	if(rem%2==0):
		n=(b-a)*rem//2+a
	else:
		n=(b-a)*rem//2+1
	print(n)
	
else:
	print(1+k)

Submission status: Wrong Answer

Solution code:
def main():
  K, A, B = map(int, input().split())

  if ((B-A) <= 2):
    print(str(K+1))
    return
  
  a = ((K+1) // (A+2))
  print(str(1 + K + a * (B - A - 2)))
  return

main()

Submission status: Wrong Answer

Solution code:
K,A,B = map(int,input().split())
if A+2>=B:
  print(K+1)
elif K <= A:
  print(int(K+1))
elif (K-A+1)%2 == 0:
  print(int(((K-A+1)*(B-A)/2)+A))
else:
  print(int(((K-A)*(B-A)/2)+A+1))

Submission status: Wrong Answer

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

if b-a <= 2:
    print(1+k)
else:
    if k < a+1:
        print(a+1)
    else:
        p = (k-a)//2
        if (k-a-1)%2 == 0:
            print((1+p)*b-p*a)
        else:
            print(p*b+1)

Submission status: Wrong Answer

Solution code:
k, a, b = map(int, input().split())
ans = 1
cnt = 0

if (b / a) / 2 > 1:
    ans += a - 1
    cnt += a - 1
    
    x = (k - (a - 1)) // 2
    ans += (b - a) * x
    cnt += 2 * x
    
    ans += k - cnt
    
else:
    ans = 1 + k
    
print(ans)

Submission status: Wrong Answer

Solution code:
k,a,b=map(int,input().split())
bis=1
i=0
ans=0
if a>b-2:
    print(bis+k)
else:
    while i<k:
        while bis<a:
            ans+=1
            i+=1
            if i==k:
                break
        if i==k:
            break
        i+=1
        if i==k:
            ans+=1
            break
        ans+=b
        i+=1
    print(ans)

Submission status: Wrong Answer

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

def solve(A,B,K):
    if A>=B-1:
        return K+1
    K-=(A-1)
    if K%2==0:
        return int(A+(B-A)*(K/2))
    else:
        return int(A+(B-A)*((K-1)/2)+1)

print(solve(A,B,K))

Submission status: Wrong Answer

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

if a>=b-2:
  print(k+1)
else: 
  tataku = (a-1)
  nokori = k-(a-1)
  koukan_times = nokori//2

  bisuket = a + (b-a)*koukan_times

  if koukan_times%(1+b) == 1:
    print(bisuket+1)
  else:
      print(bisuket)

Submission status: Wrong Answer

Solution code:
K, A, B =map(int,input().split())
import sys
should_actAB = (B-A)
if should_actAB<=2:
    print(K+1)
    sys.exit()

else:
    ans_cookie=1
    K_=K-(A-1)
    print(K_)
    ans_cookie+=(A-1)
    print(ans_cookie)
    if K_%2==0:
        ans_cookie+=should_actAB*(K_)//2
    else:
        ans_cookie+=should_actAB*(K_-1)//2+1

Submission status: Wrong Answer

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

ans = 0
if B <= A + 2:
	ans = 1+K
else:
	if K <= A:
		ans = 1+K
	else:
		K -= A-1
		print(K)
		if K % 2 == 1:
			ans += 1
			K -= 1
		N = K//2
		ans += A+(B-A)*N

print(ans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    K, A, B = LI()
    result = 0
    # 交換する価値もない
    if A >= B - 1:
        # 割りまくる
        result = K + 1
        print(result)
        return

    # 交換をできるだけする
    # 最初に円にできるまでにどれだけかかるか？？
    times_to_first_yen = A - 1
    # K - times_to_first_yenはひたすら交換しまくる
    remaining_times = (K - times_to_first_yen) // 2
    result += remaining_times * (B - A) + A
    # 端数の処理をする
    if remaining_times % 2 != 0:
        result += 1

    print(result)


main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

line=input().split()
K=int(line[0])
A=int(line[1])
B=int(line[2])

b_rate=B/A

i=0

if K<=A:
    print(A+1)
    exit(0)

sum=A
K-=A-1

if b_rate>2:
    sum+=K//2*(B-A)
    if K%2==1:
        sum+=1
else:
    sum+=K
print(sum)

Submission status: Wrong Answer

Solution code:
K,A,B = map(int,input().split())
K += 1
if K >= A + 1 and A + 1 < B:
  ans = int((K - A) / 2) * (B - A) + A + (1 if K % 2 == 1 else 0)
  print(ans)
else:
  ans = K
  print(ans)

Submission status: Wrong Answer

Solution code:
k,a,b = map(int,input().split())
if a>=b-2:
    print(1+k)
elif k<=a+1:
    print(1+k)
else:
    alpha = k-(a+1)
    print(b+(b-a)*(alpha//2)+(alpha%2))

Submission status: Wrong Answer

Solution code:
K,A,B = map(int,input().split())
a = 1+K
K = K-A-1
if K % 2 == 0:
	b = A+(B-A)*(int(K/2))
else:
	b = A+(B-A)*(int(K/2))+1

print(max(a,b))

Submission status: Wrong Answer

Solution code:
K,A,B = list(map(int,input().split()))
if A>=B-1:
    answer = K+1
else:
  # gutyoku
    first = A
    rest = K - A -1
    if rest%2==0:
        answer = (rest/2+1)*B - (rest/2)*A
    else:
        #print('else')
        answer = ((rest-1)/2+1)*B - ((rest-1)/2)*A+1
    
print(int(answer))

Submission status: Wrong Answer

Solution code:
K, A, B = map(int, input().split())
tmp = K + 1
diff = B - A
if diff <= 0:
    print(K + 1)
else:
    ans = B
    K = max(0, K - (A + 1))
    ans += (K // 2) * diff
    ans += K % 2
    print(max(tmp, ans))

Submission status: Wrong Answer

Solution code:

K, A, B = map(int, input().split())
if A >= B - 2:
    print(K + 1)
else:
    a = (K + 1) // (A + 2)
    b = (K + 1) % (A + 2)
    print(a * B + b)

Submission status: Wrong Answer

Solution code:
a,b,c = map(int,input().split())
k = 0
if b >= c+1:
	print(a+1)
else:
	if b-1 >= a:
		print(a+1)
	else:
		k = a - b - 1
		if k % 2 == 0:
			su = k//2 * (c-b) + c
		else:
			su = k//2 * (c-b) + c + 1
		print(su)

Submission status: Wrong Answer

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

if a-1 >= k or a >= b-2:
    print(k+1)
    exit()

ans = a
k -= a-1
print(ans, k)
ans += (b-a)*(k//2)
ans += k%2
print(ans)

Submission status: Wrong Answer

Solution code:
def func():
    pass


def main():
    k, a, b = map(int, input().split())

    x = a + 2
    y = k // x
    ans = max(b * y + (k - x * y) + 1, k + 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


diff = B - A
if diff <= 0:
    print(K + 1)
else:
    ans = B
    K = max(0, K - (A + 1))
    ans += (K // 2) * diff
    ans += K % 2
    print(max(K + 1, ans))

Submission status: Wrong Answer

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

if b - a <= 2:
    print(k + 1)
    exit(0)

if k <= a + 1:
    print(k + 1)
    exit(0)

n = 0
ans = 0
if (k - a + 1) % 2 == 0:
    n = (k - a + 1) // 2
else:
    n = (k - a + 1) // 2

ans = (k - n * 2) + 1

# print(n, b - a)
ans += (b - a) * n
print(ans)

Submission status: Wrong Answer

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
k,a,b=IL()
ans=1
if a>=b:
    ans=1+k
else:
    if b-a<=2:
        ans=1+k
    else:
        if a-1+2>k:
            ans=1+k
        else:
            k=k-(a+1)
            ans=b
            ans+=(k//(a+2))*b+k-(k//(a+2))*(a+2)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    k, a, b = get_int_list()
    if b - a < 2:
        print(1 + k)
        return
    print(a + ((k - (a - 1)) // 2) * (b - a) + ((k + 1) % 2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if A+1>=B or K<A+1:
    print(K+1)
else:
    ex = (K-A+1)//2
    res= (K-A+1)%2
    print(ex)
    print(res)
    print(A+ex*(B-A)+res)

Submission status: Wrong Answer

Solution code:
k,a,b=map(int, input().split())
t=1
if t<a:
    k-=(a-t)
    t=a
if b-a>2:
    t+=(k//2)*(b-a)
    k=k//2
t+=k
print(t)

Submission status: Wrong Answer

Solution code:
k,a,b = map(int,input().split())
if a+2 > b:
    print(k+1)
else:
    c = (k+1)//(a+2)
    print((k+1)%(a+2) + c*b)

Submission status: Wrong Answer

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

diff=c-b

if diff <=1:
    print(a+1)
else:
    if a -b < 1:
        print(c+1)
    else:
        if (a-b)%2==0:
            print(b+1+((a-b)*(diff))//2)
        
        else:
            print(b+((a-b+1)*(diff))//2)

Submission status: Wrong Answer

Solution code:
k, a, b = map(int, input().split())
if a >= b - 2:
    print(k + 1)
elif k <= a + 1:
    print(k + 1)
else:
    ab = (k - (a - 1)) // 2
    print(1 + (k - ab * 2) + (b - a) * ab)

Submission status: Wrong Answer

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

Biscuit=1;

if(Biscuit<A):
    K-=(A-Biscuit);
    Biscuit+=(A-Biscuit);
    if(K<0):
        Biscuit-=abs(K);
        K=0;

print("Now: "+str(Biscuit));

if(B-A>2):
    Biscuit+=(B-A)*(K//2);
    K=K%2;

if(K>0):
    Biscuit+=K;
    K=0;

print(str(Biscuit));

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


k,a,b = [int(i) for i in input().split()]

if b - 2 <= a:
    print(1+k)
else:
    d = b-a
    ans=a
    k-= a-1
    if k < a:
        print(1+k)
    else:
        if k%2==0:
            print(ans + d*k//2)
        else:
            print(ans + 1+d*(k//2))

Submission status: Wrong Answer

Solution code:
k,a,b=map(int,input().split())
if a+2>=b:print(k+1)
elif a>=k:print(k+1)
else:
    k-=a-1
    ans=a+(b-a)*k//2
    if k%2==1:print(ans+1)
    elif k%2==0:print(ans)

Submission status: Wrong Answer

Solution code:
k,a,b = map(int,input().split())
add = b - a
ans = 1
if k <= a - 1:
    ans = 1 + k
    print(ans)
else:
    ans = a
    k = k - (a-1)
    if b > a:
        ans += max(add*(k//2) + k%2,k)
        print(ans)

Submission status: Wrong Answer

Solution code:
K,A,B =[int(i)for i in input().split()]
if A+2 >= B or K <= A:
    print(K+1)
else:
    N = K -A+1
    N =N//2
    print(N,K+1,(B-A-2))
    print(K+1+(B-A-2)*N)

Submission status: Wrong Answer

Solution code:
k,a,b = map(int,input().split())
add = b - a
ans = 1
if k <= a - 1:
    ans = 1 + k
    print(ans)
else:
    ans = a
    k = k - (a-1)
    if b > a:
        ans += add*(k//2) + k%2
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
K,A,B = map(int,input().split())
bis = K+1
tempbis = 1
while K>0:
    if tempbis<A:
        tempbis+=1
    else:
        if K>=2:
            K-=1
            tempbis += B-A
        else:
            tempbis +=1
    K-=1

print(max(bis,tempbis))

Submission status: Time Limit Exceeded

Solution code:
k,a,b=map(int,input().split())
cnt=1
yen=0

if b<a+2:
    print(k+1)

else:
    for i in range(k):
        if yen>0 :
            cnt+=b
            yen-=1
        elif cnt<a or i==k-1 :
            cnt+=1
        elif cnt>=a and i<=k-2 :
            cnt-=a
            yen+=1

    print(cnt)

Submission status: Time Limit Exceeded

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

if B - A <= 2: #ビスケットを叩き続けるパターン
    ans = 1 + 1 * K
    print(ans)
else:
    cnt = 0
    money = 0
    bis = 1
    while cnt < K:
        if K - cnt >= 2:
            if bis >= A: #ビスケットをお金に交換
                bis -= A
                money += 1
            elif money == 1: #お金をビスケットに交換
                bis += B
                money -= 1
            else: #ビスケットを叩く
                bis += 1
        else:
            bis += 1
        cnt += 1
    print(bis)

Submission status: Time Limit Exceeded

Solution code:
arr = input().split()
K = int(arr[0])
A = int(arr[1])
B = int(arr[2])

x = 1
a = 0
n = 1 + K

while K > 0:
	if a > 0 and B > A:
		x += B
		a -= 1
		K -= 1
		continue

	if x >= A and B > A and K != 1:
		x -= A
		a += 1
		K -= 1
		continue

	x += 1
	K -= 1

print(max(x, n))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    K, A, B = map(int, input().split())
    cnt = 0
    if B - A >= 3:
        times = (K - (A - 1)) // 2
        if times >= 1:
            cnt += A
            for i in range(times):
                p,mod=divmod(cnt,A)
                temp = p * B
                cnt = temp + mod
            if (K - (A - 1)) // 2 == (K - (A - 1)) / 2:
                pass
            else:
                cnt += 1
        else:
            cnt = 1 + K
    else:
        cnt = 1 + K

    print(cnt)


resolve()

Submission status: Time Limit Exceeded

Solution code:
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    K, A, B = map(int, input().split())
    cnt = 0
    if B - A >= 3:
        times = (K - (A - 1)) // 2
        if times >= 1:
            cnt += A
            for i in range(times):
                temp= (cnt // A) * B
                temp2 =cnt % A
                cnt=temp+temp2
            if (K - (A - 1)) // 2 == (K - (A - 1)) / 2:
                pass
            else:
                cnt += 1
        else:
            cnt = 1 + K
    else:
        cnt = 1 + K

    print(cnt)


resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
k,a,b=map(int, input().split())
if a>=b or (a<b and b-a==1):
    bis=1
    for i in range(k):
        bis+=1
    print(bis)
    sys.exit()
if a<b and (k-a+1)%2==0:
    bis=(b-a)*((k-a+1)//2-1)+b
    print(bis)
    sys.exit()
if a<b and (k-a+1)%2!=0:
    bis=(b-a)*((k-a+1)//2-1)+b+1
    print(bis)

Submission status: Time Limit Exceeded

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

num = 1
while K > 0:
    if num < A:
        num += 1
        K -= 1
    elif num >= A and K >= 2 and A + 2 < B:
        num -= A
        num += B
        K -= 2
    else:
        num += 1
        K -= 1

print(num)

Submission status: Time Limit Exceeded

Solution code:
K, A, B = map(int, input().split())
bisk = 1
hasMoney = False
for i in range(K):
  if (B <= A+2 or i == K-1 or bisk < A) and not hasMoney:
    bisk+=1
  else:
    if hasMoney:
      hasMoney = False
      bisk+=B
    else:
      hasMoney = True
      bisk-=A

print(bisk)

Submission status: Time Limit Exceeded

Solution code:
def main():
    K,A,B = map(int,input().split())
    if A +2 >= B:
        print(K+1)
    else:
        
        dp = [1,2]+[0 for i in range(K-1)]
        for i in range(2,K+1):
            if dp[i-2] == -1:
                if dp[i-1] >= A:
                    dp[i] =-1
                else:
                    dp[i] = dp[i-1]+1
            else:
                if dp[i-2] >= A:
                    dp[i] = dp[i-2]-A+B
                elif dp[i-1] >= A:
                    dp[i] = -1
                else:
                    dp[i] = dp[i-1]+1

        if dp[-1] == -1:
            print(dp[-2]+1)
        else:
            print(dp[-1])
main()

Submission status: Time Limit Exceeded

Solution code:
k,a,b=map(int,input().split())
if a+1>=b:
    print(k+1)
    exit()
else:
    cnt=0
    biscuit=1
    yen=0
    while(cnt<=k-2):
        if yen>=1:
                yen-=1
                biscuit+=b

        elif (biscuit>=a):
            biscuit-=a
            yen+=1
        else:
            biscuit+=1
        cnt+=1
    if yen>=1:
        biscuit+=b
    else:
        biscuit+=1
print(biscuit)

Submission status: Time Limit Exceeded

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

K,A,B=MAP()

rate=B/A
cnt=A-1
bis=A
while cnt<=K-2:
    bis=(bis//A)*A*rate+bis%A
    cnt+=2
if cnt==K-1:
    bis+=1

print(max(int(bis), K+1))

Submission status: Time Limit Exceeded

Solution code:
k,a,b=map(int,input().split(" "))
x=1
count=0
if a>b or b-a<2:
  print(k+1)
  exit()
while(count<k):
  if x<a and k-count>=a-x:
    count+=a-x
    x=a
  if count+2>k:
    x+=1
    break
  else:
    x=x-a+b
    count+=2
print(x)

Submission status: Time Limit Exceeded

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

having_biscuits = 1
money = 0

if B - A <= 2:
    print(K + 1)
    sys.exit()



for x in range(K):

    if money > 0:
        # 1円をビスケットB枚に交換する
        having_biscuits += B
        money -= 1

    elif having_biscuits < A or ((K - x) < A):
        # 叩く
        having_biscuits += 1

    elif having_biscuits >= A and ((K - x ) >= 2):
        # ビスケットA枚を1円に交換する
        money += 1
        having_biscuits -= A

print(having_biscuits)

Submission status: Time Limit Exceeded

Solution code:
K,A,B = map(int,input().split())
DP = [1,2,2]
i = K - 1
while i:
	i -= 1
	if DP[0] >= A:
		DP[2] = max(DP[1]+1,DP[0]+B-A)
	else:
		DP[2] = DP[1] + 1
	DP[0] = DP[1]
	DP[1] = DP[2]
print(DP[2])

Submission status: Time Limit Exceeded

Solution code:
def circ():
    global K, B, A, b, y
    k = K
    while k > 0:
        if k >= 2:
            if b < A:
                b += 1
                k -= 1
            else:
                y += 1
                b = 0
                k -= 1

                b = B
                y = 0
                k -= 1
        else:
            b += 1
            k -= 1
    return b


if __name__ == '__main__':
    K, A, B = map(int, input().split())
    hit = 1 + K
    b, y = 1, 0
    ans = max(circ(), hit)
    print(ans)

Submission status: Time Limit Exceeded

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

ans = 1
yen = 0
if B-A <= 1:
    ans += K
else:
    for _ in range(K):
        if ans%B == A:
            ans -= A
            yen += 1
        elif yen >= 1:
            ans += B
            yen -= 1
        else:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k, a, b = map(int, input().split())
maisu = 1
if b - a <= 2:
    maisu += k
else:
    while True:
        if k >= 2 and maisu >= a:
            maisu += b-a
            k -= 2
        else:
            k-= 1
            maisu += 1
        if k == 0:
            break
print(maisu)

Submission status: Time Limit Exceeded

Solution code:
s = input().split()
K = int(s[0])
A = int(s[1])
B = int(s[2])

import time

bis = 1

if float(B/A) > 2:
  change = 1
else:
  change = 0

if change == 0:
  bis = bis + K
  time.sleep(10000)
else:
  i = A -1
  bis  = A
  k = K - i
  bis += (k//2)*(B-A)
  bis += k %2
print(bis)

Submission status: Time Limit Exceeded

Solution code:
K, A, B = map(int,input().split())
count = 1
money = 0
for i in range(0,K,1):
  if count == A and int(i)+1 != K: #ビスケットAを円に変える
    count = 0
    money += 1
  elif money == 1: #円をビスケットに変える
    count += B
    money -= 1
  elif count <= A or K-int(i) < A: #ポケットをたたく
    count += 1
    
if count >= K+1:
  print(count)
else:
  print(K+1)

Submission status: Time Limit Exceeded

Solution code:
k,a,b=map(int,input().split())
ans=1
m=0
for i in range(k):
    if i==k-1 and m==0:
        ans+=1
    elif m==1:
        m=0
        ans+=b
    elif ans<a:
        ans+=1
    elif ans>=a:
        ans-=a
        m=1
print(max(ans,k+1))

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8


import numpy as np
import glob
import os

if __name__ == "__main__":

    inputt = input()
    K,A,B  = inputt.split(" ")
    K = int(K)
    A = int(A)
    B = int(B)

    if( A > K ):
        print(1 + K)
    else:
        if(B - A > 2):
            K = K - ( A - 1);
            count = A;
            if(K % 2 == 0):
                for ki in range(int(K/2)):
                    count = count + (B - A)
            else:
                for ki in range(int((K-1)/2)):
                    count = count + (B - A)
                count = count + 1
       
            print(count)
        else:
            print(1 + K)

Submission status: Time Limit Exceeded

Solution code:
K, A, B = (int(i) for i in input().split())
num = 1
while True:
    if A + 2 - num >= B:
        print(K + num)
        break
    elif num >= A:
        if (K // 2) is not 0:
            print(num + (K // 2) * (B - A) + (K % 2))
            break
    else:
        if K >= 2 and K >= (A + 2 - num):
            K -= (A + 2 - num)
            num = B
        else:
            print(K + num)
            break

Submission status: Time Limit Exceeded

Solution code:
K,A,B = input().split()
K = int(K)
A = int(A)
B = int(B)
bi = 1

step = K
for num in range(K):
    if(step >= 1):
        if(B-A>1):
            if(step>2):
                if(bi>=A):
                    bi += B-A
                    step -= 1
                else:
                    bi+=1
            else:
                bi+=1
        else:
            bi+=1
        
        step-=1
    else:
        break

print(bi)

Submission status: Time Limit Exceeded

Solution code:
k, a, b=map(int, input().split())
index=0
coockie=1
index=0
flag=0
while index < k:
    if coockie < a:
        coockie+=1
        index+=1
    else:
        if index < k-2 and b-a > 1:
            coockie-=a
            coockie+=b
            index+=2
        else:
            coockie+=1
            index+=1
    if coockie > a:
        flag=1
        break
if flag==0:
    print(coockie)
else:
    if index < k-2 and b-a > 1:
        if (k-index)%2==0:
            print(coockie+((k-index)//2)*(b-a))
        else:
            print(coockie + ((k-index)//2)*(b-a) + (k-index)%2)
    else:
        print(coockie+(k-index))

Submission status: Time Limit Exceeded

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

if (k == 1):
    print(2)
    exit()

if (b <= (a + 1)):
    print(k + 1)
    exit()
else:
    bis = 1
    mon = 0
    for i in range(k):
        if(1 <= mon):
            mon -= 1
            bis += b
        elif(a <= bis and i != (k-1)):
            bis -= a
            mon += 1
        else:
            bis += 1
    print(bis)

Submission status: Time Limit Exceeded

Solution code:
K, A, B = (int(i) for i in raw_input().split(' '))

action = K
cookie = 1

if A + 3 > B:
    cookie += K
    print(cookie)
else:
    while(cookie < A):
        if(action <= 0):
            break
        action += -1
        cookie += 1
    if action > 0:
        trade_n = int(action/2)
        cookie += (B-A)*trade_n
        if action % 2 == 1:
            cookie += 1
    print(cookie)

Submission status: Time Limit Exceeded

Solution code:
a = input().rstrip().split(" ")
K = int(a[0])
A = int(a[1])
B = int(a[2])

bis = 1
coin = 0

if B - A > 1:
    for i in range(K):
        if coin > 0:
            bis += B
            coin -= 1
        elif bis >= A and K - i > 1:
            bis -= A
            coin += 1
        else:
            bis += 1
else:
    for i in range(K):
        bis += 1

print(bis)

Submission status: Time Limit Exceeded

Solution code:
def function(K, A, B):
	bis = 1
	get_bis = 0
	coin = 0
	if B - A > 1:
		for i in range(1, K+1):
			if coin == 1:
				coin -= 1
				get_bis += B
			elif bis < A:
				bis += 1
			elif bis == A:
				bis -= A
				coin += 1
	else:
		for i in range(1, K+1):
			bis += 1
	print(bis+get_bis)
	
def main():
	nums = input().split(' ')
	function(int(nums[0]), int(nums[1]), int(nums[2]))

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
k, a, b = map(int, input().split())
biscuit = 1
money = 0
cnt = 0
if a >= b - 1:
    biscuit += k
else:
    biscuit = 0
    while cnt <= k:
        if k - cnt >= 2:
            if biscuit >= a:
                biscuit -= a
                biscuit += b
                cnt += 2
            else:
                biscuit += 1
                cnt += 1
        else:
            biscuit += 1
            cnt += 1
print(biscuit)

Submission status: Time Limit Exceeded

Solution code:
s = input().split()
K = int(s[0])
A = int(s[1])
B = int(s[2])

bis = 1
money = 0

if float(B/A) > 2:
  change = 1
else:
  change = 0

for i in range(K):
  if change == 1:
    if bis >= A and i+1 < K:
      bis = bis - A
      money += 1
      continue
    if money >= 1:
      bis += B
      money -= 1
      continue
 
  bis = bis+1
 
print(bis)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import defaultdict

K, A, B=map(int, input().split())  #
# a2,b2=map(int, input().split())  #
# a3,b3=map(int, input().split())  #


if A >= B-1:
    print(K+1)
else:
    cookie_num = 1
    money = 0
    for i in range(K):
        if i <= A-1:
            cookie_num += 1
        elif money == 0:
            money += 1
            cookie_num -= A
        elif money > 0:
            money -= 1
            cookie_num += B
            pass
        pass
    print(cookie_num)

    
# map_dict  = defaultdict(list)
# map_dict[a1].append(b1)
# map_dict[b1].append(a1)
# map_dict[a2].append(b2)
# map_dict[b2].append(a2)
# map_dict[a3].append(b3)
# map_dict[b3].append(a3)

# #print(map_dict)
# res = 0
# cnt = 0
# for m in map_dict:
#     if len(map_dict[m]) >= 3:
#         res = -1
#         break
#     if len(map_dict[m]) >= 2:
#         cnt += 1
#         pass
#     #print(map_dict[m])
# if cnt >= 3:  res = -1

# if res == -1:
#     print("NO")
# else:
#     print("YES")

Submission status: Time Limit Exceeded

Solution code:
k, a, b = map(int, input().split())
bis = 1
money = 0
for i in range(k):
    if i != k-1:
        if (b-a) != 1 :
            if money > 0:
                bis += b
                money -= 1
            elif bis < a:
                bis += 1
            elif bis >= a:
                bis -= a
                money += 1
        else:
            bis += 1
    else :
        bis += 1
print(bis)

Submission status: Time Limit Exceeded

Solution code:

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

dp = [[-1 for _ in range(2)] for _ in range(K + 1)]

dp[0][0] = 1

for k in range(K):
    if dp[k][1] >= 0:
        dp[k + 1][0] = max(dp[k][0] + 1, dp[k][1] + B)
    else:
        dp[k + 1][0] = dp[k][0] + 1
    if dp[k][0] >= A:
        dp[k + 1][1] = max(dp[k][0] - A, dp[k][1] + 1)
    else:
        if dp[k][1] >= 0:
            dp[k + 1][1] = dp[k][1] + 1

# for p in dp:
#     print(p)

print(max(dp[K][0], dp[K][1]))

Submission status: Time Limit Exceeded

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

sunuke_has = [1,0]

for i in range(K):
    if A < B-1:
        if sunuke_has[1] == 0:
            if sunuke_has[0] < A:
                sunuke_has[0] += 1
            else:
                if i != K-1:
                    sunuke_has[0] -= A
                    sunuke_has[1] += 1
                else:
                    sunuke_has[0] += 1
        else:
            sunuke_has[1] = 0
            sunuke_has[0] += B
    else:
        sunuke_has[0] += 1
    #print(str(i) + '回目')
    #print(sunuke_has)
        
print(sunuke_has[0])

Submission status: Time Limit Exceeded

Solution code:
a=input()
b=a.split()
k=int(b[0])
A=int(b[1])
B=int(b[2])
count=1
coin=0
for i in range(k):
    if B-A <=1:
        count+=k
        break
    elif coin>=1:
        count+=B
        coin-=1
    elif count<=A or i==k-1:
        count+=1
    else:
        count-=A
        coin+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
k,a,b=map(int,input().split())
bis=1
i=0
ans=0
if a>b-2:
    print(bis+k)
else:
    while i<k:
        if bis==1:
            for v in range(a-1):
                ans+=1
                i+=1
                if i==k:
                    break
        else:
            for v in range(a):
                ans+=1
                i+=1
                if i==k:
                    break
        if i==k:
            break
        if i<=k-2:
            ans-=a
            ans+=b
            i+=1
        else:
            ans+=1
            i+=1
        if i==k:
            break
    print(ans)