#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
  while (cin >> n >> x) {
    unsigned long long ans = 0;
    if (x == n / 2) {
      ans += 3 * x;
    } else if (x < n / 2) {
      ans += x + (n - x) * (2 * x);
    } else {
      continue;
    }
    cout << ans << endl;
  }
  return 0;
}
