#include <bits/stdc++.h>
using namespace std;
const int N = 212345, LG = 21, mod = 1000000007;
const double eps = 1e-3, pi = acos(-1.0);
char s[5], t[5], a[3];
int main() {
  long long n, k;
  scanf("%lld", &n), scanf("%lld", &k);
  if (n / 2 > k) {
    printf("%lld\n", k * (2 * k - 1) + (n - 2 * k) * 2 * k);
  } else {
    printf("%lld\n", (n * (n - 1)) / 2);
  }
  return 0;
}
