#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int main() {
  ::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int j = 0;
  long long res = 0;
  int dist = (n - 1);
  for (int i = 0; i < k; ++i) {
    if (dist <= 0) break;
    res += dist * 2 - 1;
    dist -= 2;
    swap(arr[i], arr[n - i - 1]);
  }
  cout << res << endl;
  return 0;
}
