You are given a pile of n identical disks stacked on top of each other with their centers aligned vertically. Each disk has a hole at a certain radius from the center. A disk can have multiple holes on it but no two holes are at the same distance from the center. You can rotate the disks in either clockwise or anticlockwise direction but the cost to rotate it by d degrees is d (d can be any positive real number). Each disk can be rotated independently of each other. Determine the minimum cost to rotate the disks in such a way that at least one of the holes is aligned from the top to the bottom of the pile of disks (that is, all the holes should be at the same radial angle).
Note:
Input format
Output format
Print the minimum cost to align one of the holes from the top disk to the bottom disk of the pile. If it is not possible to align any hole, print −1. If the absolute difference between the output and the correct answer is ≤10−6, the output will be considered correct.
Input Constraints
1≤n≤200000
0<ri≤109
0.0≤di<360.0
0≤n∑i=1 hi≤106
All the holes are at same radius.The cost to align all holes is minimum if all the holes are aligned at 5 degrees (by rotating disks 2 and 3 in clockwise direction by 2 and 4 degrees respectively and disk 4 in anticlockwise direction by 6 degrees).