Problem:
Integral Rectangles
Let us consider rectangles whose height,
h
, and
width,
w
, are both integers. We call such rectangles
integral rectangles
. In this problem, we consider only wide
integral rectangles, i.e., those with
w
>
h
.
We define the following ordering of wide integral rectangles. Given
two wide integral rectangles,
The one shorter in its diagonal line is smaller, and
If the two have diagonal lines with the same length, the one shorter
 in its height is smaller.
Given a wide integral rectangle, find the smallest wide integral
rectangle bigger than the given one.
Input
The entire input consists of multiple datasets. The number of
 datasets is no more than 100. Each dataset describes a wide integral
 rectangle by specifying its height and width, namely
h
and
w
, separated by a space in a line, as follows.
h
w
For each dataset,
h
and
w
(>
h
) are both
integers greater than 0 and no more than 100.
The end of the input is indicated by a line of two zeros separated by a space.
Output
For each dataset, print in a line two numbers describing the
height and width, namely
h
and
w
(>
h
), of the
smallest wide integral rectangle bigger than the one described in the
dataset.  Put a space between the numbers. No other
characters are allowed in the output.
For any wide integral rectangle given in the input, the width and
height of the smallest wide integral rectangle bigger than the given
one are both known to be not greater than 150.
In addition, although
the ordering of wide integral rectangles uses the comparison of
lengths of diagonal lines, this comparison can be replaced with that
of squares (self-products) of lengths of diagonal lines, which can
avoid unnecessary troubles possibly caused by the use of floating-point
numbers.
Sample Input
1 2
1 3
2 3
1 4
2 4
5 6
1 8
4 7
98 100
99 100
0 0
Output for the Sample Input
1 3
2 3
1 4
2 4
3 4
1 8
4 7
2 8
3 140
89 109

Submitted solutions:

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool solve()
{
    int H,W;
    cin>>H>>W;
    if(H==0&&W==0)return 0;
    vector<pair<int,int>>bigger;
    auto comp=[](pair<int,int>p,pair<int,int>q)
    {
        auto[ph,pw]=p;
        auto[qh,qw]=q;
        return ph*ph+pw*pw==qh*qh+qw*qw?ph<qh:ph*ph+pw*pw<qh*qh+qw*qw;
    };
    for(int h=1;h<=200;h++)for(int w=h+1;w<=200;w++)
    {
        if(comp(make_pair(H,W),make_pair(h,w)))bigger.push_back(make_pair(h,w));
    }
    sort(bigger.begin(),bigger.end(),comp);
    cout<<bigger[0].first<<' '<<bigger[0].second<<'\n';
    return 1;
}
int main(){while(solve()){}}
accuracy: 1
time_ms: 90
memory_kb: 3540
final_rank: 15

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

int main(){
    int h,w;
    int size=0;
    pair<int,pair<int,int> > rect[30000];
    for(int i=1;i<=150;i++){
		for(int j=i+1;j<=150;j++){
            rect[size++]=make_pair(i*i+j*j,make_pair(i,j));
        }
     }
    while(1){
     cin>>h>>w;
     if(h==0&&w==0)break;
     
     sort(rect,rect+size);
     pair<int,pair<int,int> >q=make_pair(h*h+w*w,make_pair(h,w));
     pair<int,pair<int,int> >r=*upper_bound(rect,rect+size,q);
     cout<<r.second.first<<" "<<r.second.second<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 3

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

int main(){
    while(true){
        int h,w;
        cin >> h >> w;
        if(h==0&&w==0){
            break;
        }

        vector<tuple<double,int,int>>vec(0);
        for(int i=1;i<150;i++){
            for(int j=i+1;j<=150;j++){
                double len = sqrt(i*i+j*j);
                int tate=i;
                int yoko=j;
                vec.push_back({len,i,j});
            }
        }

        sort(vec.begin(),vec.end());
        for(int i=0;i<vec.size();i++){
            if(get<1>(vec[i])==h&&get<2>(vec[i])==w){
                cout << get<1>(vec[i+1]) << " " << get<2>(vec[i+1]) << endl;
                break;
            }
        }
    }
}
accuracy: 1
time_ms: 50
memory_kb: 3440
final_rank: 12

code_snippet: // #include "atcoder/all"
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <functional>
#include <cassert>
using namespace std;
// using namespace atcoder;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
// 右下左上
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<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){if(b==0){return a;}else{return gcd(b,a%b);}};
#define eb emplace_back
#define pb pop_back
#define eol endl
// ---------------------------------------------------------------------------

bool solve(){
    ll h,w;
    cin >> h >> w;
    if(h==0 && w==0) return false;
    ll res = h*h+w*w;
    ll mn = INF;
    P ans = P(INF,INF);
    for(ll i=1; i<500; i++){
        for(ll j=i+1; j<500; j++){
            if(i*i+j*j < res) continue;
            if(i*i+j*j > res){
                if(mn > i*i+j*j){
                    mn = i*i+j*j;
                    ans = P(i,j);
                }else if(mn == i*i+j*j){
                    chmin(ans,P(i,j));
                }
            }else{
                if(i > h){
                    if(mn > res){
                        mn = res;
                        ans = P(i,j);
                    }else{
                        chmin(ans,P(i,j));
                    }
                }
            }
        }
    }
    cout << ans.first << " " << ans.second << endl;
    return true;
}

int main(){
    while(solve());
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3340
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
int h, w;

void solve(){
    int taikaku = h*h+w*w;
    int ans = 100000000;
    int ansH = 100000000;
    int ansW;
    for(int H = 1000; H >= 1; H--){
        for(int W = H+1; W <= 1000; W++){
            if(H == h && W == w) continue;
            if((H*H+W*W) >= taikaku && ans >= (H*H+W*W)){
                if((H*H+W*W) == taikaku){
                    if(H < h) continue;
                }
                ans = H*H+W*W;
                ansH = H; ansW = W;
            }
        }
    }
    cout << ansH << " " << ansW << endl;
}
int main(){
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        else solve();
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3068
final_rank: 4

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#endif

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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template<typename T>
vector<vector<T>> split(typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T val) {
    vector<vector<T>> res;
    vector<T> cur;
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

vector<string> split(typename string::const_iterator begin, typename string::const_iterator end, char val) {
    vector<string> res;
    string cur = "";
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

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); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 2 "Contests/Dummy/main.cpp"

/* #include <atcoder/all> */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */
#line 1 "library/ei1333/math/number-theory/prime-table.cpp"
/**
 * @brief Prime Table(素数テーブル)
 * @docs docs/prime-table.md
 */
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i * i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
#line 7 "Contests/Dummy/main.cpp"

bool solve(){
    VP v;
    FOR(i, 1, 150) FOR(j, i+1, 151) v.emplace_back(i, j);
    auto comp = [](const P& l, const P& r) {
        int dl = l.first*l.first + l.second*l.second;
        int dr = r.first*r.first + r.second*r.second;
        if(dl == dr) return l.first < r.first;
        return dl < dr;
    };
    sort(ALL(v), comp);
    while(1) {
        int h, w; cin >> h >> w;
        if(!h) break;
        print(*upper_bound(ALL(v), P(h, w), comp));
    }
    return false;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        while(solve());
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3560
final_rank: 5

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

using namespace std;

typedef long long LL;
typedef long double LD;

#define rep(i, n) for (LL i = 0; i < (n); i++)

int main()
{
   
   while(1)
   {
       int h_limit = 150, w_limit = 150;
       int h, w; cin >> h >> w;

       if(!h && !w)
        break;
       

       vector<tuple<int,int,int>> data;

       for(int i=1; i<=h_limit+ 10; i++){

           for(int j=1; j<=w_limit + 10; j++){
               if(j > i)
               data.push_back(make_tuple(i*i+j*j,i,j));
           }

       }

       sort(data.begin(),data.end());

       int pos = -1;
       int diagonal = h * h + w * w;

       rep(i,data.size()){
           if(get<0>(data.at(i)) == diagonal && get<1>(data.at(i) )== h && get<2>(data.at(i)) == w ){
               pos = i + 1;
               break;
           }
       }
       
       //cout << "pos:" << pos << endl;
       //break;

       cout << get<1>(data.at(pos)) << " " << get<2>(data.at(pos)) << endl;

   }
   
   
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3472
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using PLL = std::pair<ll, ll>;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))


int main() {
    while(true){
        ll h, w; cin >> h >> w;
        if(h == 0 && w == 0) break;
        ll t = h*h+w*w;
        vector<tuple<ll, ll, ll>> v;
        
        for(ll H=1; H<=200; H++){
            for(ll W=1; W<200; W++){
                if(W>H) v.emplace_back(H*H+W*W, H, W);
            }
        }
        sort(all(v));
        ll ac = v.size(), wa = -1;
        // while(abs(ac-wa)>1){
        //     ll mid = (ac+wa)/2;
        //     auto [a, b, c] = v[mid];
        //     if(a>t || (a==t && b>h)) ac=mid;
        //     else wa = mid;
        // }
        // auto [A, B, C] = v[ac];
        // cout << B << " " << C << "\n";
        for(auto [a, b, c] : v){
            if(a>t){
                cout << b << " " << c << "\n";
                break;
            }else if(a == t && b>h){
                cout << b << " " << c << "\n";
                break;
            }
        }
    }

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 4292
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using PLL = std::pair<ll, ll>;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))


int main() {
    while(true){
        ll h, w; cin >> h >> w;
        if(h == 0 && w == 0) break;
        ll t = h*h+w*w;
        vector<tuple<ll, ll, ll>> v;
        
        for(ll H=1; H<=200; H++){
            for(ll W=1; W<200; W++){
                if(W>H) v.emplace_back(H*H+W*W, H, W);
            }
        }
        sort(all(v));
        ll ac = v.size(), wa = -1;
        while(abs(ac-wa)>1){
            ll mid = (ac+wa)/2;
            auto [a, b, c] = v[mid];
            if(a>t || (a==t && b>h)) ac=mid;
            else wa = mid;
        }
        auto [A, B, C] = v[ac];
        cout << B << " " << C << "\n";
        // for(auto [a, b, c] : v){
        //     if(a>t){
        //         cout << b << " " << c << "\n";
        //         break;
        //     }else if(a == t && b>h){
        //         cout << b << " " << c << "\n";
        //         break;
        //     }
        // }
    }

    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 4428
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct P{
    int h;
    int w;

    P(int h, int w): h(h), w(w){}
    
    int l() const {
        return this->h * this->h + this->w * this->w;
    }

    bool operator<(const P &other) const {
        if(l() == other.l()) return this->h < other.h;
        else return l() < other.l();
    }
};

int main(){

    vector<P> d;
    for(int i = 1; i < 1000; i++){
        for(int j = i+1; j < 1000; j++){
            d.push_back(P(i, j));
        }
    }

    // cerr << d[2].h << " " << d[2].w << endl;

    sort(d.begin(), d.end());

    while(true){
        int h, w;
        cin >> h >> w;
        if(!h && !w) break;
        P c(h, w);
        int ac = d.size();
        int wa = -1;
        while(ac-wa > 1){
            int wj = (ac+wa)/2;
            if(c < d[wj]) ac = wj;
            else wa = wj;
        }
        cout << d[ac].h << " " << d[ac].w << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 9008
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;

int main() {
    while(true) {
        int h,w;
        cin >> h >> w;
        if((h|w)==0) break;
        ll dist=h*h+w*w;
        vector<pair<int,pair<int,int>>> ans;
        for(int i=1;i<=150;i++) {
            for(int j=i+1;j<=150;j++) {
                ll tot=i*i+j*j;
                if(dist<tot) ans.push_back({tot,{i,j}});
                else if(dist==tot&&h<i) ans.push_back({tot,{i,j}}); 
            }
        } 
        sort(all(ans));
        cout << ans[0].second.first << " " << ans[0].second.second << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3552
final_rank: 9

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

int main() {
    int h, w;
    while(cin >> h >> w, h) {
        int cnt=h*h+w*w;
        vector<tuple<int, int, int>> mini;
        for(int i=1; i<=150; i++) {
            for(int j=i+1; j<=151; j++) {
                if(cnt<i*i+j*j) {
                    mini.push_back(make_tuple(i*i+j*j, i, j));
                }
                else if(cnt==i*i+j*j&&h<i) {
                    mini.push_back(make_tuple(i*i+j*j, i, j));
                }
            }
        }
        sort(mini.begin(), mini.end());
        cout << get<1>(mini[0]) << ' ' << get<2>(mini[0]) << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3576
final_rank: 10

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

int main() {
    while(true) {
        int h, w;
        cin >> h >> w;
        if(h==0) return 0;
        int cnt=h*h+w*w;
        vector<tuple<int, int, int>> mini;
        for(int i=1; i<=150; i++) {
            for(int j=i+1; j<=151; j++) {
                if(cnt<i*i+j*j) {
                    mini.push_back(make_tuple(i*i+j*j, i, j));
                }
                else if(cnt==i*i+j*j&&h<i) {
                    mini.push_back(make_tuple(i*i+j*j, i, j));
                }
            }
        }
        sort(mini.begin(), mini.end());
        cout << get<1>(mini[0]) << ' ' << get<2>(mini[0]) << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3504
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <string>
#include <math.h>
using namespace std;
int main(){
    long long int h,w,n=0,a=0,b=0;
    cin>>h;
    while(h!=0){
        a=0;
        b=0;
        cin>>w;
        n=h*h+w*w;
        for(int i=n;a==0&&b==0;i++){
            for(int j=1;(2*j*j)<(i)&&a==0;j++){
                for(int k=1;k<=(i-j*j);k++){
                    if(k*k==i-j*j){
                        if(i==n&&j>h){
                            a=k;
                            b=j;
                            break;
                        }
                        else if(i!=n){
                            a=k;
                            b=j;
                            break;
                        }
                    }
                }
            }
        }
        cout<<b<<' '<<a<<endl;
        cin>>h;
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3012
final_rank: 8

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define eps 1e-9
#define INF 2000000000              // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))

#ifndef LOCAL
#define dmp(...) ;
#else
#define dmp(...)                                                               \
  cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl
#endif

// ---------------- Utility ------------------

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

// ----------------- Input -------------------

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}

template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}

// ----------------- Output ------------------

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ',' << p.second;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  return os << "}";
}

template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  return os << "}";
}

void dump_str_rec(ostringstream &) {}

template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}

template <class T, class... U>
string dump_str(T &&arg, U &&... args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<U>(args)...);
  return oss.str();
}

// --------------- Fast I/O ------------------

void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

// ------------ End of template --------------

#define endl "\n"

bool comp(P a, P b) {
  if (sq(a.first) + sq(a.second) == sq(b.first) + sq(b.second))
    return a.first < b.first;
  return sq(a.first) + sq(a.second) < sq(b.first) + sq(b.second);
}

bool solve() {
  int h, w;
  cin >> h >> w;
  if (h == 0 && w == 0) return false;
  P a(1000, 1000);
  for (int i = 1; i < 1000; i++) {
    for (int j = i + 1; j < 1000; j++) {
      if (!comp(P(h, w), P(i, j))) continue;
      if (comp(P(i, j), a)) a = P(i, j);
    }
  }
  cout << a.first << ' ' << a.second << endl;
  return true;
}

int main() {
  fastio();
  // solve();
  while (solve()) {}
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3140
final_rank: 14

code_snippet: //#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const double eps = 1e-7;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> ansx,ansy;
    while(true){
        int x,y;
        cin>>x>>y;
        int l=x*x+y*y;
        int lw=INF;
        if(l==0)break;
        int resx,resy;
        for(int i=1;i<=500;i++){
            for(int j=i+1;j<=500;j++){
                int ltemp=i*i+j*j;
                if(ltemp>l&&ltemp<lw){
                    lw=ltemp;
                    resx=i;
                    resy=j;
                }
                if (ltemp == l && ltemp < lw&&x<i){
                    lw = ltemp;
                    resx = i;
                    resy = j;
                }
            }
        }
        ansx.push_back(resx);
        ansy.push_back(resy);
    }
    rep(i,ansx.size()){
        cout<<ansx[i]<<" "<<ansy[i]<<"\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3096
final_rank: 1

code_snippet: #pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

pair<int, int> P(int h, int w){
	return mp(h*h+w*w, h);
}

signed main(){
	while(true){
		int h, w;
		cin >> h >> w;
		if(h == 0) return 0;
		int ansH = 1000, ansW = 1000;
		for(int i=1; i<=1000; i++){
			for(int j=i+1; j<=1000; j++){
				if(P(h, w) < P(i, j) && P(i, j) <= P(ansH, ansW)){
					ansH = i;
					ansW = j;
				}
			}
		}
		cout << ansH << " " << ansW << endl;
	}
}
accuracy: 1
time_ms: 40
memory_kb: 3364
final_rank: 11

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

int main() {
    while (1) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) return 0;
        int hoge = h * h + w * w;
        vector<pair<int, int>> ans;
        for (int iw = 1; iw < 151;iw++){
            for (int ih = 1; ih < iw;ih++){
                int piyo = iw * iw + ih * ih;
                if(hoge <= piyo){
                    if (iw == w && ih == h) continue;
                    if (hoge == piyo && ih < h) continue;
                    ans.push_back(pair<int, int>(piyo, ih));
                }
            }
        }
        sort(ans.begin(), ans.end());
        int ww = (ans[0].first - ans[0].second * ans[0].second);
        int i;
        for (i = 1; i < 151; i++) {
            if (i * i == ww) break;
        }
        cout << ans[0].second << " " << i << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3340
final_rank: 6

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

struct Rect {
    Rect() = default;
    Rect(int _h, int _w) : h(_h), w(_w) {}
    int diagonal2() const { return h*h + w*w; }
    int h, w;
};

bool operator <(const Rect& a, const Rect& b) {
    if (a.diagonal2() == b.diagonal2()) return a.h < b.h;
    return a.diagonal2() < b.diagonal2();
}

bool operator >(const Rect& a, const Rect& b) {
    if (a.diagonal2() == b.diagonal2()) return a.h > b.h;
    return a.diagonal2() > b.diagonal2();
}

void Main(const int H, const int W) {
    Rect input(H, W);
    Rect ans(5000, 5000);
    for (int h = 1; h < 1000; ++h) {
        for (int w = h + 1; w < 1000; ++w) {
            Rect rect(h, w);
            if (rect > input) {
                ans = min(ans, rect);
            }
        }
    }
    cout << ans.h << " " << ans.w << endl;
}

int main() {
    while (true) {
        int h, w;
        cin >> h >> w;
        if (!(h | w)) break;
        Main(h, w);
    }
    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 3084
final_rank: 18

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

struct Rect {
    Rect() = default;
    Rect(int _h, int _w) : h(_h), w(_w) {}
    int h, w;
};

bool operator <(const Rect& a, const Rect& b) {
    int A2 = a.h * a.h + a.w * a.w;
    int B2 = b.h * b.h + b.w * b.w;
    if (A2 == B2) {
        return a.h < b.h;
    }
    return A2 < B2;
}

bool operator >(const Rect& a, const Rect& b) {
    int A2 = a.h * a.h + a.w * a.w;
    int B2 = b.h * b.h + b.w * b.w;
    if (A2 == B2) {
        return a.h > b.h;
    }
    return A2 > B2;
}

void Main(const int H, const int W) {
    Rect input(H, W);
    Rect ans(100000, 100000);
    for (int h = 1; h < 1000; ++h) {
        for (int w = h + 1; w < 1000; ++w) {
            Rect rect(h, w);
            if (rect > input) {
                ans = min(ans, rect);
            }
        }
    }
    cout << ans.h << " " << ans.w << endl;
}

int32_t main() {
    while (true) {
        int h, w;
        cin >> h >> w;
        if (!(h | w)) break;
        Main(h, w);
    }
    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 3076
final_rank: 19