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 in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    class Shape
    {
        public int w;
        public int h;
        public double diag2;
        public Shape(int hh, int ww, double d)
        {
            h = hh;
            w = ww;
            diag2 = d;
        }
    }
    

    class Program
    {

        
        static void Main(string[] args)
        {

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int h = int.Parse(input[0]);
                int w = int.Parse(input[1]);

                if (h == 0 && w == 0)
                {
                    break;
                }

                int ans_h = 0;
                int ans_w = 0;
                double origin_diag2 = h * h + w * w;

                List<Shape> diag_list = new List<Shape>();

                for(int n_h = 1; n_h <= 148; n_h++)
                {
                    for(int n_w = n_h + 1; n_w <= 149; n_w++)
                    {
                        double n_diag2 = Math.Pow(n_h, 2) + Math.Pow(n_w, 2);
                        if(n_diag2 > origin_diag2)
                        {
                            diag_list.Add(new Shape(n_h, n_w, n_diag2));
                        }      
                        else if(n_diag2 == origin_diag2 && n_h > h)
                        {
                            diag_list.Add(new Shape(n_h, n_w, n_diag2));
                        }
                    }
                }

                var diag_list_sort = diag_list.OrderBy(x => x.diag2).ToList();

                ans_h = diag_list_sort[0].h;
                ans_w = diag_list_sort[0].w;
              
                Console.WriteLine($"{ans_h} {ans_w}");

            }
            
        }
    }
}