#include <bits/stdc++.h>
int min(long long int a, long long int b) { return (a < b ? a : b); }
int main() {
  long long int n, k, kb, beg = 0, end = 0, middle = 0;
  std::cin >> n >> k;
  kb = min(n / 2, k);
  for (long long int i = 0; i < kb; i++) {
    beg += (n - i - 1);
    end += (n - 1) - (n - kb + i);
  }
  middle += (n - 2 * kb) * kb;
  std::cout << (beg + end + middle) << std::endl;
  return 0;
}
