A Tale of Three Squares

All submissions for this problem are available.
There are three squares, each with side length a placed on the xaxis. The coordinates of centers of these squares are (x_{1}, a/2), (x_{2}, a/2) and (x_{3}, a/2) respectively. All of them are placed with one of their sides resting on the xaxis.
You are allowed to move the centers of each of these squares along the xaxis (either to the left or to the right) by a distance of at most K. Find the maximum possible area of intersections of all these three squares that you can achieve. That is, the maximum area of the region which is part of all the three squares in the final configuration.
Input
 The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
 The first line of each test case contains two spaceseparated integers a, K denoting side length of the squares, and the maximum distance that you can move the center of any square.
 The second line contains three space separated integers x_{1}, x_{2}, x_{3}
Output
For each test case, output a real number corresponding to the maximum area of the intersection of the three squares that you can obtain. Your answer will be considered correct if it has an absolute error of less than or equal to 10^{2}.
Constraints
 1 ≤ T ≤ 10^{5}
 1 ≤ a ≤ 10^{5}
 0 ≤ K ≤ 10^{6}
 10^{6} ≤ x_{1}, x_{2}, x_{3} ≤ 10^{6}
Example
Input 3 1 0 1 2 3 1 1 1 2 3 1 1 1 4 6 Output 0.000000 1.0000 0.0
Explanation
Testcase 1: The figure below shows the three squares:
Since K = 0, they cannot be moved, and since there is no region which belongs to all three squares, the answer is 0.
Testcase 2: The starting configuration is the same as above, but now each of the squares can move 1 unit. So we can move the first square 1 unit to the right and the third square one unit to the left, and have all the three squares at xcoordinate = 2. Thus the entire square is part of all three squares, and the answer is 1.
Author:  admin2 
Tags  admin2, gwr17rol, simple 
Date Added:  19122017 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 