#include <bits/stdc++.h>
using namespace std;
long long get(long long x) { return (x * (x - 1)) / 2; }
signed main() {
  long long n, d, ans;
  cin >> n >> d;
  if (d == 1)
    ans = get(n);
  else if (d == 2)
    ans = get(n) - 1;
  else if (d == 3)
    ans = get(n - 2) + 2;
  else
    ans = get(n - (d + 1) + 2) + (d - 1);
  if (d >= 3 && (n - 1) != d) ans++;
  cout << ans << endl;
}
