#include <bits/stdc++.h>
const long long int maxn = 1e5 + 2;
using namespace std;
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i++) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
bool cmp(pair<int, int> p, pair<int, int> q) {
  if (p.second == q.second) {
    return p.first > q.first;
  } else {
    return p.second > q.second;
  }
}
long long int lcmN(int a, int b) {
  long long int large = max(a, b);
  long long int small = min(a, b);
  for (long long int i = large;; i += large) {
    if (i % small == 0) {
      return i;
    }
  }
}
int findX(int A, int B) {
  int j = 0, x = 0;
  while (A || B) {
    if ((A & 1) && (B & 1)) {
      x += (1 << j);
    }
    A >>= 1;
    B >>= 1;
    j += 1;
  }
  return x;
}
unsigned long long int merge(int a[], int t[], int l, int m, int r) {
  unsigned long long int ic = 0;
  int i, j, k;
  i = l, j = m, k = l;
  while ((i <= m) && (j <= r)) {
    if (a[i] <= a[j]) {
      t[k++] = a[i++];
    } else {
      t[k++] = a[j++];
      ic = ic + (m - i);
    }
  }
  while (i <= m - 1) {
    t[k++] = a[i++];
  }
  while (j <= r) {
    t[k++] = a[j++];
  }
  for (i = l; i <= r; i++) {
    a[i] = t[i];
  }
  return ic;
}
unsigned long long int _mergesort(int a[], int t[], int l, int r) {
  int m;
  unsigned long long int ic = 0;
  if (r > l) {
    m = (l + r) / 2;
    ic += _mergesort(a, t, l, m);
    ic += _mergesort(a, t, m + 1, r);
    ic += merge(a, t, l, m + 1, r);
  }
  return ic;
}
unsigned long long int mergesort(int a[], int s) {
  int t[s];
  return _mergesort(a, t, 0, s - 1);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  int a[n];
  unsigned long long int ans;
  for (int i = 0; i < n; i++) {
    a[i] = i + 1;
  }
  for (int i = 0; i < min(n / 2, k); i++) {
    swap(a[i], a[n - 1 - i]);
  }
  ans = mergesort(a, n);
  cout << ans;
}
