Three rectangles
59% Success944 Attempts30 Points1s Time Limit256MB Memory1024 KB Max Code

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 \(Area_{max}-Area_{min}\) where \(Area_{max}\) is the area of the largest rectangle and \(Area_{min}\) 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 \(Area_{max}-Area_{min}\) in a new line.

Constraints

\(1 \le T \le 1000\)
\(2 \le H,W \le 200000\)

  • 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$$.
Examples
Input
2
3 4
2 2
Output
0
1
Explanation

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

For the first testcase $$Area_{max}-Area_{min}$$ = $$4-4=0$$.

For the first testcase $$Area_{max}-Area_{min}$$ = $$2-1=1$$.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...
Results