#include <bits/stdc++.h>
using namespace std;
int n, k;
int v[100005];
long long ans, T[100005];
void upd(int x) {
  for (; x <= n; x += x & -x) T[x]++;
}
long long tap(int x) {
  long long ret = 0;
  for (; x > 0; x -= x & -x) ret += T[x];
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) v[i] = i;
  int l = 1, r = n;
  while (k > 0 && l < r) {
    swap(v[l], v[r]);
    l++, r--, k--;
  }
  for (int i = n; i > 0; i--) {
    ans += tap(v[i]);
    upd(v[i]);
  }
  printf("%lld\n", ans);
}
