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: Wrong Answer)

function times(num1,num2){
  var num1str=(num1+"").split("").reverse();
  var num2str=(num2+"").split("").reverse();
  var L1=num1str.length;
  var L2=num2str.length;
  var newNumStr=[]
  for(var i=0;i<L1;i++){
    for(var j=0;j<L2;j++){
      if(newNumStr[i+j]===undefined)newNumStr[i+j]=0;
      newNumStr[i+j] += parseInt(num1str[i])*parseInt(num2str[j]);
    }
  }
  for(var k=0;k<2*(L1+L2);k++){
    if(newNumStr[k]===undefined)newNumStr[k]=0;
  }
  for(var k=0;k<2*(L1+L2);k++){
    if(newNumStr[k]===undefined)newNumStr[k]=0;
  }
  var l=0;
  while(newNumStr[l]||newNumStr[l]===0){
    newNumStr[l+1] += (newNumStr[l]-(newNumStr[l]%10))/10;
    newNumStr[l] = (newNumStr[l]%10).toString(10);
    l++;
  }
  newNumStr=newNumStr.reverse();
  newNumStr.splice(0,1);
  while(newNumStr[0]==="0"){
    newNumStr.splice(0,1);
  }
  newNumStr=newNumStr.join("");
  return(newNumStr);
}

function adds(num1,num2){
  var num1str=(num1+"").split("").reverse();
  var num2str=(num2+"").split("").reverse();
  var L1=num1str.length;
  var L2=num2str.length;
  var newNumStr=[];
  for(var i=0;i<Math.max(L1,L2);i++){
    if(num1str[i]===undefined)num1str[i]=0;
    if(num2str[i]===undefined)num2str[i]=0;
  }
  for(var i=0;i<Math.max(L1,L2);i++){
    newNumStr[i]=parseInt(num1str[i])+parseInt(num2str[i]);
  }
  var l=0;
  while(newNumStr[l]||newNumStr[l]===0){
    newNumStr[l+1] += (newNumStr[l]-(newNumStr[l]%10))/10;
    newNumStr[l] = (newNumStr[l]%10+"");
    l++;
  }
  newNumStr=newNumStr.reverse();
  newNumStr.splice(0,1);
  while(newNumStr[0]==="0"){
    newNumStr.splice(0,1);
  }
  newNumStr=newNumStr.join("");
  return(newNumStr);
}

function subtracts(num1,num2){
  var num1str=(num1+"").split("").reverse();
  var num2str=(num2+"").split("").reverse();
  var L1=num1str.length;
  var L2=num2str.length;
  var newNumStr=[];
  for(var i=0;i<Math.max(L1,L2);i++){
    if(num1str[i]===undefined)num1str[i]=0;
    if(num2str[i]===undefined)num2str[i]=0;
  }
  for(var i=0;i<Math.max(L1,L2);i++){
    newNumStr[i]=parseInt(num1str[i])-parseInt(num2str[i]);
  }
  var l=0;
  while(newNumStr[l]||newNumStr[l]===0){
    if(newNumStr[l]<0){
      newNumStr[l+1]--;
      newNumStr[l]+=10;
    }
    l++;
  }
  newNumStr=newNumStr.reverse();
  newNumStr.splice(0,1);
  while(newNumStr[0]==="0"){
    newNumStr.splice(0,1);
  }
  newNumStr=newNumStr.join("");
  return(newNumStr);
}

function Main(input) {
    input = input.replace("\n","");
	input = input.split(' ');
        var K=parseInt(input[0]);
        var A=parseInt(input[1]);
        var B=parseInt(input[2]);
        var D=B-A;
        var E=K-A;
        var biscuit=0;
/*        var biscuit=((E<2)||(D<3))?(K+1):(E%2===0)?(A+E*D/2+1):(A+(E+1)*D/2);
console.log(biscuit);
*/
  if((E<2)||(D<3)){
    biscuit=adds(K,1);
  }else if(E%2===0){
    biscuit=adds(adds(times(E/2,D),A),1);
  }else{
    biscuit=adds(times((E+1)/2,D),A);
  }
  console.log(biscuit);
}

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