#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
string a, b, a1, b1;
int n, k;
const int MAXN = 100100;
int mk;
int mas[MAXN];
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) mas[i] = i + 1;
  for (int i = 0; i < min(n / 2, k); ++i) {
    swap(mas[i], mas[n - 1 - i]);
  }
  int t = min(n / 2, k);
  long long ans = 0;
  for (int i = 0; i < t; ++i) {
    ans += (n - 1 - i);
  }
  for (int i = t; i < n - t; ++i) ans += t;
  for (int i = n - t; i < n; ++i) ans += (n - 1 - i);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(time(0));
  solve();
  return 0;
}
