#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long ans = 0;
  int n, k;
  cin >> n >> k;
  while (n > 1 && k) {
    ans += n - 1;
    ans += n - 2;
    n -= 2;
    k--;
  }
  cout << ans << "\n";
}
int main() {
  solve();
  return 0;
}
