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: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
k, a, b = map(int, input().split())
x = min(k, a)
k = max(0, k - a + 1)
x += max(b - a, 2) * (k // 2) + k % 2 
print(x)

Submission status: Accepted

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


        ans = max(ans, kk+1)

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
K, A, B = map(int, input().split(' '))

n1 = 1 + K

m = (K - A + 1) // 2
if m <= 0:
    print(n1)
    exit()

n2 = A + (B - A) * m
n2 +=  (K - A + 1) - (2 * m)

print(max(n1, n2))

Submission status: Accepted

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

c = b-a

if c >1:
    if k < a-1:
        print(1+k)
        exit(0)
    else:
        d=(k-a+1)
        if d %2==0:
            print(c*(d//2)+a)
        else:
            print(c*(d//2)+a+1)
        exit(0)
else:
    print(1+k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(K:int,A:int,B:int) -> int:
   if((B - A) <=2):
      return K + 1
   else:
      return max(0,(K - (A - 1)) // 2)*(B - A) + A + (K - (A - 1)) % 2


def modelAnswer():
   return
def main():
   K,A,B = map(int,input().split())
   print(myAnswer(K,A,B))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
k, a, b = map(int, input().split())
if k <= a:
    print(k+1)
else:
    # 交換しないほうがお得
    if a+2 >= b:
        print(k+1)
    # 交換したほうがお得
    else:
        print(a+(b-a)*((k-(a-1))//2)+((k-(a-1))%2))

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
K,A,B = map(int,input().split())

ans1 = 1 + K
zanturn = K - (A - 1)
AtoB,mod = divmod(zanturn,2)
ans2 = A + (B-A)*AtoB + mod

ans = max(ans1,ans2)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
K,A,B=map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

exchange_times, last = divmod(K-(A-1), 2)
profit = B - A
ans = A + exchange_times * profit + last
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

# C - When I hit my pocket...
def get_max_biscuits():
	
	if K < A + 1:
		return K + 1
	else:
		count = K - (A+1)
		
		return B + (B-A)*(count//2) + count%2


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

if B - A >= 2:
	print(get_max_biscuits())
else:
	print(K + 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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
            cnt+=(B-A)*times
            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: Accepted

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

  # 交換しても得しない、地道に増やす
  if b - a <= 2: return 1 + k

  # 交換できる数まで増えずに終了 (終了2回前にa個に到達していること)
  if 1 + (k - 2) < a: return 1 + k

  # 交換できる数まで増えたら、交換し続ける
  # 最初1個あるので a-1 回で最初の交換可能へ到達
  # k-(a-1)//2 回は交換できて、毎回 b-a が増える
  exchange_times, last = divmod(k-(a-1), 2)
  profit = b - a
  ans = a + exchange_times * profit + last
  return ans

ans = solve()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k,a,b=map(int,input().split())
    if b-a<=2 or k<=a:
        print(k+1)
    else:
        print(a+(b-a)*((k-a+1)//2)+(k-a+1)%2)

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
k,a,b=map(int, input().split())
if a>=b or (a<b and b-a==1):
    bis=1+k
    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: Accepted

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

cnt=K-A+1
count=cnt//2
cnt=A-1
cnt+=count*2
balance=K-cnt
ans=0
ans+=A
ans+=(B-A)*count
ans+=balance
#print(ans)
ans=max(ans,K+1)
print(ans)

Submission status: Accepted

Solution code:
k, a, b = map(int, input().split())
biscuits = 1
if a + 2 >= b:
    #全てビスケットでいい
    print(1 + k)
else:
    #お金に交換する方がいい
    ans = 0
    change = 0
    if k >= a+1:
        ans += b
        k -= a + 1
    else:
        print(1+k)
        exit()
    change = max(0, k//2)
    ans += change * (b - a) + (k % 2)
    print(ans)

Submission status: Accepted

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

k+=1
"""
ans=0
k-=a#最初の連星
k-=1#クッキーを１円に変える
k-=1#１円でクッキーを買う
ans+=b
k-=1
ans-=a
k-=1
ans+=b
k-=b-a
k-=1
k-=1
ans+=b

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

  
else:
    k=k//(b-a-2)

print(k)
"""

if a+1<b and a+2<=k:
    k-=a
    k-=2
    #print(48518828981938099-(b-a)*(k//2))
    print(  (b-a)*(k//2)+b+k%2)

else:
    print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
if A >= B:
    #ひたすらたたく
    ans = 1 + K
else:
    #1円で増えるビスケットの枚数が2枚以下なら、たたいたほうがいい
    if B - A <= 2:
        ans = 1 + K
    else:
        #まずA枚にする
        k = K - (A - 1)
        if k < 2:
            ans = 1 + K
        else:
            #A枚を1円にかえて、1円をB枚に変える
            k -= 2 
            ans = B
            #残った手順でひたすらA枚を1円に、1円をB枚にする
            ans += (k // 2) * (B - A)
            ans += k % 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if 1 > (b-a)*(1/2):
    print(k+1)
    exit()

else:
    n = max(0,(k-(a-1))//2)
    print(n*(b-a)+(k-n*2)+1)

Submission status: Accepted

Solution code:
k,a,b = [int(x) for x in input().split()]

l = k - (a - 1)

tmp = a + (b-a) * (l//2) + (l%2)
print(max(k+1, tmp))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
k,a,b = [int(x) for x in input().split()]

l = k - (a - 1)

tmp = a + (b-a) * (l//2) + (l%2)
print(max(k+1, tmp))

Submission status: Accepted

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

print(max(K+1, A + (B-A)*((K - (A-1))//2) + (K-A+1) % 2))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
k, a, b = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

bis = 1
m = 0
if b - a < 2:
    print(bis + k)
else:
    change = (k - (a - 1)) // 2
    bis += k - change * 2
    bis += change * (b - a)
    print(bis)

Submission status: Accepted

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

l = k - (a - 1)
ab = a + (b - a) * (l // 2) + (l % 2) 

print(max(1+k, ab))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,a,b=map(int,input().split())
ans=1
if b-a<=2: #交換するメリットがない k回すべて一枚増やす
    print(ans+k)
else:
    if k<(a+1):
        print(ans+k)
    else:
        zan=(k-(a-1))
        if zan%2==0:
            print(a+(zan//2)*(b-a))
        else:
            print(a+(zan//2)*(b-a)+1)

Submission status: Accepted

Solution code:
k,a,b=map(int,input().split())
ans=1
if b-a<=2: #交換するメリットがない k回すべて一枚増やす
    print(ans+k)
else:
    if k<(a+1):
        print(ans+k)
    else:
        zan=(k-(a-1))
        if zan%2==0:
            print(max(ans+k,a+(zan//2)*(b-a)))
        else:
            print(max(ans+k,a+(zan//2)*(b-a)+1))

Submission status: Accepted

Solution code:
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    K, A, B = map(int, input().split())
    if (B - A) <= 2:
        answer = 1 + K
    else:
        cookie = A
        cnt = A - 1
        money = (K - cnt) // 2
        hit = (K - cnt) % 2
        cookie += money * (B - A)
        cookie += hit
        answer = cookie
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, A, B = MAP()

if A+1 >= B or A >= K:
	print(1+K)
else:
	ans = A
	K -= A-1
	n, left = divmod(K, 2)
	ans += n*(B-A)+left
	print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K,A,B = map(int,input().split())
ans = 0
if B-A <= 2:
    # 1円に交換せず割り続けたほうが良い
    ans = 1+K
else:
    # x 回 ビスケット→円→ビスケットが行われると
    # ビスケットの儲けは(B-A)*2,消費する手数はx*2
    # k-x*2 分は交換せず叩いて増やす
    x = max(0,(K-(A-1))//2)
    ans = 1 + (B-A)*x + (K-(x*2))
print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
k, a, b = map(int, input().split())

# ずっと叩いたほうがいい場合
# bの方がaより小さかったら交換する意味がない
# aがb-1の場合、2回で1枚増えるより叩いて2回で2枚増えた方がお得
# a - 1回叩いてaになった時点で2回残ってないと交換できない
# 2回ないと交換できない
if a >= b or a == b - 1 or k < (a - 1) + 2 or k == 1:
    print(1 + k)
    exit(0)
# 叩いてa枚にする
k -= (a - 1)
ans = a
# ひたすら交換する
ans += (b - a) * (k // 2)
ans += k % 2
print(ans)

Submission status: Accepted

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline

k, a, b = map(int, input().split())
if b > a and k + 1 > a:
    ans = max(k + 1, (b - a) * math.floor((k + 1 - a) / 2) + (k + 1 - a) % 2 + a)
else:
    ans = k + 1
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

def main():
    K,A,B = map(int,input().split())
    if A+2 >= B:
        print(K+1)
    else:
        if K<=A:
            print(K+1)
        else:
            rest = K-(A-1)
            print(A+(B-A)*(rest//2)+rest%2)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

K,A,B = imn()

tmp = A-1
cnt = (K-tmp)
ans = (cnt//2)*B
ans -= (cnt//2-1)*(A)
ans += cnt%2

print(max(K+1, ans))

Submission status: Accepted

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  k, a, b = input_list()
  ans = 1
  lf = max(0, k - a+1)
  lf1 = lf//2
  if lf:
    ans = a + lf1 * (b - a) + lf%2
  else:
    ans +k
  print(max(ans, k+1))
  
  
import math
import fractions
import collections
from functools import reduce
main()

Submission status: Accepted

Solution code:
#temprate
from sys import setrecursionlimit
setrecursionlimit(10**6)
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#temprate
K,A,B = inputlist()
if A >= B:
    print(K + 1)
    exit()

tmp = K - (A - 1)
if tmp < 0:
    print(K + 1)
    exit()
cnt = tmp // 2
amari = tmp % 2

ans = cnt * B - (cnt - 1) * A + amari
ans = max(ans, K + 1)
print(ans)

Submission status: Accepted

Solution code:
K, A, B = map(int, input().split())
if A >= B:
    print(K + 1)
    exit()

# A - 1 回叩いて A 枚にする
# 残り K - (A - 1) 回については，A 枚を1 円にして，B 枚のクッキーに増やすを繰り返す．
tmp = K - (A - 1)
if tmp < 0:
    print(K + 1)
    exit()
cnt = tmp // 2
amari = tmp % 2

ans = cnt * B - (cnt - 1) * A + amari
ans = max(ans, K + 1)
print(ans)

Submission status: Accepted

Solution code:
import math

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

# 最初は1枚
ans = 1

# 1枚からはじめって1円に考案できるかどうか
if K >= A - 1:
    K -= (A - 1)  # A枚になるように叩く
    ans += (A - 1) # A枚持っている
else:
    ans += K # 1円にならないので全部叩く
    K = 0 # 残りは0

# 交換する価値がある (増える)
if A2B > 2:
    times = K // 2  # 残り回数のうち，A->円，円->Bの回数だけ交換できる
    ans += A2B * times  # 交換で増える分
    ans += K % 2  # 残りの枚数
else: # 増えない場合，残っている回数は叩いて増やせばいい
    ans += K

print(ans)

Submission status: Accepted

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

# 最終的にビスケットに交換するのが必要
if (B-A < 2) :
    # ビスケットたたいてるほうがアド
    print(K+1)
elif (K < A - 1) :
    # たたいてる間に終わってしまう(換金操作は2行動必要)
    print(K+1)
else :
    # 最初はA枚になるまでビスケットをたたく
    K -= (A-1)
    biscuits = A

    action = K // 2
    # A枚払ってB枚獲得
    biscuits += (B-A) * action
    
    if (K % 2 == 1) :
        biscuits += 1
    
    print(biscuits)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    k, a, b = map(int, input().split())
    cookie = 1
    if b <= a + 1 or 1 + k <= a:
        cookie += k
    else:
        cookie += a - 1
        k -= a - 1
        if k % 2:
            k -= 1
            cookie += 1
        cookie += (b - a) * max(0, k // 2)
    print(cookie)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
step,pay,gain=map(int,input().split())
b=step-pay+1
print(max(step+1,pay+b//2*(gain-pay)+b%2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

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

    viscuit = 1

    #aをbにするとき増える枚数
    a2b = b - a

    #最初は1枚持っている

    if k >= (a-1):
        k -= (a-1)
        viscuit += (a-1)
    else:
        viscuit += k
        k = 0

    if a2b > 2:
        times = k // 2
        rem = k % 2
        viscuit += a2b * times
        viscuit += rem
    else:
        viscuit += k
        k = 0

    print(viscuit)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    k, a, b = map(int, input().split())
    x = k+1
    y = 0
    if b > a:
        c = b-a
        k -= a-1
        y = c*(k//2-1) + b + (k%2)
    print(max(x, y))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,a,b = map(int, input().split( ))
if a>=b-2 or k<=a:##
    print(k+1)
    exit()

cnt = a 
k -= a-1


ch = k//2 

cnt += (b-a)*ch 
cnt += k%2
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

if B-A>1:
    if K<=A:
        print(K+1)
    else:
        print((B-A)*max(0,math.floor((K-(A-1))/2))+A+1-((K+A)%2))
else:   #B-A<=0
    print(1+K)

Submission status: Accepted

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