Under construction

Still being built. Things may change

Picking a device for the movie

Time limit1sMemory limit128 MB

Summary
Given a movie resolution, pick the cheapest of eight listed devices that maximizes the full-screen usage ratio in either orientation.
Level

Easy3 of 10

Topics
Simulation, Math, Implementation
Solved
No attempts yet

Problem

The movie "Last ACM Contest" came out recently and set the record for the highest worldwide gross. Gabby was busy practicing for the ICPC contest at the Tehran site, so he never got to watch it in a cinema. On 20 December 2013, the day of the contest, he legally downloaded the movie to watch it on a smart phone or a tablet on his way home from Sharif University. The trouble is that he owns neither a smart phone nor a tablet, so he decided to buy one of the following devices sold in the market.

DevicePriceResolution
iPad Mini3191024 × 768
Galaxy Tab4191024 × 600
iPhone 4S450960 × 640
iPad45192048 × 1536
iPhone 5C5991136 × 640
Galaxy Tab26001280 × 800
Galaxy S46301080 × 1920
iPhone 5S7191136 × 640

Each device has a fixed "height × width" resolution, the number of distinct pixels it can show in each dimension. A movie also has a fixed resolution H × W. A video player scales both dimensions of the movie by the same factor c and draws the movie in a window of size [cH] × [cW], where [x] is the largest integer not greater than x and c is a rational number such that cH is not greater than the height resolution of the display and cW is not greater than its width resolution. In other words, the player zooms the movie in or out while keeping its aspect ratio (the ratio of the height resolution to the width resolution). A full-screen window uses the largest c that satisfies those two bounds.

When a player shows a movie in a full-screen window, part of the display can stay blank because the display and the movie have different aspect ratios. Given a movie resolution and a display resolution, the usage ratio is the area the movie actually covers in the full-screen player window divided by the area of the whole display. Every device above can rotate its screen by 90 degrees, which can raise the usage ratio for a movie. For example, if the movie resolution is 720 × 480, the usage ratio of iPad4 is the larger of (2048 × 1365) / (2048 × 1536) and (1536 × 1024) / (1536 × 2048), which is 1365 / 1536. The second value comes from rotating the screen by 90 degrees.

Gabby wants the device with the highest usage ratio for "Last ACM Contest", which is stored with resolution H × W. Tell him which device that is before the contest ends.

Input

The input holds several test cases. Each test case is one line with two integers H and W (1 ≤ H, W ≤ 5000), the resolution of "Last ACM Contest". The last line of the input is 0 0 and is not processed.

Output

For each test case, print one line with the price of the device that has the highest usage ratio for the given movie resolution. If several devices share the highest usage ratio, print the smallest of their prices. For example, if iPad4 and iPad Mini both have the highest usage ratio, print 319.

Examples1

  1. Example 1

    Input
    720 480
    640 320
    800 600
    2500 2500
    0 0
    
    Expected output
    450
    630
    319
    319