#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int maxn = 100100;
const int mod = 1000000007;
int n, k, x;
int a[maxn];
long long res;
void solve() {
  scanf("%d %d", &n, &k);
  x = min(k, n / 2);
  res = 1ll * (n - 1) * x;
  res += 1ll * x * (n - 2 * x);
  printf("%I64d", res);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
