#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    long long n, d;
    cin >> n >> d;

    long long ans;
    if(d == 1)
        ans = n * (n - 1) / 2;
    else
        ans = (n - d) * (n - d - 1) / 2 + 2 * n - d - 2;
    cout << ans << endl;

    return 0;
}