#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n, k, ans = 0;
  cin >> n >> k;
  if (k >= n / 2)
    ans = (n * (n - 1)) / 2;
  else {
    ans = (n * (n - 1)) / 2 - (((n - k) * (n - k - 1)) / 2) + k * (n - 2 * k) +
          (k * (k - 1)) / 2;
  }
  cout << ans << endl;
}
