Problem:
Problem C
Training Schedule for ICPC
With little time remaining until ICPC, you decided to reschedule your training plan.  As maintaining both mental and physical vitality is important, you decided to spend
n
days of the remaining
n
+
m
days for training, and
m
days for repose.  The question is which days should be used for the training and which for the repose. A schedule that increases your
ICPC power
more is better.
Training days increase the power, and consecutive training days are more effective.  One day of training on the
k-
th day of consecutive training days increases the power by 2
k
− 1, where
k
= 1 for the first day of the consecutive training days.  A single training day increases the power by only 1, but two consecutive training days increase it by 1 + 3 = 4, and three consecutive training days increase it by 1 + 3 + 5 = 9.
Repose days, on the other hand, decrease the power, and consecutive repose days decrease it more rapidly.  One day of repose on the
k-
th day of consecutive repose days decreases the power by 2
k
− 1, where
k
= 1 for the first day of the consecutive repose days.  A single repose day decreases the power by only 1, but two consecutive repose days decrease it by 1 + 3 = 4, and three consecutive repose days decrease it by 1 + 3 + 5 = 9.
Let us compute the largest increment of your ICPC power after
n
+
m
days of training and repose by the best training schedule.  Note that, if you have too many repose days, this may be negative.
Input
The input consists of multiple datasets, each in the following format.
n
m
Here,
n
and
m
are the numbers of training and repose days, respectively.  Neither of them exceeds 10
6
, and at least one of them is non-zero.
The end of the input is indicated by a line containing two zeros.
    The number of datasets does not exceed 100.
Output
For each of the datasets, output in a line the largest increment of ICPC power after
n
+
m
days of training and repose by the best training schedule.
Sample Input
1 1
3 2
6 1
1 6
0 3
2 4
7 9
0 0
Output for the Sample Input
0
7
35
-17
-9
-4
10

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,m;
    vector<long long> lastans;
    while(true){
        cin >> n >> m;
        if(n==0&&m==0){
            break;
        }
        long long ans=n*n-m*m;
        for(long long i=1;i<=n&&i-1<=m;i++){
            long long sum=0;
            long long r=m/(i+1);
            if(m%(i+1)==0){
                sum+=(n-i+1)*(n-i+1)+(i-1)-((i+1)*r*r);
            }else{
                sum+=(n-i+1)*(n-i+1)+(i-1)-((i+1)*r*r+(m%(i+1))*(r+1)*(r+1)-(m%(i+1))*r*r);
            }           
            if(sum>ans){
                ans=sum;
            }
        }
        lastans.push_back(ans);
    }
    for(auto at:lastans){
        cout << at << endl;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3144
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool solve();

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}

int main() {
  while (solve());
  return 0;
}

struct Node{
  vector<Node*>ns;
  char c;
  int idx;
};

ll f(ll x){return x*x;}
bool solve() {
  int N,M;cin>>N>>M;
  if(N+M==0)return 0;

  ll ans=f(N)-f(M);
  //平方数の加減
  for(int i=1;i<=N;i++){
    ll ret = 0;    
    //練習日の塊の数i
    int j=i+1;
    //休息日の塊の数j
    if(j>M)break;
    //練習 i-1個の1日と1個のN-(i-1)日
    ret+=ll(i-1)*f(1)+1LL*f(N-(i-1));
    //休息 a個のfloor(M/j)日 b個のfloor(M/j)+1日
    ll b=M%j;
    ll a=j-b;
    ret-=a*f(M/j)+b*f(M/j+1);
    chmax(ans,ret);
  }
  cout<<ans<<endl;
  return 1;
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

/*
k回に休みを分割するとk-2回1日、1回n-k+2日
m/k回ずつ
*/

void solve(ll n, ll m) {
    if (m == 0) {
        cout << n * n << endl;
        return;
    }
    ll ans = n * n - m * m;
    for (ll k = 2; k <= min(n + 1, m); k++) {
        ll kari = k - 2 + (n - k + 2) * (n - k + 2);
        ll len = m / k;
        ll mod = m % k;
        kari -= mod * (len + 1) * (len + 1) + (k - mod) * len * len;
        ans = max(ans, kari);
    }
    cout << ans << endl;
}

int main() {
    while (true) {
        ll n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        solve(n, m);
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3052
final_rank: 1

code_snippet: /* template */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()


int main(){
    cin.tie(nullptr);ios::sync_with_stdio(false);

    /* (>_<) mycode! */
    ll n, m;
    while (true) {
        cin >> n >> m;
        if (n == 0 && m == 0) {
            return 0;
        }

        if (n == 0) {
            cout << -(m * m) << endl;
            continue;
        }
        if (m == 0) {
            cout << n * n << endl;
            continue;
        }
        if (m == 1) {
            cout << n * n - 1 << endl;
            continue;
        }
        ll ans = -1e18;
        ll x = min(n, m - 1);
        for (ll i = 1; i <= x; i++) {
            ll max_n = n - i + 1;
            ll min_m = m / (i + 1);
            ll cnt_min = (min_m + 1) * (i + 1) - m;
            ll score = i - 1 + max_n * max_n;
            score -= min_m * min_m * cnt_min;
            score -= (min_m + 1) * (min_m + 1) * (i + 1 - cnt_min);
            ans = max(ans, score);
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3292
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define rep2(i,m,n) for(ll i=ll(m);i<ll(n);i++)
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
#define pb push_back

const long double EPS = 0.0000000001;
const ll INF = 1000000000000000000;
const double pi = std::acos(-1.0);

__int128 read_int128(){ //__int128を入力する
    string S;
    cin >> S;
    int N = S.size();
    int st = 0;
    bool minus = false;
    if(S[0] == '-'){
        minus = true;
        st = 1;
    }
    __int128 res = 0;
    rep2(i,st,N) res = res*10+int(S[i]-'0');
    if(minus) res *= -1;
    return res;
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) { //これでcoutで__int128を出力できるように
    std::ostream::sentry s(dest);
    if (s) {
      __uint128_t tmp = value < 0 ? -value : value;
      char buffer[128];
      char *d = std::end(buffer);
      do {
          --d;
          *d = "0123456789"[tmp % 10];
          tmp /= 10;
      } while (tmp != 0);
      if (value < 0) {
          --d;
          *d = '-';
      }
      int len = std::end(buffer) - d;
      if (dest.rdbuf()->sputn(d, len) != len) {
          dest.setstate(std::ios_base::badbit);
      }
    }
    return dest;
}

void Yes(){ cout << "Yes" << endl; } //文字列"Yes"を標準出力
void No(){ cout << "No" << endl; } //文字列"No"を標準出力

template<class T> bool chmin(T& a,T b){
    if(a > b){
        a = b;
        return true;
    }
    else return false;
}

template<class T> bool chmax(T& a,T b){
    if(a < b){
        a = b;
        return true;
    }
    else return false;
}



int main(){
    while(1){
        ll N,M;
        cin >> N >> M;
        if(N == 0 && M == 0) break;
        if(M == 0) cout << N*N << endl;
        else if(N == 0) cout << -M*M << endl;
        else{
            ll ans = N*N-M*M;
            rep2(i,2,M+1){ //休憩をi個に分ける→練習はi-1個に分ける
                if(i-1 > N) break;
                ll plus = (N+2-i)*(N+2-i)+1*(i-2);
                ll small = M/i;
                ll big_num = M%i;
                ll big = small+1;
                ll small_num = i-big_num;
                ll minus = small*small*small_num + big*big*big_num;
                ans = max(ans,plus-minus);
            }
            cout << ans << endl;
        }
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3352
final_rank: 8

code_snippet: #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define rrep(i,l,r) for(int i=(r)-1;i>=(l);--i)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long,long long>;
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define pqueue priority_queue
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define inr(l, x, r) (l <= x && x < r)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
#define INF (1<<30)-1
#define INFLL (1LL<<60)-1
#define popcount __builtin_popcount
#define UNIQUE(v) sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end());
void yn(bool flag){if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;}
template <typename T>
bool chmax(T &a,const T& b){if(a<b){a=b;return true;}return false;}
template <typename T>
bool chmin(T &a,const T& b){if(a>b){a=b;return true;}return false;}
void solve();

// using mint = modint998244353;

#ifdef LOCAL
#  include "debug_print.hpp"
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(10);
    solve();
}

void solve(){
    while(true){
        ll N,M; cin>>N>>M;
        if(N==0&&M==0)return;
        ll ans=-INFLL;
        if(N==0){
            cout<<-M*M<<endl;
            goto g;
        }
        if(M==0){
            cout<<N*N<<endl;
            goto g;
        }
        if(M==1){
            cout<<N*N-1<<endl;
            goto g;
        }
        rep(i,2,min(M+1,N+2)){
            ll n1=M/i;
            ll n2=n1+1;
            n1*=n1,n2*=n2;
            n2*=M%i;
            n1*=i-M%i;
            // debug(i,n1,n2,(N-i+2)*(N-i+2)+(i-2)-n1-n2);
            chmax(ans,(N-i+2)*(N-i+2)+(i-2)-n1-n2);
        }
        cout<<ans<<endl;
        g:;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3384
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
using ull = unsigned long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
template<class T> using pqmin = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pqmax = priority_queue<T>;
const ll inf=LLONG_MAX/3;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define si(x) ll(x.size())
#define rept(n) for(ll _ovo_=0;_ovo_<n;_ovo_++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rng(i,l,r) for(ll i=l;i<r;i++)
#define gnr(i,l,r) for(ll i=r-1;i>=l;i--)
#define fore(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
template<class T> bool chmin(T& a, const T& b){ if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, const T& b){ if(a >= b) return 0; a = b; return 1; }
template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); }
template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); }
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define VLL(name,size) vector<ll>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>> name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>> name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>> name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SUM(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
template<class T, class F = less<>> void sor(T& a, F b = F{}){ sort(all(a), b); }
template<class T> void uniq(T& a){ sor(a); a.erase(unique(all(a)), end(a)); }
template<class T, class F = less<>> map<T,vector<ll> > ivm(vector<T>& a, F b = F{}){ map<T,vector<ll> > ret; rep(i,si(a))ret[a[i]].push_back(i); return ret;}
template<class T, class F = less<>> map<T,ll> ivc(vector<T>& a, F b = F{}){ map<T,ll> ret; rep(i,si(a))ret[a[i]]++; return ret;}
template<class T, class F = less<>> vector<T> ivp(vector<T> a){ vector<ll> ret(si(a)); rep(i,si(a))ret[a[i]] = i; return ret;}
template<class T, class F = less<>> vector<ll> rev(vector<T> a){ reverse(all(a)); return a;}
template<class T, class F = less<>> vector<ll> sortby(vector<T> a, F b = F{}){vector<ll> w = a; sor(w,b); vector<pll> v; rep(i,si(a))v.eb(a[i],i); sor(v); if(w[0] != v[0].first)reverse(all(v)); vector<ll> ret; rep(i,si(v))ret.pb(v[i].second); return ret;}
template<class T, class P> vector<T> filter(vector<T> a,P f){vector<T> ret;rep(i,si(a)){if(f(a[i]))ret.pb(a[i]);}return ret;}
template<class T, class P> vector<ll> filter_id(vector<T> a,P f){vector<ll> ret;rep(i,si(a)){if(f(a[i]))ret.pb(i);}return ret;}
ll monotone_left(function<bool(ll)> f){ll l = -1,r = (ll)1e18 + 1; assert(f(l + 1) >= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?l:r) = mid;} return l;}
ll monotone_left(ll l,ll r,function<bool(ll)> f){l--; assert(f(l + 1) >= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?l:r) = mid;} return l;}
ll monotone_right(function<bool(ll)> f){ll l = -1,r = (ll)1e18 + 1; assert(f(l + 1) <= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?r:l) = mid;} return r;}
ll monotone_right(ll l,ll r,function<bool(ll)> f){l--; assert(f(l + 1) <= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?r:l) = mid;} return r;}
double monotone_double_left(double l,double r,function<bool(double)> f){assert(f(l) >= f(r)); rep(_,100){double mid = (l + r) / 2.0; (f(mid)?l:r) = mid;} return l;}
double monotone_double_right(double l,double r,function<bool(double)> f){assert(f(l) <= f(r)); rep(_,100){double mid = (l + r) / 2.0; (f(mid)?l:r) = mid;} return r;}
template<class S> S unimodal_max(ll l,ll r,function<S(ll)> f){while(l + 2 < r){ll m1 = l + (r - l) / 3,m2 = l + (r - l) / 3 * 2; if(f(m1) < f(m2))l = m1; else r = m2;} S ret = f(l); rng(k,l,r + 1)chmax(ret,f(k)); return ret;}
template<class S> S unimodal_min(ll l,ll r,function<S(ll)> f){while(l + 2 < r){ll m1 = l + (r - l) / 3,m2 = l + (r - l) / 3 * 2; if(f(m1) > f(m2))l = m1; else r = m2;} S ret = f(l); rng(k,l,r + 1)chmin(ret,f(k)); return ret;}
vector<pll> neighbor4(ll x,ll y,ll h,ll w){vector<pll> ret;rep(dr,4){ll xx = x + dx[dr],yy = y + dy[dr]; if(0 <= xx && xx < h && 0 <= yy && yy <w)ret.eb(xx,yy);} return ret;};
vector<pll> neighbor8(ll x,ll y,ll h,ll w){vector<pll> ret;rep(dr,8){ll xx = x + dx[dr],yy = y + dy[dr]; if(0 <= xx && xx < h && 0 <= yy && yy <w)ret.eb(xx,yy);} return ret;};

void outb(bool x){cout<<(x?"Yes":"No")<<"\n";}
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
ll gcd(ll a,ll b){return (b?gcd(b,a%b):a);}
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); per(i,ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
vll prime_table(ll n){vec(ll,isp,n+1,1);vll res;rng(i,2,n+1)if(isp[i]){res.pb(i);for(ll j=i*i;j<=n;j+=i)isp[j]=0;}return res;}
ll powll(lll x,ll y){lll res = 1; while(y){ if(y & 1)res = res * x; x = x * x; y >>= 1;} return res;}
ll powmod(lll x,ll y,lll mod){lll res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod; y>>=1;} return res; }
ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0)u+=m;return u;}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }

template <class T> vector<T> &operator++(vector<T> &v) {
		fore(e, v) e++;
		return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
		auto res = v;
		fore(e, v) e++;
		return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
		fore(e, v) e--;
		return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
		auto res = v;
		fore(e, v) e--;
		return res;
}
template <class T> vector<T> &operator+=(vector<T> &l, const vector<T> &r) {
		fore(e, r) l.eb(e);
		return l;
}

template<class... Ts> void in(Ts&... t);
[[maybe_unused]] void print(){}
template<class T, class... Ts> void print(const T& t, const Ts&... ts);
template<class... Ts> void out(const Ts&... ts){ print(ts...); cout << '\n'; }
namespace IO{
#define VOID(a) decltype(void(a))
struct S{ S(){ cin.tie(nullptr)->sync_with_stdio(0); fixed(cout).precision(12); } }S;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...); }
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{}); }
template<class T> void o(const T& t){ o(t, P<4>{}); }
template<size_t N> void o(const char (&t)[N], P<4>){ cout << t; }
template<class T, size_t N> void o(const T (&t)[N], P<3>){ o(t[0]); for(size_t i = 1; i < N; i++){ o(' '); o(t[i]); } }
template<class T> auto o(const T& t, P<2>) -> VOID(cout << t){ cout << t; }
template<class T> auto o(const T& t, P<1>) -> VOID(begin(t)){ bool first = 1; for(auto&& x : t) { if(first) first = 0; else o(' '); o(x); } }
template<class T, size_t... idx> void otuple(const T& t, index_sequence<idx...>){ print(get<idx>(t)...); }
template<class T> auto o(T& t, P<0>) -> VOID(tuple_size<T>{}){ otuple(t, make_index_sequence<tuple_size<T>::value>{}); }
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO::i(t)); }
template<class T, class... Ts> void print(const T& t, const Ts&... ts){ IO::o(t); unpack(IO::o((cout << ' ', ts))); }
#undef unpack
bool solve(){
	ll n,m;
	cin>>n>>m;
	if(n + m == 0)return false;
	ll ans = -inf;
	if(n == 0){
		ans = -m * m;
		cout<<ans<<endl;
		return true;
	}
	for(ll k = 1;k <= n;k++){
		ll res = 0;
		{
			ll b = n - (k - 1);
			res += k - 1 + b * b;
		}
		{
			ll q = m / (k + 1);
			ll r = m % (k + 1);
			res -= r * (q + 1) * (q + 1) + (k + 1 - r) * q * q;
		}
		chmax(ans,res);
	}
	cout<<ans<<endl;
	return true;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	while(solve()){}
}
accuracy: 1
time_ms: 250
memory_kb: 3508
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef std::pair<long long, long long> P;
typedef std::priority_queue<P, std::vector<P>, std::greater<P>> PQ;
typedef std::complex<double> cd;

struct P3 {
    long long first, second, third;
};

struct P3P {
    P first, second, third;
};

struct compP3{
    bool operator()(const P3 &p1,const P3 &p2) const {
        if (p1.first != p2.first) return p1.first < p2.first;
        if (p1.second != p2.second) return p1.second < p2.second;
        else return p1.third < p2.third;
    }
};

struct gcompP3{
    bool operator()(const P3 &p1,const P3 &p2) const {
        if (p1.first != p2.first) return p1.first > p2.first;
        if (p1.second != p2.second) return p1.second > p2.second;
        else return p1.third > p2.third;
    }
};

const double PI = acos(-1.0);

bool ckran(int a, int n) {
    return (a >= 0 && a < n);
}

void yn (bool f) {
    if (f) std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
}

long long pplus(P a) {
    return a.first + a.second;
}

long long pminus(P a) {
    return a.first - a.second;
}

long long ptime(P a) {
    return a.first * a.second;
}

long long pdiv(P a) {
    return a.first / a.second;
}

template<typename T, typename U>
bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template<typename T, typename U>
bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template<typename T>
void outspace(std::vector<T> a) {
    int n = a.size();
    for (int i = 0; i < n; ++i) {
        std::cout << a[i];
        if (i != n - 1) std::cout << " ";
        else std::cout << std::endl;
    }
}

void outspace(P a) {
    std::cout << a.first << ' ' << a.second << '\n';
}

template<typename T>
void outendl(std::vector<T> a) {
    int n = a.size();
    for (int i = 0; i < n; ++i) {
        std::cout << a[i] << '\n';
    }
}

std::vector<long long> lltovec(long long n, long long base = 10, long long minsize = -1) {
    std::vector<long long> res;
    while (minsize-- > 0 || n > 0) {
        res.push_back(n % base);
        n /= base;
    }
    // std::reverse(res.begin(), res.end());
    return res;
}

long long vectoll(std::vector<long long> vec, long long base = 10) {
    long long res = 0;
    std::reverse(vec.begin(), vec.end());
    for (auto i : vec) {
        res *= base;
        res += i;
    }
    std::reverse(vec.begin(), vec.end());
    return res;
}

static const long long MOD = 998244353;
static const int MAXN = 1000000;  // 必要に応じて大きく設定

// 階乗・階乗逆元の配列
static long long fact[MAXN+1], invFact[MAXN+1];

// 繰り返し二乗法 (a^b mod M)
long long modpow(long long a, long long b, long long M) {
    long long ret = 1 % M;
    a %= M;
    while (b > 0) {
        if (b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
        b >>= 1;
    }
    return ret;
}

// 前処理: 階乗と逆元のテーブルを作る
void initFactorials() {
    // 階乗テーブル
    fact[0] = 1;
    for (int i = 1; i <= MAXN; i++) {
        fact[i] = fact[i-1] * i % MOD;
    }
    // 階乗逆元テーブル
    invFact[MAXN] = modpow(fact[MAXN], MOD - 2, MOD);  // フェルマーの小定理で逆元を計算
    for (int i = MAXN; i >= 1; i--) {
        invFact[i-1] = invFact[i] * i % MOD;
    }
}

// 組み合わせ数 C(n, r)
long long comb(int n, int r) {
    if (r < 0 || r > n) return 0;
    return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;
}

int main()
{
    vector<ll> an;
    while (true) {
        ll n, m;
        cin >> n >> m;
        if (n == m && n == 0) break;
        ll ans = -1e18;
        if (n == 0) {
            ans = -m * m;
            an.push_back(ans);
            continue;
        } else if (n == 1) {
            ans = -(m / 2) * (m / 2) - ((m + 1) / 2) * ((m + 1) / 2) + 1;
            an.push_back(ans);
            continue;
        }
        for (ll i = 2; i <= n + 1; ++i) {
            ll cur = 0;
            cur += (n - i + 2) * (n - i + 2);
            cur += i - 2;
            ll d = m / i;
            ll o = m % i;
            cur -= (d * d) * (i - o);
            cur -= ((d + 1) * (d + 1)) * o;
            chmax(ans, cur);
        }
        an.push_back(ans);
    }
    outendl(an);
}
accuracy: 1
time_ms: 240
memory_kb: 3180
final_rank: 15

code_snippet: // written in sccp_20250626 "aizu_d"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
inline bool chmax(ll &a,ll b){ return (a<b?a=b,true:false); }

int main(){
    const ll inf=1ll<<60;
    auto calc_two=[](ll x){
        return x*x;
    };
    while(true){
        ll n,m;
        cin>>n>>m;
        if(n==0 and m==0) return 0;
        ll ans=-inf;
        if(n==0){
            ans=-calc_two(m);
        }else if(m==0){
            ans=calc_two(n);
        }else if(m==1){
            ans=calc_two(n)-1;
        }else{
            rep(k,1,n+1){
                const ll d=m/(k+1);
                const ll c=m%(k+1);
                if(d<=0) break;
                ll sum=calc_two(n-k+1)+(k-1);
                sum-=calc_two(d)*((k+1)-c)+calc_two(d+1)*c;
                chmax(ans,sum);
            }
        }
        cout<<ans<<'\n';
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3456
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using ll = long long;

//  o := 練習日
//  x := 休息日
//
//  前提:
//  [1] 休息日、練習日ともに連続する長さ k の二乗の能力が増減する
//  [2] 休息日は可能な限り分割すべき
//  [3] 練習日は可能な限り連続にすべき
//
//  これらは x^2 + y^2 < (x + y)^2 を考えると良い
//
//  どのように分割すべきか?
//
//  **休息日は均等に割り振るべき**
//  例
//  n = 5, m = 5
//  xoooooxxxx : score 8
//  xxoooooxxx : score 12
//
//  これは f(x) = x^2 + (m - x) のグラフの最小値を観察すると良い
//
//  **練習日は偏るように割り振るべき**
//  例
//  n = 5, m = 5
//  xxooxxooox : score 4
//  xxoxxoooox : score 8
//
//  これは f(x) = x^2 + (n - x) のグラフの最大値を観察すると良い
//
//  ここまで考察できれば、あとは様々な考え方がある
//  ここでは、休息日をいくつに分割するか全探索する
//
//  休息日をk個に分割するとき、
//  長さ ceil(m / k) の連続する休息日は m % k個
//  長さ floor(m / k)の連続する休息日は k - (m % k) 個
//
//  それらの間に練習日を偏らせて詰めていく
//  長さ1の練習日をk - 2個, 長さn - (k - 2)の練習日を1個を詰めるのが最善

int solve() {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 1;
    auto f = [&](ll len) {
        return len * len;
    };
    if (n == 0) {
        cout << -f(m) << '\n';
        return 0;
    }
    if (m == 0) {
        cout << f(n) << '\n';
        return 0;
    }
    ll ans = f(n) - f(m);
    rep(k, 2, m + 1) {
        if (k - 1 > n) break;
        ll cur = 0;
        {  //  休息日
            ll len1 = (m + k - 1) / k;
            ll len2 = m / k;
            ll num1 = m % k;
            ll num2 = k - (m % k);
            cur -= num1 * f(len1) + num2 * f(len2);
        }
        {  //  練習日
            ll len1 = 1;
            ll len2 = n - (k - 2);
            ll num1 = k - 2;
            ll num2 = 1;
            cur += num1 * f(len1) + num2 * f(len2);
        }
        if (ans < cur) ans = cur;
    }
    cout << ans << '\n';
    return 0;
}
int main() {
    while (!solve());
}
accuracy: 1
time_ms: 30
memory_kb: 3456
final_rank: 9

code_snippet: #include<bits/extc++.h>
#define rep(i,n) for(int i=0; i< (n); i++)
#define all(a) begin(a),end(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 998244353;
const int inf = (1<<30);
const ll INF = (1ull<<62);
const int dx[8] = {1,0,-1,0,1,1,-1,-1};
const int dy[8] = {0,1,0,-1,1,-1,1,-1};
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int main(){
    while(1){
      ll n,m;
      cin>>n>>m;
      if(n == 0 && m == 0) break;
      if( n == 0) cout<<-(m*m)<<endl;
      else{
        ll ans = -INF;
        for(int i = 0; i<n; i++){
            ll k  = (n-i)*(n-i);
            ll d = m/(i+2);
            ll c = m%(i+2);
            //cout<<i<<" "<<k<<" "<<d<<" "<<c<<endl;
            chmax(ans,k - (d)*(d)*(i+2 - c) - (d+1)*(d+1)*(c) + i);
        }
        cout<<ans<<endl;
      }
    }
}
accuracy: 1
time_ms: 260
memory_kb: 3320
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
inline bool chmax(ll &a,ll b){ return (a<b?a=b,true:false); }

int main(){
    const ll inf=1ll<<60;
    auto calc_two=[](ll x){
        return x*x;
    };
    while(true){
        ll n,m;
        cin>>n>>m;
        if(n==0 and m==0) return 0;
        ll ans=-inf;
        if(n==0){
            ans=-calc_two(m);
        }else if(m==0){
            ans=calc_two(n);
        }else if(m==1){
            ans=calc_two(n)-1;
        }else{
            rep(k,1,n+1){
                const ll d=m/(k+1);
                const ll c=m%(k+1);
                if(d<=0) break;
                ll sum=calc_two(n-k+1)+(k-1);
                sum-=calc_two(d)*((k+1)-c)+calc_two(d+1)*c;
                chmax(ans,sum);
            }
        }
        cout<<ans<<'\n';
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3456
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
    while (true){
        long long n, m;
        cin >> n >> m;
        if (n == 0 and m == 0) break;
        long long ans = n * n - m * m;
        for (int i = 0; i < n; i++){
            long long sum = (n - i) * (n - i) + i;
            int d = i + 2;
            sum -= (m / d) * (m / d) * (d - m % d);
            sum -= (m / d + 1) * (m / d + 1) * (m % d);
            ans = max(ans, sum);
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 90
memory_kb: 3456
final_rank: 13

code_snippet: #include <bits/stdc++.h>
namespace ranges = std::ranges;
long long f(const long long sum, const long long num) {
    assert(1 <= num and num <= sum);
    const long long fl = sum / num, ce = (sum + num - 1) / num;
    const long long cn = sum % num, fn = num - cn;
    const long long res = fn * fl * fl + cn * ce * ce;
    return res;
}
long long g(const long long sum, long long num) {
    assert(1 <= num and num <= sum);
    num--;
    return num + (sum - num) * (sum - num);
}
long long solve(const long long N, const long long M) {
    long long ans = N * N - M * M;
    for (int n = 1 ; n <= N ; n++) {
        int m = n + 1;
        if (M < m) continue;
        const long long val = g(N, n) - f(M, m);
        ans = std::max(ans, val);
    }
    return ans;
}
int main() {
    while (true) {
        long long N, M;
        std::cin >> N >> M;
        if (N == 0 and M == 0) break;
        std::cout << solve(N, M) << '\n';
    }
}
accuracy: 1
time_ms: 50
memory_kb: 3456
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using ll = long long;

int solve() {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 1;
    auto f = [&](ll len) {
        return len * len;
    };
    if (n == 0) {
        cout << -f(m) << '\n';
        return 0;
    }
    if (m == 0) {
        cout << f(n) << '\n';
        return 0;
    }
    ll ans = f(n) - f(m);
    rep(k, 2, m + 1) {
        if (k - 1 > n) break;
        ll cur = 0;
        {
            ll len1 = (m + k - 1) / k;
            ll len2 = m / k;
            ll num1 = m % k;
            ll num2 = k - (m % k);
            cur -= num1 * f(len1) + num2 * f(len2);
        }
        {
            ll len1 = 1;
            ll len2 = n - (k - 2);
            ll num1 = k - 2;
            ll num2 = 1;
            cur += num1 * f(len1) + num2 * f(len2);
        }
        if (ans < cur) ans = cur;
    }
    cout << ans << '\n';
    return 0;
}
int main() {
    while (!solve());
}
accuracy: 1
time_ms: 30
memory_kb: 3584
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

void solve(ll n, ll m){
    if (n == 0){
        cout << -m*m << endl;
        return;
    }
    if (m == 1){
        cout << n*n - m*m << endl;
        return;
    }

    ll ans = -1e18;
    for (ll div = 1; div <= n; div++){
        ll k = 0;
        k = (n-div+1)*(n-div+1) + div-1;

        k -= (m/(div+1))*(m/(div+1))*(div+1-(m%(div+1))) + (m/(div+1)+1)*(m/(div+1)+1)*(m%(div+1));
        ans = max(ans, k);
    }
    cout << ans << endl;
}

int main(){
    ll n,m;cin >> n >> m;
    while(n || m){
        solve(n,m);
        cin >> n >> m;
    }
}
accuracy: 1
time_ms: 240
memory_kb: 3348
final_rank: 16

code_snippet: // AOJ 1658 - Training Schedule for ICPC
// ICPC Japan Domestic Contest 2022 - Problem C

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool solving() {
  int n, m; cin >> n >> m;
  if(n == 0 && m == 0) return false;

  ll ans = -9e18;
  if(m == 0) ans = (ll)n * n;
  for(int i=1; i<=min(n+1,m); ++i) {
    ll prac, rest;
    prac = max(0, i-2) + (ll)(n - max(0, i-2)) * (n - max(0, i-2));
    int more = m % i;
    rest = (ll)(m/i + 1) * (m/i + 1) * more + (ll)(m/i) * (m/i) * (i - more);
    ans = max(ans, prac - rest);
  }
  cout << ans << endl;
  return true;
}

int main() {
  while(solving()) {}
}
accuracy: 1
time_ms: 30
memory_kb: 3340
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

template <typename A> void chmin(A &l, const A &r) {
    if(r < l)
        l = r;
}
template <typename A> void chmax(A &l, const A &r) {
    if(l < r)
        l = r;
}

ll mod = 998244353;

vector<char> isprime;
void init() {
    isprime.assign(1000005, 1);
    isprime[0] = 0;
    isprime[1] = 0;
    for(int i = 2; i < 1000005; i++) {
        if(isprime[i]) {
            for(int j = i * 2; j < 1000005; j += i) {
                isprime[j] = 0;
            }
        }
    }
}

class UnionFind {
  private:
    int sz;
    vector<int> par, size_;

  public:
    UnionFind() {}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1) {
        iota(par.begin(), par.end(), 0);
    }
    int find(int x) {
        if(par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y)
            return;
        if(size_[x] < size_[y])
            swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x) {
        x = find(x);
        return size_[x];
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

ll n, m;
vector<string> v;
void input() { cin >> n >> m; }

void solve() {
    ll ans = -m * m;
    for(int i = 1; i <= n; i++) {
        ll a = (n - i + 1) * (n - i + 1) + (i - 1);

        ll b = m / (i + 1), c = m % (i + 1);
        a -= b * b * (i + 1 - c) + (b + 1) * (b + 1) * c;

        chmax(ans, a);
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // init();
    while(1) {
        input();
        if(n == 0 && m == 0)
            break;
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 3380
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

#define fast ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

ll n,m;
int main() {
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        ll ans = -m * m;
        for(int i = 1; i <= n; i++){
            ll now = i - 1 + (n - i + 1) * (n - i + 1);
            ll r = m / (i + 1);
            ll rem = m - r * (i + 1);
            now -= (r + 1) * (r + 1) * rem + (i + 1 - rem) * (r * r);
            ans = max(ans, now);
        }
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 250
memory_kb: 3344
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name
#define REP1(n) for(ll i=0;i<(n);i++)
#define REP2(i, n) for (ll i=0;i<(n);i++)
#define REP3(i, a, n) for (ll i=a;i<(n);i++)
#define REP4(i, a, b, n) for(ll i=a;i<(n);i+=b)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name
#define RREP1(n) for(ll i=(n)-1;i>=0;i--)
#define RREP2(i, n) for(ll i=(n)-1;i>=0;i--)
#define RREP3(i, a, n) for(ll i=(n)-1;i>=(a);i--)
#define RREP4(i, a, b, n) for(ll i=(n)-1;i>=(a);i-=(b))
#define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define len(n) (long long)(n).size()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvvc = vector<vvc>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;

ll intpow(ll a,ll b){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
        }
        a *= a;
        b /= 2;
    }
    return ans;
}
ll modpow(ll a,ll b,ll c){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b /= 2;
    }
    return ans;
}

template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; input(__VA_ARGS__)
#define CHA(...) char __VA_ARGS__; input(__VA_ARGS__)
#define VLL(name,length) vll name(length);rep(i,length){cin >> name[i];}
#define VVLL(name,h,w) vvll name(h,vll(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLL(name,a,b,c) vvvll name(a,vvll(b,vll(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VI(name,length) vi name(length);rep(i,length){cin >> name[i];}
#define VVI(name,h,w) vvi name(h,vi(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVI(name,a,b,c) vvvi name(a,vvll(b,vi(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VLD(name,length) vld name(length);rep(i,length){cin >> name[i];}
#define VVLD(name,h,w) vvld name(h,vld(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLD(name,a,b,c) vvvld name(a,vvld(b,vld(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VC(name,length) vc name(length);rep(i,length){cin >> name[i];}
#define VVC(name,h,w) vvc name(h,vc(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVC(name,a,b,c) vvvc name(a,vvc(b,vc(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VS(name,length) vs name(length);rep(i,length){cin >> name[i];}
#define VVS(name,h,w) vvs name(h,vs(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVS(name,a,b,c) vvvs name(a,vvs(b,vs(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define PLL(name) pll name;cin>>name.first>>name.second;
#define VPLL(name,length) vpll name(length);rep(i,length){cin>>name[i].first>>name[i].second;}

void print(){cout << "\n";}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
    os << "[";
    for (size_t i = 0; i < vec.size(); ++i) {
        os << vec[i];
        if (i + 1 < vec.size()) os << ", ";
    }
    os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::pair<T1, T2>>& a) {
    os << "[";
    for (size_t j = 0; j < a.size(); ++j) {
        os << "(" << a[j].first << ", " << a[j].second << ")";
		if (j + 1 < a.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::vector<std::vector<std::pair<T1, T2>>>& mat) {
	os << "[";
    for (size_t i = 0; i < mat.size(); ++i) {
		os << "[";
        for (size_t j = 0; j < mat[i].size(); ++j) {
            os << "(" << mat[i][j].first << ", " << mat[i][j].second << ")";
			if (j + 1 < mat[i].size()) os << ", ";
        }
		os << "]";
		if (i + 1 < mat.size()) os << ", ";
    }
	os << "]";
    return os;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
    os << "{";
    bool first = true;
    for (const auto& x : s) {
        if (!first) os << ", ";
        os << x;
        first = false;
    }
    os << "}";
    return os;
}

template <typename K, typename V>
std::ostream& operator<<(std::ostream& os, const std::map<K, V>& m) {
    os << "{";
    bool first = true;
    for (const auto& [key, val] : m) {
        if (!first) os << ", ";
        os << key << ": " << val;
        first = false;
    }
    os << "}";
    return os;
}

template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}

void write(){cout << "\n";}
template<class T, class... Ts>
void write(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}
void write(vll x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vi x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvi x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvi x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vld x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvld x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvld x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vc x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvc x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvc x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(vs x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void write(vvs x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void write(vvvs x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void write(pll x){cout << x.first << ' ' << x.second << '\n';}
void write(vpll x){rep(i,len(x)){cout << x[i].first << ' ' << x[i].second << '\n';}}
void write(vvpll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j].first << ' ' << x[i][j].second;if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}

template <typename T>
T sum(const std::vector<T>& v) {
    return std::accumulate(v.begin(), v.end(), T(0));
}

template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }

long long mod_mul(long long a, long long b, long long mod) {
    return (__int128)a * b % mod;
}

long long mod_pow(long long a, long long b, long long mod) {
    long long result = 1;
    a %= mod;
    while (b > 0) {
        if (b & 1) result = mod_mul(result, a, mod);
        a = mod_mul(a, a, mod);
        b >>= 1;
    }
    return result;
}

bool MillerRabin(ll x){
    
    if(x <= 1){return false;}
    if(x == 2){return true;}
    if((x & 1) == 0){return false;}
    vll test;
    if(x < (1 << 30)){
        test = {2, 7, 61};
    } 
    else{
        test = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    }
    ll s = 0;
    ll d = x - 1;
    while((d & 1) == 0){
        s++;
        d >>= 1;
    }
    for(ll i:test){
        if(x <= i){return true;}
        ll y = mod_pow(i,d,x);
        if(y == 1 || y == x - 1){continue;}
        ll c = 0;
        for(int j=0;j<s-1;j++){
            y = mod_mul(y,y,x);
            if(y == x - 1){
                c = 1;
                break;
            }
        }
        if(c == 0){
            return false;
        }
    }
    return true;
}

#include<atcoder/dsu>
vpll rle(vll seq){
    vpll res;
    for(auto x:seq){
        if(res.empty() || res.back().first != x){
            res.emplace_back(x,1);
        }
        else{
            res.back().second++;
        }
    }
    return res;
}
int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
    
    rep(i,(1<<16)){
        break;
        vll a;
        ll t = 0;
        rep(j,16){
            a.push_back((i >> j) & 1);
        }
        t = sum(a);
        if(t != 7){continue;}
        vpll s = rle(a);
        ll score = 0;
        for(auto [x,y]:s){
            score += y * y * (x == 0?-1:1);
        }
        if(score >= 0){
            print(a,score);
        }
        


    }
    //exit(0);
    while(1){
        LL(n,m);
        if(n == 0 && m == 0){break;}
        ll ans = -1LL<<60;
        if(n == 0){
            print(-(m * m));
            continue;
        }
        if(m == 0){
            print(n * n);
            continue;
        }
        chmax(ans, n * n - m * m);
        rep(i,2,m+1){
            if(i-1 > n){break;}
            ll temp = 0;
            ll x = m / i;
            ll y = m % i;
            temp -= x * x * (i - y) + (x + 1) * (x + 1) * y;
            temp += 1LL * (i-2) + (n - (i-2)) * (n - (i-2)) * 1LL;
            chmax(ans,temp);
        }
        print(ans);
        
        
    }
    
}
accuracy: 1
time_ms: 20
memory_kb: 3456
final_rank: 5