#include<bits/stdc++.h>
#define int long long
using namespace std;
int get(int x){
  return (x*(x-1))/2;
}
signed main(){
  int n,d,ans;
  cin>>n>>d;
  if(d==1)ans=get(n);
  else if(d==2)ans=get(n)-1;
  else if(d==3)ans=get(n-2)+2;
  else ans=get(n-(d+1)+2)+(d-1);
  
  if(d>=3&&(n-1)!=d)ans+=(n-(d+1));
  
  cout<<ans<<endl;
}

