n,x = gets.split(" ").map(&:to_f)
result = 0

if n / 2 === x
  result = 3*x
elsif n / 2 > x
  a = n - (x*2)
  result = (n-x) * 3 + a * (x+1)
elsif n / 2 < x
  result = x + (n-x)*(n+3)
end



puts result.to_i
