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: Runtime Error

Solution code:
a,b,c = map(int,input().split())
bis = 1
money = 0
d = [0]*a
if b >= c:
        bis = bis*a + 1
        print(bis)
else:
        for i in range(a):
                if money == 0 :
                        if bis < b:
                                bis += 1
                                d[i] = bis
                        else:
                                money += 1
                                bis -= b
                                d[i] = bis
                else:
                        bis += c
                        money -= 1
                        d[i] = bis
        if d[-1] > d[-2] :
                print(d[-1])
        else:
                print(d[-2]+1)

Submission status: Runtime Error

Solution code:
N = int(input())
b = input().split()
b = [int(i) for i in b ]
ans = 1
def check(n):
	global b
	global ans
	for i in range(1,n+1):
		if not b[0] == 1:
			ans = 0
		elif b[i-1] <= i:
			b[i-1-(b[i-1])],b[i-1] = b[i-1],b[i-1-(b[i-1])]
		else:
			ans = 0
		return b
b = check(N)
if ans == 0:
	print(-1)
else:
	for i in b:
		print(i)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys


K, A, B = sys.stdin.readline().split(" ")
k = long(K)
a = long(A)
b = long(B)

if (b-a) >= 2:
	hitsteps = a - 1
	leftoversteps = k - hitsteps
	rem = (leftoversteps)%2
	assert(rem==1 or rem == 0)
	swaps = (leftoversteps-rem)/2
	multbiscuits = swaps * (b-a)
	print(int(multbiscuits+rem+a))
else:
	print(int(k+1))

Submission status: Runtime Error

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

K = int(input_string[0])
A = int(input_string[1])
B = int(input_string[2])

if (A > B):
    print(K+1)
    
# y = -Ax + B(K-x)
# y = -Ax + BK - Bx
# y = -(A + B)x + BK

y = -(A + B)*x + B*K + 1
        
print(y)

Submission status: Runtime Error

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

#交換しても割に合わない
if a > b:
        biscuits = k+1

#交換するとお得

#交換できない(叩き続ける)
if a < b:
    if k - 1 < a:
        biscuits = k + 1

#交換可能(集まり次第交換)
    if k - 1 >= a:
        if (k - a - 1) % 2 == 0:
            p = k - a - 1
            biscuits = (p / 2 + 1) * b - p / 2 * a
        else:
            biscuits = (p / 2 + 1) * b + 1

        
print(biscuits)

Submission status: Runtime Error

Solution code:
 k, a, b = [int(i) for i in input().split()]
#k, a, b= 314159265, 35897932, 384626433

sum = 0
if a >= b:
    # A >= Bの場合
    # a,bに１施行ずつ使い、それ以外は叩く、という選択
    sum = k + 1
else:
    # A < B の場合
    diff = b - a
    if diff == 1:
        sum = k + 1
    elif diff == 2:
        sum = k + 1
    elif diff >= 3:
        # a->bコンボが利潤を生み続けるパターン
        rest = 1 + k - a
#         print("K:{}".format(rest))
        if rest >= 0:
            if rest % 2 == 0:
                sum = a + ((diff) * int(rest / 2))
#                 print("biscuits:{}".format(a))
#                 print("diff:{}, k/2:{}".format(diff, rest / 2))
            else:
                # 最後1回はコンボができないので、叩くパターン
                sum = a + ((diff) * int((rest - 1) / 2)) + 1
#                 print("biscuits:{}".format(a))
#                 print("diff:{}, k/2:{}".format(diff, (rest - 1) / 2))
        else:
            sum = k + 1
                
print(int(sum))

Submission status: Runtime Error

Solution code:
K,A,B=map(int,input().split())
K1=K-(A+1)
n=K1//2
print(max(K+1,((n+1)*B-n*A+K1%2)))
#
K,A,B=map(int,input().split())
print(A+((K-A+1)//2)*(B-A)+(K-A+1)%2) if(B-A>2 and K-A>0) else print(K+1)
#
k,a,b = map(int,input().split())
if a+2 > b:
    print(k+1)
else:
    print(a-1 + (b-a)*(k-a+1)//2 + (k-a+1)%2)

Submission status: Runtime Error

Solution code:
K,A,B = list(map(int,input().split()))
if A>=B-1:
    answer = K+1
'''if A > K-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:
        answer="else"
        #answer = ((rest-1)/2+1)*B - ((rest-1)/2)*A+1
    
print(int(answer))

Submission status: Runtime Error

Solution code:
from math import log
k, a, b = [int(i) for i in input().split()]

N = []

for n in range(1, (k+1)//a+1):
    x = n*a - 1
    y = int(log((b/a-1)*k+1, b/a))
    z = y
    m = 1 + x - a*y + b*z
    y = y+1
    z= z+1
    mm = 1 + x - a*y + b*z
    mmm = [m, mm]
    N.append(max(mmm))
N.append(k+1)
print(max(N))

Submission status: Runtime Error

Solution code:
a=input()
K=int(a.split()[0])
A=int(a.split()[1])
B=int(a.split()[2])
 
num=1
coin=0
for i in range(K):
  if(num==A):
    coin+=1
    num=0
  elif(coin>0):
    num=num+(coin*B)
    coin=0
  else:
    num+=1
num_a=1+K
if(num_a>num):
  print(num_a)
else:
  print(num)
a=input()
K=int(a.split()[0])
A=int(a.split()[1])
B=int(a.split()[2])

num=1
coin=0
for i in range(K):
  if(num==A):
    coin+=1
    num=0
  elif(coin>0):
    num=num+(coin*B)
    coin=0
  else:
    num+=1
num_a=1+K
if(num_a>num):
  print(num_a)
else:
  print(num)
提出情報

Submission status: Runtime Error

Solution code:
in_list = input().split()
K = int(in_list[0])
A = int(in_list[1])
B = int(in_list[2])
if(A>=B):
   print(K)
else:
   if(B/A<2):
      rest = 2
      bis = K-1
   else:
      rest = K-A+1
      bis = A
   coin = 0
   if(rest%2==1):
      bis = A+1
      rest-=1
   for i in range(rest):
      if(i%2==0):
         change = int(bis/A)
         bis -= A*change
         coin = 1*change
      else:
         bis += B*coin
         coin = 0
   print(bis)

Submission status: Runtime Error

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

bis = 1
while K > 0:
  if(bis+1 > B):
    bis += 1
    K -= 1
  else:
    if(bis%A == 0):
      bis = 0
    else:
      bis //= A
    bis += B*max(bis//A, 1)
    K -= 2
print(bis)

Submission status: Runtime Error

Solution code:
in_list = input().split()
K = int(in_list[0])
A = int(in_list[1])
B = int(in_list[2])
if(A>=B):
   print(K)
else:
   if(B/A<2):
      rest = 2
      bis = K-1
   else:
      rest = K-A+1
      bis = A
   coin = 0
   if(rest%2==1):
      bis = A+1
      rest-=1
   print(bis,rest)
   for i in range(rest):
      if(i%2==0):
         change = int(bis/A)
         bis -= A*change
         coin = 1*change
      else:
         bis += B*coin
         coin = 0
   print(bis)

Submission status: Runtime Error

Solution code:
in_list = input().split()
K = int(in_list[0])
A = int(in_list[1])
B = int(in_list[2])
if(A>=B):
   print(K)
else:
   if(B/A<2):
      rest = 2
      bis = K-1
   else:
      rest = K-A+1
      bis = A
   coin = 0
   if(rest%2==1):
      bis = A+1
      rest-=1
   print(bis,rest)
   for i in range(rest):
      %print(bis,coin)
      if(i%2==0):
         change = int(bis/A)
         bis -= A*change
         coin = 1*change
      else:
         bis += B*coin
         coin = 0
   print(bis)

Submission status: Runtime Error

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

X = 1
Y = 0

for i in range(K):
    if (B > A) and  (i <K-1:) and (X = A):
        X = 0
        Y += 1
    elif Y == 1:
        X += B
        Y  = 0
    else:
        X;=1

print(X)

Submission status: Runtime Error

Solution code:
# coding:utf-8

K, A, B = [int(i) for i in input().split()]

def cal(K, A, B):
    BNUM = 1
    TRANS_GET = B - A
    # 操作開始
    counter = 0
    while counter < K:
        nokori = K - counter
        if BNUM >= A:
        # 交換可能
            if nokori >= 2:
                syou = int(nokori / 2)
                amari = nokori % 2
                BNUM += TRANS_GET * syou + amari
                break
            else:
                BNUM += nokori
                break
        else:
        # 交換不可
            atonanko = A - BNUM
            if atonanko < nokori-2:
                BNUM += atonanko
                counter += atonanko
            else:
                BNUM += nikori
                break
    return BNUM


if A < B:
    if B - A > 2:
        max_b = cal(K, A, B)
    else:
        max_b = 1 + K
else:
    max_b = 1 + K

print(max_b)

Submission status: Runtime Error

Solution code:
k,a,b=map(int,input().split())
c=[]
for m in range(k//2):
 if 1+k-(2+a)*m<0:break
 c+=[1+k+(b-a-2)*m]
print(max(c))

Submission status: Runtime Error

Solution code:
K,A,B = (int(x) for x in input().split())
ans = 1

if B-A>2:
    if K>= A-1:
        ans += A - 1
        K -= A - 1
        if K >= 2:
            ans = ans + (B - A) * ((unsigned long long)(K / 2));
            K = K % 2;

ans += K

print(ans)

Submission status: Runtime Error

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

if a < b - 2:
    if k > (a + 2):
        k2 = k - (a + 2)
        res = b + (k2//2 + 1) * (b - a)
        if k2 % 2 == 0:
            res += 1
else:
    res = k + 1

print(res)

Submission status: Runtime Error

Solution code:
k, a, b=map(int, input().split())
index=0
coockie=1
index=0
flag=0
if b-a <= 2:
    print(k+1)
else:
    while index < k:
        if coockie < a:
            if index+(a-coockie) < k:
                plus = (a-coockie)
                coockie += plus
                index += plus
            else:
                coockie+=(k-index-1)
                index+=(k-index-1)
        else:
            if index < k-2:
                coockie-=a
                coockie+=b
                index+=2
                flag=1
            else:
                coockie+=1
                index+=1
        if coockie > a and flag:
            flag2=1
            break
    if flag2==0:
        print(coockie)
    else:
        if index < k-2:
            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: Runtime Error

Solution code:
# coding:utf-8

K, A, B = [int(i) for i in input().split()]
print(K, A, B)

def cal(K, A, B):
    BNUM = 1
    TRANS_GET = B - A
    # 操作開始
    counter = 0
    while counter < K:
        nokori = K - counter
        if BNUM >= A:
        # 交換可能
            if nokori >= 2:
                BNUM += TRANS_GET
                counter += 2
            else:
                BNUM += nokori
                break
        else:
        # 交換不可
            atonanko = A - BNUM
            if atonanko < nokori-2:
                BNUM += atonanko
                counter += atonanko
            else:
                BNUM += nikori
                break
    return BNUM


if A < B:
    if B - A > 2:
        max_b = cal(K, A, B)
    else:
        max_b = 1 + K
else:
    max_b = 1 + K

print(max_b)

Submission status: Runtime Error

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

if a < b - 2:
    if k > (a + 2):
        k2 = k - (a + 2)
        res = b + (b-a) + (k2//2) * (b - a) -1
        if k2 % 2 == 1:
            res += 1
else:
    res = k + 1

print(res)

Submission status: Runtime Error

Solution code:
k, a, b = map(int, input().split())
ans = 0
def sousa(t, bis): # 残りターン数、所持ビスケット数、所持金はゼロまで全部買った後
    req = max(a - bis, 0) + 2 # 売買に必要なターン数
    # print(t, bis, req)
    if t< req: # 残りターン不足
        print(bis + t)
        return 
    elif req >= b - a: # 売買の成果が叩く成果以下なら売買する意味なし
        print(bis + t)
        return bis + t
    else: # 売買する
        sousa(t - req, bis + ((req - 2) - a + b)) # 売買の結果
import sys
sys.setrecursionlimit(500000)
sousa(k, 1)

Submission status: Runtime Error

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

if K >= A  or B  > 1 + 2A :

    cookie = B
    K = K-A-1

    if K%2==0:
        cookie += (B-A)* math.floor(K/2)
        print(cookie)
    else:
        cookie += (B-A)*math.floor((K-1)/2)
        print(cookie + 1)
else:
    print(K + 1)

Submission status: Runtime Error

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

if b+2 > c:
  print(1+a)
else:
  a -= b
  if a <= 0:
    print(1+a)
  else:
    ans = c
    while a < 0:
    	a -= b+1
		if a <= 0:
    		print(ans+ a+b+1)
        	break
		ans += c

Submission status: Runtime Error

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

if B > 2A :

    cookie = B
    K = K-A-1

    if K%2==0:
        cookie += (B-A)* math.floor(K/2)
        print(cookie)
    else:
        cookie += (B-A)*math.floor((K-1)/2)
        print(cookie + 1)
else:
    print(K + 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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)


    base0 =1000
    if( A > K ):
        print(1 + K)
    else:
        if(B - A > 2):
            K = K - ( A - 1);
            count = A;
            if(K % 2 == 0):
                ki = 0
                while ki < int(K/2):
                    if int(K/2) - ki > base0:
                        count = count + (B-A) * base0
                        ki = ki + base0
                    elif int(K/2) - ki > 100:
                        count = count + (B-A) * 100
                        ki = ki + 100
                    else:
                        count = count + (B - A)
                        ki = ki + 1
            else:
                while ki < int((K-1)/2):
                    if int(K/2) - ki > base0:
                        count = count + (B-A) * base0
                        ki = ki + base0
                    elif int(K/2) - ki > 100:
                        count = count + (B-A) * 100
                        ki = ki + 100
                    else:
                        count = count + (B - A)
                        ki = ki + 1
                count = count + 1
       
            print(count)
        else:
            print(1 + K)

Submission status: Runtime Error

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):
                ki = 0
                while ki < int(K/2):
                    if int(K/2) - ki > 100:
                        count = count + (B-A) * 100
                        ki = ki + 100
                    else:
                        count = count + (B - A)
                        ki = ki + 1
            else:
                while ki < int((K-1)/2):
                    if int(K/2) - ki > 100:
                        count = count + (B-A) * 100
                        ki = ki + 100
                    else:
                        count = count + (B - A)
                        ki = ki + 1
                count = count + 1
       
            print(count)
        else:
            print(1 + K)

Submission status: Runtime Error

Solution code:
res = 0
if (b-a)<2:
    print(1+k)
else:
    while k>=1:
        if 1 + res >=a and k >= 2:
            res += b-a
            k -= 2
        else:
            res += 1
            k -= 1
print(res+1)

Submission status: Runtime Error

Solution code:
import math
K, A, B = map(int, input.split())
ans = K+1
if B > 2 + A:
  N = K - A
  if N == 1:
    ans = B
  elif N%2==1:
    ans=B+(B-A)*math.floor((K-A)/2)
  elif N%2==0:
    ans=B+(B-A)*math.floor((K-A)/2-1)+1

print(ans)

Submission status: Runtime Error

Solution code:
import math
_k,A,B = map(int, input().split())

def solve():
  if(_k<A+1):
    print(_k+1)
  else:
    print(max(_k+1, rec(B, _k-(A+1))))

def rec(sum, k):
  if(k<A+2):
    return B+k
  else:
    return sum + max(sum+k, rec(sum+B, k-(A+2)))
  
solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def f():
    # A枚に達する
    a = A - 1
    # 増殖に使える時間
    b = K - a
    # A->Bにd回変換
    d, m = divmod(b, 2)
    return A + (B - A) * d + m

def g():
    return 1 + K

if (A + 2) < B:
    print(f())
else:
    print(g())

Submission status: Runtime Error

Solution code:
"""

問題文

すぬけ君は最初、ビスケットを 1 枚持っており、日本円は持っていません。 すぬけ君は、以下の操作を好きな順に合計ちょうど K 回行います。

    持っているビスケットを叩き、1 枚増やす
    ビスケット A 枚を 1 円に交換する
    1 円をビスケット B 枚に交換する

K 回の操作の後、すぬけ君が持っているビスケットの枚数の最大値を求めてください。
制約

    1≤K,A,B≤109
    K,A,B は整数である
"""

def func(K , A , B) : 
    if B >= A + 3 :
        #売って買ってで(B - A)枚手に入る(ただし2回消費する)
        #まずは手持ちをAまいに持っていく必要がある。
        #売って買ってをn回繰り返す
        #最後に１回余ったら1叩く
        # K - (A - 1) = 2 * n + r
        # K - (A - 1)を計算し、偶数であれば n*(B - A) + A (n = (K - A + 1) / 2)
        # 奇数であれば n = (K - A) / 2として n*(B - A) + A + 1
        if (K - A + 1) % 2 == 0 : 
            n = int((K - A + 1) / 2)
            return n * (B - A) + A 
        else : 
            n = int((K - A) / 2)
            return n*(B - A) + A + 1
    else : 
        #叩き続けたほうがいい
        return K + 1

if not func(4 , 2 , 6) == 7 : 
    print("test 1 fail")

if not func(7 , 3, 4) == 8 : 
    print("test 2 fail")

if not func(314159265 , 35897932 , 384626433) == 48518828981938099 : 
    print(f"{int(func(314159265 , 35897932 , 384626433)) } != 48518828981938099")
    print("test 3 fail")

s = input().split(" ")
print( int(func( int(s[0]) , int(s[1]) , int(s[2]) )) )

Submission status: Runtime Error

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

#%%
#k, a, b = 4, 2, 6


#%%
def main(biscuit, k, a, b):
    if k < a + 1:
        return biscuit + k


    dif = b - a

    if dif > 2:
        if biscuit < a:
            new_biscuit = a
            new_k = k - a
            return main(new_biscuit, new_k, a, b)
        else:
            new_k = k - 2
            new_biscuit = biscuit + dif
            return main(new_biscuit, new_k, a, b)
    else:
        return biscuit + k


print(main(1, k, a, b))

#%%

Submission status: Runtime Error

Solution code:
4 2 6

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k, a, b;
  cin >> k >> a >> b;
  int res = k + 1;
  if (a < b && k > a) {
    int t = k - (a - 1);
    int m = t / 2;
    int c = a + m * (b - a) + (t % 2 == 1);
    res = max(res, c);
  }
  cout << res << "\n";
  return 0;
}

Submission status: Runtime Error

Solution code:
# encoding:utf-8

import copy
import numpy as np
import random

a = []
b = []

for i in range(3):
    a_now,b_now = map(int, input().split())
    a.append(a_now)
    b.append(b_now)

town_dic = {1:0,2:0,3:0,4:0}

for i in range(3):
    town_dic[a[i]] += 1
    town_dic[b[i]] += 1

answer = "YES"
for i in range(4):
    if town_dic[i+1] == 3:
        answer = "NO"


print(answer)

Submission status: Runtime Error

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

def calc(k, a, b, now):
  if k==1:
    return now + 1
  if k==0:
    return now
  if now<a:
    return calc(k-1, a, b, now + 1)
  if k>=2 and (b-a) >= 2:
    return calc(k-2, a, b, now - a + b)
  return calc(k-1, a, b, now + 1)

print(calc(K, A, B, 1))

Submission status: Runtime Error

Solution code:
k, a, b = map(int, raw_input().split())
if a >= b:
    print(res)
    exit()

res = k
k -= a-1
if k >= 0:res = max(res, a + (k / 2) * (b-a))
k -= 1
if k >= 0:res = max(res, a + 1 + (k / 2) * (b-a))
print res

Submission status: Runtime Error

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

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

S = 1

M = min(K, A-1)
K -= M
S += M

S += K / 2 * (B - A)
K %= 2
S += K

print S