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

Solution in C (Clang 3.8.0) (judge verdict: Accepted)

#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}

int main(int argv, char *argc[]){
  unsigned char a;
  long long int N, M, K,A, B;
  long long int X[100000];
  long long int i, j;
  long long int location_coma[10000] = {0};
  long long int cnt = 0;
  scanf("%lld", &K);
  scanf("%lld", &A);
  scanf("%lld", &B);

  if (A >= B-1) {
    printf("%lld\n", K+1);
  }
  else {
    long long int cookie_num = 1;
      if (K < A) {
        printf("%lld\n", K+1);
      }
      else if (K >= A) {

        K = K - (A - 1);
        cookie_num = A;
        if (K%2 == 0) {
          cookie_num = A + (B-A)*(K/2);
        }
        else {
          cookie_num = A + (B-A)*(K/2) + 1;
        }
        printf("%lld\n", cookie_num);
      }
    

    
  }
  
  /* for (i = 1; i <= N; i += 2) { */
  /*   cnt++; */
  /*   /\* for (j = i; j <= N; j++) { *\/ */
  /*   /\*   if (abs(i-j) != 1 && i != j) { *\/ */
  /*   /\*     cnt++; *\/ */
  /*   /\*   } *\/ */
  /*   /\* } *\/ */

  /* } */
  /* if (cnt >= K) { */
  /*   puts("YES"); */
  /* }else { */
  /*   puts("NO"); */
  /* } */
  /* for (i = 0; i < M; i++) { */
  /*   scanf("%lld", &X[i]); */
  /* } */
 /*  qsort(X, M, sizeof(long long int), compare_int); */
 /*  long long int sum = 0; */
 /*  for (i = 0; i < M; i++) { */
 /*    printf("%lld, ", X[i]); */
 /*    //sum += L[i]; */
 /*  } */

 /*  location_coma[0] = X[0]; */
 /*  location_coma[N-1] = X[M-1]; */
 /*  printf("%lld, lld\n", location_coma[0], location_coma[N-1]); */
 /* for (i = 0; i < N; i++) { */
 /*    float pos = X[M-1] - X[0] / N; */
 /*      for (i = 0; i < M; i++) { */
        

 /*      } */
 /*  } */


  
  /* //qsort(L, N, sizeof(long long int), compare_int); */
  /* long long int sum = 0; */
  /* for (i = 0; i < N-1; i++) { */
  /*   //printf("%lld, ", L[i]); */
  /*   sum += L[i]; */
  /* } */
  /* if (sum > L[N-1]) { */
  /*   puts("Yes"); */
  /* } else { */
  /*   puts("No"); */
  /* } */
  return 0;
  /* scanf("%d", &X); */
  /* printf("%f\n", (float)T/X); */
  //a = 122;
  //printf("%lx\n",a);
  
}