#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int n, k;
int main() {
  cin >> n >> k;
  int l = 0, r = n - 1;
  long long ans = 0;
  while (l < r && k > 0) {
    ans += r - l - 1;
    ans += r - l;
    k--;
    r--;
    l++;
  }
  cout << ans << endl;
  return 0;
}
