#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
const int Direction[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
const int Nmax = 200100;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  k = min(k, n / 2);
  long long sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += (n - i);
    sum += (i - 1);
  }
  int rest = (n - 2 * k);
  sum += rest * 1ll * k;
  cout << sum << endl;
  return 0;
}
