#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int main() {
  long long n, k;
  long long ans = 0;
  cin >> n >> k;
  long long m = min(k, n / 2);
  while (m--) {
    n -= 2;
    ans += 2 * n + 1;
  }
  cout << ans << endl;
  return 0;
}
