#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, ans = 0;
  cin >> n >> k;
  long long p = n - 1;
  long long t = k;
  while (t) {
    if (p < 1) break;
    ans = ans + p + (p - 1);
    t--;
    if (t == 0 || (p - 1) < 1) break;
    p -= 2;
  }
  cout << ans;
  return 0;
}
