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