#include #include using namespace std; using ll = long long; int u = 300; int main(){ ll r,b; cin >> r >> b; if(r > b) swap(r, b); if(r >= u * u) { ll ok = 1,ng = 1817125; while(ng - ok > 1) { ll mid = (ok + ng) / 2; if(mid * (mid + 1) / 2 * (2 * mid + 1) / 3 <= r + b) ok = mid; else ng = mid; } cout << ok << endl; } else { bitset<90000>dp, next; dp[0] = 1; int need = 0, max_r = 0; for(int i = 1; i <= u; i++) { need += i * i; next = dp; next |= dp << (i * i); for(int j = 0; j <= r; j++) { if(need - j <= b && next[j]) { max_r = max(max_r, j); } } swap(dp, next); } ll ok = 1,ng = 1817125; while(ng - ok > 1) { ll mid = (ok + ng) / 2; if(mid * (mid + 1) / 2 * (2 * mid + 1) / 3 <= max_r + b) ok = mid; else ng = mid; } cout << ok << endl; } }