#include using namespace std; typedef long long ll; typedef pair P; #define REP(i,n) for(int i=0;i> x >> n; if(x>0){ ll ng=-1,ok=2000000000; while(ok-ng>1){ ll m=(ok+ng)/2; if(x<=m*(m+1)/2) ok=m; else ng=m; } if(ok>=n){ cout << x-n*(n+1)/2 << endl; return 0; } ll p=(n-ok)/2; x-=ok*(ok+1)/2; if((n-ok)%2==0){ cout << x-p << endl; return 0; }else{ cout << x-p+n << endl; return 0; } }else{ x*=-1; ll ng=-1,ok=2000000000; while(ok-ng>1){ ll m=(ok+ng)/2; if(x<=m*(m+1)/2) ok=m; else ng=m; } x*=-1; if(ok>=n){ cout << x+n*(n+1)/2 << endl; return 0; } ll p=(n-ok)/2; x+=ok*(ok+1)/2; if(x==0){ if((n-ok)%2==0){ cout << x-p << endl; return 0; }else{ cout << x-p+n << endl; return 0; } }else{ if((n-ok)%2==0){ cout << x+p << endl; return 0; }else{ cout << x+p-n << endl; return 0; } } } return 0; }