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 JavaScript (node.js v5.12) (judge verdict: Accepted)

function Main(input) {
  input = input.split("\n");
  var K=parseInt(input[0].split(" ")[0]);
  var A=parseInt(input[0].split(" ")[1]);
  var B=parseInt(input[0].split(" ")[2]);

  var ans=K+1;

  if(B>2+A){
    var N = K-A;
    if(N==1){
      ans=B;
    }else if(N%2==1){
      var X = UInt64(Math.floor((K-A)/2));
      var Y = UInt64(B-A);
      var Z = UInt64(B);
      var XY = X.multiply(Y);
      var XYZ = XY.add(Z);
      ans = XYZ.toString();
    }else if(N%2==0){
      var X = UInt64(Math.floor((K-A)/2-1));
      var Y = UInt64(B-A);
      var Z = UInt64(B+1);
      var XY = X.multiply(Y);
      var XYZ = XY.add(Z);
      ans = XYZ.toString();
    }
  }



  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}

function UInt64(value) {
  var uint64 = Object.create(UInt64.prototype);
  uint64._wordArray = new Array(4);
 
  uint64.set(value);
 
  return uint64;
}
 
UInt64.compare = function(a, b) {
  for (var i = a._wordArray.length; i >= 0; i++) {
      if (a._wordArray[i] > b._wordArray[i]) {
          return 1;
      }
      else if (a._wordArray[i] < b._wordArray[i]) {
          return -1;
      }
      else {
      }
  }
  return 0;
};
 
UInt64.prototype.set = function(value) {
  var div = 0;
 
  if (UInt64.prototype.isPrototypeOf(value)) {
      for (var i = 0; i < this._wordArray.length; i++) {
          this._wordArray[i] = value._wordArray[i];
      }
  }
  else if (typeof value == 'number') {
      div = 1;
      for (var i = 0; i < this._wordArray.length; i++) {
          this._wordArray[i] = (Math.floor(value / div) & 0xFFFF);
          div *= 0x10000;
      }
  }
  else {
      for (var i = 0; i < this._wordArray.length; i++) {
          this._wordArray[i] = 0;
      }
  }
};
 
UInt64.prototype.add = function(value) {
  var prevCarry = 0;
  var carry = 0;
 
  for (var i = 0; i < this._wordArray.length; i++) {
      carry = (((this._wordArray[i] + value._wordArray[i] + prevCarry) & 0xFFFF0000) >>> 16);
      this._wordArray[i] = ((this._wordArray[i] + value._wordArray[i] + prevCarry) & 0xFFFF);
      prevCarry = carry;
  }
 
  return this;
};
 
UInt64.prototype.multiply = function(value) {
  var prevCarry = 0;
  var carry = 0;
  var prod = UInt64(0);
 
  for (var i = 0; i < this._wordArray.length; i++) {
      prevCarry = 0;
      for (var j = 0; j < value._wordArray.length; j++) {
          if (i + j >= prod._wordArray.length) {
              break;
          }
 
          carry = (((this._wordArray[i] * value._wordArray[j] + prevCarry + prod._wordArray[i + j]) & 0xFFFF0000) >>> 16);
          prod._wordArray[i + j] = ((this._wordArray[i] * value._wordArray[j] + prevCarry + prod._wordArray[i + j]) & 0xFFFF);
          prevCarry = carry;
      }
  }
 
  this.set(prod);
 
  return this;
};
 
UInt64.prototype.isZero = function() {
  var ret = true;
 
  for (var i = 0; i < this._wordArray.length; i++) {
      if (this._wordArray[i] > 0) {
          ret = false;
          break;
      }
  }
 
  return ret;
};
 
UInt64.prototype.toString = function() {
  var work = UInt64(this);
  var prevMod = 0;
  var mod = 0;
  var str = '';
 
  if (work.isZero()) {
      str = '0';
  }
  else {
      while (!work.isZero()) {
          mod = 0;
          prevMod = 0;
          for (var i = work._wordArray.length - 1; i >= 0; i--) {
              mod = (work._wordArray[i] + prevMod) % 10;
              work._wordArray[i] = Math.floor((work._wordArray[i] + prevMod) / 10);
              prevMod = mod << 16;
          }
 
          str = String.fromCharCode('0'.charCodeAt() + mod) + str;
      }
  }
 
  return str;
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));