Problem:
Score : 200 points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:

Operation A: The displayed value is doubled.

Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total.
Find the minimum possible value displayed in the board after N operations.

Constraints

1 \leq N, K \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.

Sample Input 1

4
3

Sample Output 1

10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.

Sample Input 2

10
10

Sample Output 2

76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.

By the way, this contest is AtCoder Beginner Contest 076.

Solution in Ruby (2.3.3) (judge verdict: Runtime Error)

def a(num)
  num*2
end
def b(num)
  num+@k
end

n = gets.to_i
@k = gets.to_i
answers = []

if n==1
  aa, bb = a(1), b(1)
  answer = aa<=bb ? aa : bb
  puts answer
  exit(0)
end

if k==1
  answer = 1
  n.times do
    answer = b(answer)
  end
  puts answer
  exit(0)
end

n.times do |i|
  answer = 1
  n.times do |ii|
    if ii < i
      answer = a(answer)
    else
      answer = b(answer)
    end
  end
  answers << answer
end
puts answers.min