#C7200. Maximum Angular Difference
Maximum Angular Difference
Maximum Angular Difference
You are given several datasets representing angular positions on a circle. For each dataset, the first line contains an integer n representing the number of angles. The following line contains n integers, representing angles (in degrees) on a circle. The datasets are terminated by a dataset where n = 0 (which should not be processed).
For each dataset, compute the maximum angular difference between any two consecutive angles on the circle, where the angular difference between two angles a and b is defined as
[ \Delta = \min(|a - b|, 360 - |a - b|) ]
Print each result on a separate line.
Note: When there is only one angle, the maximum angular difference is considered to be 0.
inputFormat
The input consists of multiple datasets. Each dataset is given in two lines:
- The first line contains an integer n (1 ≤ n ≤ 360) or 0 to terminate input.
- If n > 0, the second line contains n space-separated integers representing angles (in degrees) where 0 ≤ angle ≤ 360.
The input terminates with a line containing a single 0.
outputFormat
For each dataset, output a single integer representing the maximum angular difference (in degrees) between any two consecutive angles (taking into account the circular nature of the circle), each in its own line.
## sample5
10 20 70 150 300
4
0 90 180 270
3
0 10 350
0
150
90
20
</p>