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