#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const int base = 10;
const int maxn = 205;
const long double pi = acosl(-1.0);
const long double eps = 1e-9;
void error(void) { exit(1); }
void solve() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  long long cur = n - 1;
  for (int i = 0; i < min(k, n / 2); i++) {
    ans += 2 * cur - 1;
    cur -= 2;
  }
  cout << ans;
}
int main() {
  solve();
  return 0;
}
