#include <bits/stdc++.h>
int main(void) {
  int N, X, sum = 0;
  scanf("%d%d", &N, &X);
  if (N % 2 == 0 && N == 2 * X) sum = N + X;
  if (N > 2 * X) sum = (N - 2 * X) * 3 + N + 2 * X;
  if (N < 2 * X) sum = X + (N - X) * (N + 1);
  printf("\n%d\n", sum);
  return 0;
}
