#include <bits/stdc++.h>
using namespace std;
int n, k, a;
long long ans;
int main() {
  scanf("%d %d", &n, &k);
  a = n - 1;
  k = min(k, n / 2);
  for (int i = 1; i <= k; i++) {
    ans += a;
    ans += a - 1;
    a -= 2;
  }
  printf("%lld\n", ans);
  return 0;
}
