#include <bits/stdc++.h>
using namespace std;
vector<int> read(int n) {
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  return v;
}
void solve() {
  long long int i, j, k, m, n, ans = 0, cnt = 0, sum = 0;
  cin >> n >> k;
  if (n == 1) {
    cout << 0 << "\n";
  } else {
    if (k >= n / 2) {
      cout << (n * (n - 1)) / 2;
    } else {
      ans = k * (2 * (n - 2 * k) + (2 * k - 1));
      cout << ans << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
