#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
long long arr[100005];
int main() {
  long long n, k, ans = 0;
  scanf("%lld %lld", &n, &k);
  long long p = 1, q = n, valP = 1, valQ = n, valK = k;
  for (int i = 1; i <= n; i++) arr[i] = i;
  for (int i = 1; i <= n / 2; i++) {
    arr[p++] = valQ--, arr[q--] = valP++, k--;
    if (k == 0) break;
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i] != i)
      ans += arr[i] - 1;
    else
      ans += min(valK, n / 2);
  }
  cout << ans << "\n";
}
