#include <bits/stdc++.h>
using namespace std;
long long n, d;
int main() {
  cin >> n >> d;
  cout << d * (d != 1) + (n - d - 1) * (n - d - 2) / 2 +
              (d != 1) * (n - d - 1) * min(3LL, d + 1)
       << endl;
  return 0;
}
