#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using pstr = pair<string, string>;
using vint = vector<int>;
using vstr = vector<string>;
int main() {
  int n, x;
  cin >> n >> x;
  if (n == 2 * x) {
    cout << 3 * x;
  } else if (n % 3 == 0) {
    x = x < n / 2 ? x : n - x;
    cout << abs((x * 3) * (n - x * x));
  } else {
    cout << 2 * n + (n - 3);
  }
  return 0;
}
