#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long MOD = 1e9 + 9;
bool isPrime(long long x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
double dist(double a, double b, double c, double d) {
  return sqrt((c - a) * (c - a) + (d - b) * (d - b));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  srand(time(0));
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    v[i] = i;
  }
  int l = 0, r = n - 1;
  while (l < r && k) {
    swap(v[l], v[r]);
    l++, r--, k--;
  }
  vector<int> seg(2 * n + 5);
  auto update = [&](int x) {
    for (seg[x += n] = 1; x > 1; x >>= 1) {
      seg[x >> 1] = seg[x] + seg[x ^ 1];
    }
  };
  auto get = [&](int l, int r) {
    long long res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        res += seg[l++];
      }
      if (r & 1) {
        res += seg[--r];
      }
    }
    return res;
  };
  for (int i = 0; i < n; i++) {
    ans += get(v[i] + 1, n + 1);
    update(v[i]);
  }
  cout << ans;
  return 0;
}
