#include <bits/stdc++.h>
using namespace std;
int main() {
  double N, X;
  cin >> N >> X;
  if (N == X / 2) cout << 3 * X;
  if (X > N / 2) cout << ((N - 1) * (N - X) * 2 + X);
  if (X < N / 2)
    cout << 3 * X + N - X + (N - 2 * X) * (X / (N - 2 * X)) * 2 - (N - 2 * X);
  return 0;
}
