Compute the winding number The winding number is the integer number of net counterclockwise revolutions an observer must have made to follow a given closed path. Note that any clockwise revolutions count negative towards the winding number. The path is allowed to self intersect.

Some examples (shamelessly taken from Wikipedia) are given below:



Your goal is to compute the winding number for a given path.

Input

The observer is assumed be at the origin (0,0).

The input is a finite sequence of points (pair-like of integer numbers) from any desired input source which describes the piece-wise linear path. You may flatten this into a 1D sequence of integer numbers if desired, and may also swizzle the input to take all x coordinates before all y coordinates/vise-versa. You may also take the input as a complex number a+b i. The path may self intersect and may contain zero-length segments. The first point is the start of the path and is assumed to lie somewhere on the positive x axis.

No part of the path will intersect the origin. The path will always be closed (i.e. the first and lost point are the same). Your code may either imply the last point or require it to be included.

For example, depending on your preference both inputs specify the same square:

implied end point

1,0
1,1
-1,1
-1,-1
1,-1


explicit end point

1,0
1,1
-1,1
-1,-1
1,-1
1,0


Output

The output is a single integer for the winding number. This may be to any source (return value, stdout, file, etc.).

Examples

All examples have the end point explicitly defined and are given as x,y pairs. Incidentally, you should be able to also directly feed these examples into any codes assuming implicitly defined end points and the outputs should be the same.

1. Basic test

1,0
1,1
-1,1
-1,-1
1,-1
1,0


Output

1


2. Repeated point test

1,0
1,0
1,1
1,1
-1,1
-1,1
-1,-1
-1,-1
1,-1
1,-1
1,0


Output

1


3. Clockwise test

1,0
1,-1
-1,-1
-1,1
1,1
1,0


Output

-1


4. Outside test

1,0
1,1
2,1
1,0


Output

0


5. Mixed winding

1,0
1,1
-1,1
-1,-1
1,-1
1,0
1,-1
-1,-1
-1,1
1,1
1,0
1,1
-1,1
-1,-1
1,-1
1,0
1,1
-1,1
-1,-1
1,-1
1,0


Output

2


Scoring

This is code golf; shortest code wins. Standard loopholes apply. You may use any builtin functions so long as they were not specifically designed to compute the winding number.
ES6, 83 bytes

a=&gt;a.map(([x,y])=&gt;r+=Math.atan2(y*b-x*c,y*c+x*b,b=x,c=y),b=c=r=0)&amp;&amp;r/Math.PI/2


Takes as input an array of pairs of points which are interpreted as complex numbers. Rather than converting each point into an angle, the points are divided by the previous point, which Math.atan2 then converts into an angle between -π and π, thus automatically determining which way the path is winding. The sum of the angles is then 2π times the winding number.

Since Math.atan2 doesn't care about the scale of its arguments I don't actually perform the full division z / w = (z * w*) / (w * w*) instead I just multiply each point by the complex conjugate of the previous point.

Edit: Saved 4 bytes thanks to @edc65.