#include <bits/stdc++.h>
using namespace std;
int getint() {
  int r = 0, k = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') k = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c;
  return r * k;
}
long long n, k, x, ans;
int main() {
  n = getint();
  k = getint();
  if (n == 1) {
    printf("0");
    return 0;
  }
  if (k >= (n / 2)) {
    x = n;
    x = x * (x - 1);
    x = x / 2;
    printf("%I64d", x);
    return 0;
  }
  ans = k * (n * 2 - k * 2 - 1);
  printf("%I64d", ans);
  return 0;
}
