Jumbled Compass

Given two compass directions from 0 to 359, print the signed rotation with the smallest magnitude that moves the needle from the first direction to the second, breaking ties toward clockwise.

Easy2MathImplementationBrute forceInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Jonas is developing the JUxtaPhone and is tasked with animating the compass needle. The API is simple: the compass needle is currently in some direction (between 0 and 359 degrees, with north being 0 and east being 90), and it is animated by giving it the number of degrees to spin. If the needle points north and you give the compass an input of 90, it spins clockwise (positive numbers mean the clockwise direction) and stops at east, whereas an input of -45 spins it counter-clockwise and stops at north west.

The compass reports the direction the phone currently points, and Jonas has to animate the needle along the shortest path from the current needle direction to the correct direction. Many ifs, moduli, and even an arctangent later, he is still not convinced his minimumDistance function is correct, so he calls you on the phone.

Input

The first line contains an integer n1n_1 (0n13590 \le n_1 \le 359), the current direction of the needle.

The second line contains an integer n2n_2 (0n23590 \le n_2 \le 359), the correct direction of the needle.

Output

Print the change in direction that makes the needle spin the shortest distance from n1n_1 to n2n_2. A positive change means spinning the needle clockwise, and a negative change means spinning it counter-clockwise.

If the two input numbers are diametrically opposed, the needle travels clockwise. That is, in this case print 180 rather than -180.