We want to place each of the problems into exactly one of Div.3, Div.2, and Div.1. Each Div must contain at least one problem.
The difficulty of problem is . If is E, it is an easy problem and can be placed only in Div.3 or Div.2. If is H, it is a hard problem and can be placed only in Div.2 or Div.1. Whether a problem is easy or hard is unrelated to its difficulty. There is no condition on the relative difficulties between Divs.
The width of a Div is the maximum difficulty of the problems placed in it minus the minimum difficulty. If it contains only one problem, its width is .
Minimize the maximum of the widths of the three Divs. If no valid placement exists, output -1.
The input is given in the following format.
For each test case, output the minimum possible value of the maximum of the widths of the three Divs on a single line.
If it is impossible, output -1.
Each test case is given in the following format.
| 3 | 16 | For all such that and , . |
| 4 | 22 | . |
| 5 | 43 | No additional constraints. |