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