#include <bits/stdc++.h>
using namespace std;
int const MAXN = 100100;
int n, s[MAXN], mas[MAXN];
long long inv(int l, int r) {
  if (l == r) return 0;
  int mid = (l + r) / 2;
  long long ans = inv(l, mid) + inv(mid + 1, r);
  for (int i = l; i <= mid; i++) {
    int d = mid + 1;
    int u = r;
    while (u > d) {
      int m = (u + d) / 2;
      if (s[m] >= s[i])
        u = m - 1;
      else
        d = m + 1;
    }
    int m = (u + d) / 2;
    if (s[m] >= s[i]) m--;
    if (m >= mid) ans += m - mid;
  }
  int len = 0;
  int i = l;
  int j = mid + 1;
  while (i <= mid || j <= r)
    if (i <= mid && j <= r) {
      if (s[i] < s[j]) {
        len++;
        mas[len] = s[i];
        i++;
      } else {
        len++;
        mas[len] = s[j];
        j++;
      }
    } else if (i <= mid) {
      len++;
      mas[len] = s[i];
      i++;
    } else {
      len++;
      mas[len] = s[j];
      j++;
    }
  for (int i = 1; i <= len; i++) s[l + i - 1] = mas[i];
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) s[i] = i;
  for (int qq = 1; qq <= min(k, n / 2); qq++) swap(s[qq], s[n - qq + 1]);
  cout << inv(1, n);
  return 0;
}
