#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  long long n, k;
  cin >> n >> k;
  if (k >= n / 2) {
    cout << n * (n - 1) / 2;
  } else {
    cout << k * (2 * n - k - 1) / 2 + (n - 2 * k) * k + (k) * (k - 1) / 2;
  }
}
