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