#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


int main() {
	long long int N,D;cin>>N>>D;
	if (D == 1) {
		cout<<N*(N-1)/2<<endl;
	}
	else if (D == 2) {
		cout<<N*(N-1)/2-1<<endl;
	}
	else {
		cout<<(N-D)*(N-D-1)/2+2*(N-D)+(D-2)<<endl;
	}
	return 0;
}