#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 1000000007;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

ll n, d;

int main(){
    cin >> n >> d;
    ll ans;
    if(d == 1){
        ans = n*(n-1)/2;
    } else if(d == 2){
        ans = n*(n-1)/2-1;
    } else{
        ans = d+2*(n-d-1)+(n-d-1)*(n-d)/2;
    }
    cout << ans << endl;
}