#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  if (k > n / 2) k = n / 2;
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  int fr = n - 2;
  long long int ans = 0;
  while (k > 0) {
    ans += 2 * fr + 1;
    k--;
    fr -= 2;
  }
  std::cout << ans << std::endl;
}
