Three rectangles

5

2 votes
Algorithms, Basics of Greedy Algorithms, Greedy Algorithms
Problem

You are given a rectangle of height H and width W. You must divide this rectangle exactly into three pieces such that each piece is a rectangle of integral height and width. You are required to minimize AreamaxAreamin where Areamax is the area of the largest rectangle and Areamin is the area of the smallest rectangle, among all three rectangle pieces.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains two space-separated integers H and W denoting the height and width of the rectangle.

Output format

For each test case, print the minimum possible value of AreamaxAreamin in a new line.

Constraints

1T10002H,W200000

  • It is guaranteed that the sum of H over T test cases does not exceed 1e6.
  • It is guaranteed that the sum of W over T test cases does not exceed 1e6.
Sample Input
2
3 4
2 2
Sample Output
0
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For both the test cases, the division is shown below:

For the first testcase AreamaxAreamin = 44=0.

For the first testcase AreamaxAreamin = 21=1.

Editor Image

?