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