#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const double E = 1e-5;
template <class T>
inline void cerrV(T) {}
template <class T>
inline void cerrV2(vector<T>) {}
long long n, k;
long long ans;
int main(void) {
  cin >> n >> k;
  if (k >= n / 2) {
    cout << (n - 1) * n / 2 << endl;
    return 0;
  }
  for (int i = 0; i < k; ++i) {
    ans += (n - 2 * i - 1);
    ans += (n - 2 * i - 2);
  }
  cout << ans << endl;
  return 0;
}
