#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using ull = unsigned long long;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, k;
  cin >> n >> k;
  if (k >= n / 2) {
    cout << n * (n - 1) / 2 << endl;
  } else {
    ll ans = (n - 2 * k) * k;
    ll cnt = n - 1;
    for (int i = 0; i < k; i++) {
      ans += cnt;
      cnt--;
    }
    ans += k * (k - 1) / 2;
    cout << ans << endl;
  }
  return 0;
}
