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

Solution (Python):
def sol(h,w):
    d = (h*h) + (w*w)
    ans =(150,150)
    for dw in range(1,150):
        for dh  in range(1,dw):
            dd = (dw*dw) +  (dh*dh)
            if dd < d:continue
            if dw == w and dh == h:continue
            if dd == d and dh < h:continue
            da = (ans[0]*ans[0]) + (ans[1]*ans[1])
            if dd < da:ans = (dh,dw)
            elif dd == da:
                if dh < ans[0]: ans = (dh,dw)
    print(*ans)

if __name__ =="__main__":       
    while 1:
        h,w = list(map(int,input().split(' ')))
        if h ==0:break
        sol(h,w)

Solution (Python):
while True:
    h, w = map(int, input().split())
    if not h:
        break
    diagonal = h**2 + w**2
    ans = []
    append = ans.append
    for y in range(1, 151):
        for x in range(y+1, 151):
            if x**2+y**2 > diagonal or x**2+y**2 == diagonal and y > h:
                append((x**2+y**2, y, x))
                break
    print(*sorted(ans)[0][1:])

Solution (Python):
import math
anslist = []

while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break

    diagonal = h * h + w * w
    i = h + 1
    
    while True:
        
        if i * i >= diagonal - i * i:
            i = 0
            diagonal += 1
        elif math.sqrt(diagonal - i * i) == int(math.sqrt(diagonal - i * i)):
            anslist.append([i, int(math.sqrt(diagonal - i * i))])
            break
        i += 1

for i, j in anslist:
    print(i, j)

Solution (Python):
def less(ah, ad, bh, bd):
    if ad == bd:
        return ah < bh
    return ad < bd

def check(aw, ah, bw, bh, cw, ch):
    ad, bd, cd = aw * aw + ah * ah, bw * bw + bh * bh, cw * cw + ch * ch
    return less(ah, ad, bh, bd) and less(bh, bd, ch, cd)

while True:
    h, w = map(int, input().split())
    if not w:
        break
    d = w * w + h * h
    aw, ah = 1000, 1000
    for hh in range(1, 151):
        for ww in range(hh + 1, 151):
            if check(w, h, ww, hh, aw, ah):
                aw, ah = ww, hh
    print(ah, aw)

Solution (Python):



import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        diag = [[None for j in range(151)] for i in range(151)]
        for i in range(1, len(diag)):
            for j in range(1, len(diag[0])):
                if i >= j:
                    continue
                diag[i][j] = i * i + j * j
        while True:
            h, w = map(int, raw_input().split())
            if h == 0 and w == 0:
                break
            m = (float('inf'), float('inf'), float('inf'))
            for i in reversed(range(1, len(diag))):
                for j in reversed(range(1, len(diag[0]))):
                    if diag[i][j] is not None and diag[i][j] >= h * h + w * w:
                        if diag[i][j] == h * h + w * w:
                            if h < i <= m[0]:
                                m = (i, j, diag[i][j])
                        elif m[2] == diag[i][j]:
                            if i < m[0]:
                                m = (i, j, diag[i][j])
                        elif m[2] > diag[i][j]:
                            m = (i, j, diag[i][j])

            print '{0} {1}'.format(m[0], m[1])
                        
                        
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Solution (Python):
rect = [(i**2+j**2, i, j) for i in range(1,150) for j in range(i+1, 150)]
rect.sort()
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0: break
    _, n_h, n_w = rect[rect.index((h**2+w**2, h, w))+1]
    print(n_h, n_w)

Solution (Python):



import itertools

rects = sorted([(t[0]**2 + t[1] ** 2,t[0],t[1]) for t in itertools.combinations(range(1,151),2)],key = lambda x:(x[0],x[1]))

while True:
    h,w = map(int,input().split(" "))
    if h == 0 and w == 0:
        break
    rect = h**2 + w**2
    for i in range(len(rects)):
        if rects[i][0] == rect and rects[i][1] == h and rects[i][2] == w:
            H,W = rects[i+1][1:]
            print(H,W)

Solution (Python):
def dia(r):
	return r[0]**2 + r[1]**2 
def issmaller (a,b):
 	if dia(a) != dia(b):
		return dia(a) < dia(b)
	else :
		return a[0] < b[0]

while 1 :
	h, w = map(int,raw_input().split())
	if (h, w) == (0,0):
		break
	dia_base = (h, w)
	rect = (149,150) if h + 1 == w else (h+1,w) 
	winc = w + 1
	hinc = winc
	while hinc > 1:
		for hinc in xrange(1,winc):
			if issmaller(dia_base, (hinc, winc)):
				if issmaller((hinc,winc),rect):
					rect = (hinc,winc)
				break
		winc += 1

	winc = w - 1
	hinc = winc
	while hinc > 1:
		for hinc in xrange(1, winc):
			if issmaller((winc-hinc,winc),dia_base):
				break
			if issmaller((winc-hinc,winc),rect):
				rect = (winc-hinc,winc)
		winc -= 1
	
	print rect[0], rect[1]

Solution (Python):
import itertools
S=[]
for i in range(1,150):
    for j in range(1,i):
        S.append((i*i+j*j,j,i))
S.sort()
while True:
    h,w=map(int, input().split())
    if h==0 and w==0:
        exit()
    s = S[S.index((w*w+h*h,h,w))+1]
    print(s[1],s[2])

Solution (Python):

class T:
	def __init__(self, h, w):
		self.h = h
		self.w = w
		self.d = w*w + h*h
	def __lt__(self, other):
		return (self.d < other.d) or ((self.d == other.d) and self.h < other.h)
	def __gt__(self, other):
		return (self.d > other.d) or ((self.d == other.d) and self.h > other.h)

t = []
for i in range(1, 151):
	for j in range(i+1, 151):
		t.append(T(i, j))
t = sorted(t)

while True:
	h, w = map(int, input().split())
	if (h, w) == (0, 0):
		break
	hw = T(h, w)
	for i in range(len(t)):
		if hw < t[i]:
			print('{} {}'.format(t[i].h, t[i].w))
			break

Solution (Python):
from bisect import bisect_right

rectangles = [(h ** 2 + w ** 2, h, w) for h in range(1, 151) for w in range(1, 151) if h < w]
rectangles.sort()

while True:
    h, w = map(int, input().split())
    if not h and not w:
        break

    gt_rectangle = rectangles[bisect_right(rectangles, (h ** 2 + w ** 2, h, w))]
    print(gt_rectangle[1], gt_rectangle[2])

Solution (Python):
import sys
import math

def f(h,w):
    r = h**2 + w**2
    ary = []
    for hi in range(1,150+1):
        for wi in range(hi+1,150+1):
            ss = hi**2+wi**2
            if ss == r and hi>h:
                ary.append({
                    "ss": ss
                    ,"h": hi
                    ,"w": wi
                })
            elif ss > r:
                ary.append({
                    "ss": ss
                    ,"h": hi
                    ,"w": wi
                })
    mino = ary[0]
    for i,o in enumerate(ary):
        if mino["ss"]>o["ss"]:
            mino = o
        elif mino["ss"]==o["ss"] and mino["h"]>o["h"]:
            mino = o
    return (mino["h"],mino["w"])

while True:
    line = sys.stdin.readline()
    line = line.split(" ")

    h = int(line[0])
    w = int(line[1])

    if h==0 and w==0:
        break

    ret = f(h,w)
    print(str(ret[0])+" "+str(ret[1]))

Solution (Python):
import heapq
q = []

for i in xrange(1, 1001):
  for j in xrange(i+1, 1001):
    heapq.heappush(q, (i**2+j**2, (i,j)))
q = sorted(q)

while True:
  h,w = map(int, raw_input().split())
  if h==w==0: break
  for i in xrange(len(q)):
    if q[i][1] == (h, w):
      index = i
  print "%d %d" % (q[index+1][1][0], q[index+1][1][1])

Solution (Python):
l = []
for i in range(1,151):
    for j in range(1,151):
        if i==j or i>j: continue
        l += [[i**2+j**2,i,j]]
l = sorted(l)
while True:
    h,w = map(int,input().split())
    if w==h==0: break
    i = l.index([w**2+h**2,h,w])+1
    print(*l[i][1:],sep=' ')

Solution (Python):
l = [[i**2+j**2,i,j] for j in range(1,151) for i in range(1,151) if i!=j and i<j]
l = sorted(l)
while True:
    h,w = map(int,input().split())
    if w==h==0: break
    i = l.index([w**2+h**2,h,w])+1
    print(*l[i][1:],sep=' ')

Solution (Python):
import bisect
l = [[i**2+j**2,i,j] for j in range(1,151) for i in range(1,151) if i!=j and i<j]
l.sort()
while True:
    h,w = map(int,input().split())
    if w==h==0: break
    r = l[bisect.bisect_right(l,[w**2+h**2,h,w])]
    print(r[1],r[2])

Solution (Python):
def f(h,w):
    s=h*h+w*w
    h+=1
    while 1:
        while h*h<s:
            w=h+1
            while h*h+w*w<=s:
                if h*h+w*w==s:print(h,w);return
                w+=1
            h+=1
        s+=1;h=1
while 1:
    h,w=map(int,input().split())
    if h==0:break
    f(h,w)

Solution (Python):
import bisect
l = sorted([[i**2+j**2,i,j] for j in range(1,150) for i in range(1,150) if i<j and i!=j])
while True:
    h,w = map(int,input().split())
    if h==w==0: break
    rh,rw = l[bisect.bisect_right(l, [h**2+w**2,h,w])][1:]
    print(rh,rw)

Solution (Python):
import sys
from math import sqrt

inf = 1<<30

def solve():
    while 1:
        h, w = map(int, sys.stdin.readline().split())

        if h == w == 0:
            return

        L = h**2 + w**2
        maxL = inf
        ansx = inf
        ansy = inf

        for x in range(1, L):
            if L - x**2 < 0:
                break

            y = nibutan(L - x**2)

            if y <= x:
                break

            if x**2 + y**2 == L:
                if h < x:
                    ansx = x
                    ansy = y
                    break
                else:
                    y += 1

            if x**2 + y**2 < maxL:
                maxL = x**2 + y**2
                ansx = x
                ansy = y

        print(ansx, ansy)

def nibutan(a):
    top = inf
    btm = 0

    while top - btm > 1:
        mid = (top + btm) // 2

        if mid**2 >= a:
            top = mid
        else:
            btm = mid

    return top

if __name__ == '__main__':
    solve()

Solution (Python):
import sys
from math import sqrt

inf = 1<<30

def solve():
    while 1:
        h, w = map(int, sys.stdin.readline().split())

        if h == w == 0:
            return

        L = h**2 + w**2

        ansx, ansy = zentansaku(h, w, L)

        print(ansx, ansy)

def zentansaku(h, w, L):
    ansx = ansy = maxL = inf

    for x in range(1, 150 + 1):
            for y in range(x + 1, 150 + 1):
                if x**2 + y**2 == L:
                    if h < x:
                        return x, y
                elif L < x**2 + y**2 < maxL:
                    maxL = x**2 + y**2
                    ansx = x
                    ansy = y

    return ansx, ansy

if __name__ == '__main__':
    solve()

Solution (Python):
def compare(h,w):
    hw=h**2+w**2

    tmp_h=150
    tmp_w=150
    tmp_hw=150**2+150**2

    for j in range(1,150):
        for i in range(1,j):
            ij=i**2+j**2
            if (hw < ij) or (hw == ij and h < i) : 
                
                if  (tmp_hw > ij) or (tmp_hw == ij and tmp_h > i):
                    
                    tmp_h=i
                    tmp_w=j
                    tmp_hw=ij

    print(tmp_h,tmp_w)


import sys

for line in sys.stdin:
    h,w=map(int,line.split())
    if h!=0 and w!=0:
        compare(h,w)

Solution (Python):
A=[(j,i)for i in range(150)for j in range(1,i)]
A.sort(key=lambda(j,i):(i**2+j**2,j,i))
while 1:
 h,w=map(int,raw_input().split())
 if h<1:break
 h,w=A[A.index((h,w))+1];print h,w

Solution (Python):
while True:
    H,W = map(int,input().split())
    if H == 0: break
    d0 = H*H + W*W
    ans = (10**9,H,W)
    for w in range(2,151):
        for h in range(1,w):
            d = h*h + w*w
            if (d,h,w) < (d0,H,W) or (h,w) == (H,W): continue
            ans = min(ans, (d,h,w))
            break
    print('{0} {1}'.format(ans[1], ans[2]))

Solution (Python):
def intRec(h,w):
    diag=h**2+w**2
    minD=1e8
    ans=[]
    for H in range(1,151):
        for W in range(1,151):
            if H<W:
                Diag=H**2+W**2
                if diag==Diag and H>h:
                    return [H,W]
                elif diag<Diag and Diag<minD:
                    minD=Diag
                    ans=[H,W]
    return ans

if __name__=="__main__":
    while True:
        h,w=map(int,input().split())
        if h==0:
            break
        ans=intRec(h,w)
        print(ans[0],ans[1])

Solution (Python):
from math import ceil

while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break

    ha, wa = 150, 150
    dia = h**2 + w**2
    for hi in range(1, 150):
        wi = ceil((dia - hi ** 2) ** (1 / 2))

        if hi >= wi:
            break

        if dia == hi**2 + wi**2:
            if hi <= h:
                wi += 1

        if ha**2 + wa**2 > hi**2 + wi**2:
            ha, wa = hi, wi

    print(ha, wa)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []
    t = []
    for i in range(1,151):
        for j in range(i+1,151):
            t.append((i**2+j**2, (i,j)))
    t.sort()
    tt = list(map(lambda x: x[1], t))

    while True:
        h,w = LI()
        if h == 0:
            break
        i = tt.index((h,w))
        r = tt[i+1]

        rr.append(' '.join(map(str,r)))

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
lst = [(i**2+j**2,i,j) for i in range(1,201) for j in range(i+1,201)]
lst.sort(key = lambda x:(x[0],x[1]))
while True:
	a,b = map(int,input().split(" "))
	if a == 0 and b == 0:
		break
	else:
		obj = a**2 + b**2
		for i in range(40000):
			if lst[i] == (obj,a,b):
				print(lst[i+1][1],lst[i+1][2])
				break

Solution (Python):
d={(i,j):(i**2+j**2)**(0.5) for i in range(1,151) for j in range(1,151) if i<j}
r=sorted(d.items(),key=lambda x:x[1])

while 1:
    h,w=map(int,input().split())
    if not h and not w:break
    idx=[i for (i,j) in enumerate(r) if j[0]==(h,w)][0]
    H,W=r[idx+1][0]
    print(H,W)

Solution (Python):
L=[]
for h in range(1,150):
    for	w in range(h+1,151):
	L.append((h*h+w*w,h,w))
L.sort()
while True:
    h,w=map(int,raw_input().split())
    if h==w==0:break
    d=h*h+w*w
    for dd,dh,dw in L:
	if dd==d and dh>h:
            print dh,dw
            break
	elif dd>d:
            print dh,dw
            break

Solution (Python):
S = []
for i in range(1,100):
	for j in range(i+1,151):
		S.append([i,j])
S = sorted(S, key = lambda x:x[0]**2 + x[1]**2)
while 1:
	h,w = map(int,raw_input().split())
	if h == 0: break
	hi,wi = S[S.index([h,w])+1]
	print hi,wi

Solution (Python):
S = sorted([[i,j] for i in range(1,100) for j in range(i+1,151)], key = lambda x:x[0]**2+x[1]**2)
while 1:
	h,w = map(int,raw_input().split())
	if h == 0: break
	hi,wi = S[S.index([h,w])+1]
	print hi,wi

Solution (Python):
a = []
for w in range(2, 201):
    for h in range(1, w):
        a.append([h**2+w**2, h, w])
a.sort()

while 1:
    h,w = map(int,input().split())
    if h == 0: break
    
    ans = a[a.index([h**2+w**2,h,w])+1]
    print(ans[1], ans[2])

Solution (Python):
from sys import exit, stderr, stdin
input = stdin.readline


def debug(var, name="hoge"):
    print(str(type(var)) + name +":" + " = " + repr(var), file=stderr)
    return

class Tri:

    def __init__(self, h, w):
        self.h = h
        self.w = w
        self.diag = h**2 + w**2

    def __lt__(t1, t2):
        if t1.diag < t2.diag:
            return True
        elif t1.diag > t2.diag:
            return False
        else:
            return t1.h < t2.h

    def __repr__(self):
        return str(self.h) +" " + str(self.w)

    def __str__(self):
        return 0

def main():
    while(1):
        H, W = list(map(int, input().split()))
        if (H + W == 0):
            break
        diag = H**2 + W**2
        tris = []
        for h in range(1, 150):
            for w in range(h+1, 150):
                tris.append((Tri(h,w), h==H and w==W))
        
        
        tris = sorted(tris, key=lambda x:x[0])
        
        
        
        for i in range(len(tris)):
            if tris[i][1] == True:
                print(tris[i+1][0].h, tris[i+1][0].w)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline

cheat = []
len_ = 0
for w in range(1, 151):
    for h in range(1, w):
        cheat.append((w**2+h**2, h, w))
        len_ += 1
cheat = sorted(cheat, key=lambda x:(x[0], x[1]))

while True:
    h, w = map(int, input().split())
    if h == 0:
        break
    L = h**2 + w**2
    for i in range(len_):
        if cheat[i][0] == L:
            if cheat[i][1] > h:
                print(cheat[i][1], cheat[i][2])
                break
        elif cheat[i][0] > L:
            print(cheat[i][1], cheat[i][2])
            break

Solution (Python):
poly = []
for w in range(2,150):
	for h in range(1,w):
		poly.append((w*w+h*h,h,w))
poly.sort()

while True:
	h,w = map(int,input().split())
	if h + w == 0:
		break
	a = poly.index((w*w+h*h,h,w))
	print(poly[a+1][1],poly[a+1][2])

Solution (Python):
from inspect import currentframe


def debug_print(s):
    
    return


def debug_key(*args):
    names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    debug_print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))


def solve(h, w):
    debug_print("\n-----solve-----")

    if h == 0:
        return 
    d0 = h * h + w * w
    ans = (10 ** 9, h, w)
    for w in range(2, 151):
        for heisght in range(1, w):
            d = heisght * heisght + w * w
            if (d, heisght, w) < (d0, h, w) or (heisght, w) == (h, w):
                continue
            ans = min(ans, (d, heisght, w))
            break
    print('{0} {1}'.format(ans[1], ans[2]))

    return


if __name__ == '__main__':

    while True:
        h_input, w_imput = map(int, input().split())
        if h_input == w_imput == 0:
            break
        solve(h_input, w_imput)

Solution (Python):
while True:

    H, W = [int(i) for i in input().split()]

    if H == 0:
        break

    min_h = 10 ** 8
    min_w = 10 ** 8
    a = H ** 2 + W ** 2

    for w in range(1, 151):
        for h in range(1, w):
            d = w ** 2 + h ** 2
            e = min_h ** 2 + min_w ** 2
            if d < a:
                continue
            if d == a and h <= H:
                continue

            if d < e:
                min_h = h
                min_w = w
            elif d == e and h < min_h:
                min_h = h
                min_w = w

    print(min_h, min_w)

Solution (Python):
def main(h,w):
    a = h * h + w * w
    ans = []
    for x in range(1,151):
        for y in range(x+1,151):
            if a <= x ** 2 + y ** 2:
                b = x ** 2 + y ** 2
                ans.append((b, x, y))
    ans.sort()
    for b, x, y in ans:
        if a < b or x > h:
            ans = [x, y]
            break
    print(" ".join(list(map(str,ans))))
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    main(h,w)

Solution (Python):
def hypot2(x, y):
    return x**2 + y**2


while True:
    h, w = map(int, input().split())
    if h == 0:
        exit()
    lb = hypot2(h, w)
    ans = []
    for y in range(1, 151):
        for x in range(y + 1, 151):
            if lb < hypot2(x, y) or (lb == hypot2(x, y) and h < y):
                ans.append([hypot2(x, y), y, x])
    d, h, w = sorted(ans)[0]
    print(h, w)

Solution (Python):
while True:
    H, W = map(int, input().split())
    if H == 0:
        break
    original_diagonal = H**2 + W**2

    ans_h = 200
    ans_w = 200
    ans_diagnal = 200000000

    for i in range(1, 150):
        for j in range(i+1, 150):
            new_diagonal = i**2 + j**2
            if original_diagonal > new_diagonal or (original_diagonal == new_diagonal and i <= H):
                continue
            if (new_diagonal < ans_diagnal) or (new_diagonal == ans_diagnal and i < ans_h):
                ans_h = i
                ans_w = j
                ans_diagnal = new_diagonal

    print(ans_h, ans_w)

Solution (Python):
H,W = 150,150
dp = [[0 for w in range(W+1)] for h in range(H+1)]
for h in range(1,H+1):
  for w in range(1,W+1):
    if h<w:
      dp[h][w] = h*h + w*w
while True:
  h,w = map(int,input().split())
  if h+w==0:
    break
  
  l = dp[h][w]
  a,b = h,w
  for i in range(1,H+1):
    for j in range(1,W+1):
      if dp[i][j]==l and a<i:
        a,b = i,j
        break
    if a!=h or b!=w:
      break
  if a!=h or b!=w:
    print(a,b)
  else:
    m = 10**10
    for i in range(1,H+1):
      for j in range(1,W+1):
        if dp[i][j]>l and dp[i][j]<m:
          m = dp[i][j]
          a,b = i,j
    print(a,b)

Solution (Python):
X=[]
while(True):
    h,w=map(int,input().split())
    if (h,w)==(0,0):
        break
    else:
        X.append((h,w))
Y=[]
N=200
for h in range(1,N+1):
    for w in range(h+1,N+1):
        Y.append((h*h+w*w,min(h,w),h,w))
Y.sort()
Z=[[-1 for i in range(N+1)] for j in range(N+1)]
for i in range(len(Y)):
    p,q,r,s=Y[i]
    Z[r][s]=i

for seq in X:
    h,w=seq
    x,y,a,b=Y[Z[h][w]+1]
    print(a,b)

Solution (Python):
import math
while True:
    h,w=map(int,input().split())
    if w==0 and h==0:
        break
    tikk=w*w+h*h
    
    min=151*151
    minw=0
    minh=0
    for ih in reversed(range(1,int(math.sqrt(tikk))+2)):
        for iw in reversed(range(ih+1,int(math.sqrt(tikk))+2)):
            itikk=iw*iw+ih*ih
            if tikk>itikk:
                continue
            if itikk<=min and (iw!=w or ih!=h):
                if itikk==tikk and ih<h:
                    continue
                min=itikk
                minw=iw
                minh=ih
    print("{} {}".format(minh,minw))

Solution (Python):
def main():
    while True:
        h, w = map(int, input().split(" "))
        if h == 0: break
        
        initOblSq = OblSq(w, h)
        minOblSq = OblSq(149, 149)
        minw = 149
        minh = 149
        for varw in range(1, 150):
            for varh in range(1, varw):
                varsq = OblSq(varw, varh)
                if varsq >= initOblSq and varsq <= minOblSq:
                    if varsq == initOblSq and varh <= h: continue
                    if varsq == minOblSq and varh >= minh: continue
                    minOblSq = varsq
                    minw = varw
                    minh = varh
        
        print(minh, minw)

def OblSq(width, height):
    return width**2 + height**2

main()

Solution (Python):
while 1:
    h,w=map(int,input().split())
    if h==w==0:break
    r=h**2+w**2
    d_m=float("inf")
    ax,ay=0,0
    for x in range(1,int(r**0.5)+2):
        y=int([(r-x**2),0][(r-x**2)<0]**0.5)
        y+=[1,0][r==x**2+y**2 and h<x]
        if x>=y:continue
        dia=x**2+y**2
        if d_m>dia:d_m,ax,ay=dia,x,y
    print(ax,ay)

Solution (Python):
lst = []
for h in range(1, 151):
    for w in range(h + 1, 151):
        lst.append((h ** 2 + w ** 2, h, w))
lst.sort()
while True:
    h, w = map(int, input().split())
    if h == 0:break
    ind = lst.index((h ** 2 + w ** 2, h, w))
    print(*lst[ind + 1][1:])

Solution (Python):
t = [(i * i + j * j, (i, j)) for i in range(1, 151) for j in range(i + 1, 151)]
t.sort()
d = {a[1]: b[1] for a, b in zip(t, t[1:])}
res = []
for e in iter(input, '0 0'):
    h, w = map(int, e.split())
    ans = d[h, w]
    res.append(' '.join(map(str, ans)))
print('\n'.join(map(str, res)))

Solution (Python):

data={}
for i in range(1,151):
    for j in range(1,151):
        if (i>j):
            data[(i,j)]=i*i+j*j
data=sorted(data.items(),key=lambda x:(x[1],x[0][1]))
while 1:
    n,m=map(int,input().split())
    if n==0:
        break
    for i in range(len(data)):
        if data[i][0]==(m,n):
            print(*data[i+1][0][::-1])
            break

Solution (Python):
a_list = []
for i in range(1, 151):
    for j in range(1, 151):
        tmp_list = []
        tmp_list.append(i**2+j**2)
        tmp_list.append(i)
        tmp_list.append(j)
        a_list.append(tmp_list)

a_list.sort()
while(True):
    n = input()
    n = n.split()
    h = int(n[0])
    w = int(n[1])
    flag = 0

    if h==0 and w==0:
        break
    a = h**2 + w**2
    for i in range(len(a_list)):
        if a == a_list[i][0] and flag==0:
            if h < a_list[i][1] and a_list[i][1] < a_list[i][2]:
                print(str(a_list[i][1])+" "+str(a_list[i][2]))
                flag = 1
        elif a < a_list[i][0] and flag==0:
            if a_list[i][1] < a_list[i][2]:
                print(str(a_list[i][1]) + " " + str(a_list[i][2]))
                flag = 1