#include using namespace std; typedef long long LL; #define F(N,S,T) for(int N=(S);N<=(T);N++) LL sum(LL s,LL d,LL c){ return (s+s+(c-1)*d)*c/2; } void work(){ LL n,m; cin>>n>>m; cout<<(m>=n/2?n*(n-1)/2:sum(2*n-3,-4,m))<>t; while(t--){ work(); } return 0; }