Maria participates in a bicycle race.

The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.

Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).

Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.

Help Maria get ready for the competition — determine the number of dangerous turns on the track.


-----Input-----

The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track.

The following (n + 1)-th line contains pairs of integers (x_{i}, y_{i}) ( - 10 000 ≤ x_{i}, y_{i} ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (x_{i}, y_{i}) and ends at the point (x_{i} + 1, y_{i} + 1).

It is guaranteed that:

  the first straight section is directed to the north;  the southernmost (and if there are several, then the most western of among them) point of the track is the first point;  the last point coincides with the first one (i.e., the start position);  any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point);  no pair of points (except for the first and last one) is the same;  no two adjacent straight sections are directed in the same direction or in opposite directions. 


-----Output-----

Print a single integer — the number of dangerous turns on the track.


-----Examples-----
Input
6
0 0
0 1
1 1
1 2
2 2
2 0
0 0

Output
1

Input
16
1 1
1 5
3 5
3 7
2 7
2 9
6 9
6 7
5 7
5 3
4 3
4 4
3 4
3 2
5 2
5 1
1 1

Output
6



-----Note-----

The first sample corresponds to the picture:

 [Image] 

The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.

Difficulty: interview

Starter code:

Solutions:
#!/usr/bin/env python3

try:
    while True:
        n = int(input())
        prev_x, prev_y = list(map(int, input().split()))
        prev_d = 0
        result = 0
        for i in range(n):
            x, y = list(map(int, input().split()))
            if y > prev_y:
                d = 0
            elif x > prev_x:
                d = 1
            elif y < prev_y:
                d = 2
            else:
                d = 3
            if ((d + 1) & 0x3) == prev_d:
                result += 1
            prev_x, prev_y = x, y
            prev_d = d
        print(result)

except EOFError:
    pass


def isLeft(x1, y1, x2, y2, x3, y3):
    return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1) < 0


def isMn(s):
    return not (True in s and False in s)

def pr():
    for i in range(1, n - 1):
        s.append(isLeft(x[i - 1], y[i - 1], x[i], y[i], x[i + 1], y[i + 1]))
    s.append(isLeft(x[-1], y[-1], x[0], y[0], x[1], y[1]))
    s.append(isLeft(x[-2], y[-2], x[-1], y[-1], x[0], y[0]))


n = int(input())
x = []
y = []
for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)
s = []
pr()
ans = 0
for i in range(len(s)):
    if not s[i]:
        ans += 1
print(min(ans, len(s) - ans))

n=int(input())
a=[]

tr=0
tl=0

for i in range(0,n+1):
    p=input().split()
    p[0]=int(p[0])
    p[1]=int(p[1])
    a.append(p)
a.append(a[0])

for i in range(0,n):
    x1=a[i+1][0]-a[i][0]
    y1=a[i+1][1]-a[i][1]
    x2=a[i+2][0]-a[i+1][0]
    y2=a[i+2][1]-a[i+1][1]
    if x1>0:
        if y2>0:
            tl+=1
        else:
            tr+=1
    elif x1<0:
        if y2<0:
            tl+=1
        else:
            tr+=1
    elif y1>0:
        if x2<0:
            tl+=1
        else:
            tr+=1
    else:
        if x2>0:
            tl+=1
        else:
            tr+=1

print(str(min(tl,tr)))

    




n = int(input())

p = []
for _ in range(n + 1):
	x, y = map(int, input().split())
	p.append((x, y))

def cp(v1, v2):
	return v1[0] * v2[1] - v1[1] * v2[0]

answer = 0
for i in range(n - 1):
	v1 = (p[i + 1][0] - p[i][0], p[i + 1][1] - p[i][1])
	v2 = (p[i + 2][0] - p[i + 1][0], p[i + 2][1] - p[i + 1][1])
	if cp(v1, v2) > 0:
		answer += 1

print(answer)

n = int(input())
print((n - 4) // 2)


n = int(input())
p1 = tuple(map(int, input().split()))
p2 = tuple(map(int, input().split()))
count = 0

for x in range(n - 1):
    p3 = tuple(map(int, input().split()))
    x1 = p2[0] - p1[0]
    y1 = p2[1] - p1[1]
    x2 = p3[0] - p2[0]
    y2 = p3[1] - p2[1]
    if x1 * y2 > x2 * y1:
        count += 1
    p1 = p2
    p2 = p3

print(count)


n = int(input())
a, b = 0, 0

gi = lambda : list(map(int, input().split(' ')))
u, v = gi()
x, y = gi()
for _ in range(n - 1):
    p, q = gi()
    w = (x - u) * (q - y) - (y - v) * (p - x)
    if w < 0:
        a += 1
    else:
        b += 1
    u, v, x, y = x, y, p, q

print(min(a, b))


n = int(input())
count = 0
points = [tuple(map(int, input().split())), tuple(map(int, input().split()))]
for i in range(2, n + 1):
    x, y = map(int, input().split())
    points.append((x, y))
    if points[i - 1][0] < x:
        temp = 'east'
    if points[i - 1][0] > x:
        temp = 'west'
    if points[i - 1][1] < y:
        temp = 'north'
    if points[i - 1][1] > y:
        temp = 'south'
    x = points[i - 1][0]
    y = points[i - 1][1]
    if points[i - 2][0] < x:
        temp1 = 'east'
    if points[i - 2][0] > x:
        temp1 = 'west'
    if points[i - 2][1] < y:
        temp1 = 'north'
    if points[i - 2][1] > y:
        temp1 = 'south'
    if (temp1, temp) in [('north', 'west'), ('west', 'south'), ('south', 'east'), ('east', 'north')]:
        count += 1
print(count)

n = int(input())
point = [0] * (n + 1)
for i in range(n + 1):
    point[i] = [int(x) for x in input().split()]
v = [0] * n
for i in range(1, n + 1):
    v[i - 1] = [point[i][0] - point[i - 1][0], point[i][1] - point[i - 1][1]]
ans = 0
for i in range(1, n - 1):
    if v[i - 1][0] * v[i][1] - v[i - 1][1] * v[i][0] > 0:
        ans += 1
if v[n - 1][0] * v[0][1] - v[n - 1][1] * v[0][0] > 0:
    ans += 1
print(ans)

#!/usr/bin/env python3

read_ints = lambda : list(map(int, input().split()))

def solve(ps):
    ans = 0
    for i in range(len(ps)-2):
        if ccw(ps[i], ps[i+1], ps[i+2]):
            ans += 1
    return ans

def ccw(p1, p2, p3):
    return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) > 0

def __starting_point():
    n = int(input())
    ps = []
    for i in range(n+1):
        ps.append(read_ints())
    print(solve(ps))

__starting_point()

n = int(input())
data = [list(map(int, input().split())) for i in range(n + 1)]
ans = 0
for i in range(n - 3):
    x0, y0, x1, y1, x2, y2 = data[i][0], data[i][1], data[i + 1][0], data[i + 1][1], data[i + 2][0], data[i + 2][1]
    if y0 == y1 and x1 == x2:
        ans += 1
print(ans)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time


n   = int(input())
x   = []
y   = []

(x0, y0) = (int(i) for i in input().split())

for i in range(n):
    (x1, y1) = (int(i) for i in input().split())
    x.append(x1-x0)
    y.append(y1-y0)
    x0 = x1
    y0 = y1

start = time.time()

ans = 0
for i in range(n-1):
    if x[i]*y[i+1]-x[i+1]*y[i] > 0:
        ans += 1

if x[n-1]*y[0]-x[0]*y[n-1] > 0:
    ans += 1

print(ans)
finish = time.time()
#print(finish - start)


3

class StdIO:
	def read_int(self):
		return int(self.read_string())

	def read_ints(self, sep=None):
		return [int(i) for i in self.read_strings(sep)]

	def read_float(self):
		return float(self.read_string())

	def read_floats(self, sep=None):
		return [float(i) for i in self.read_strings(sep)]

	def read_string(self):
		return input()

	def read_strings(self, sep=None):
		return self.read_string().split(sep)

io = StdIO()


def left(u, v):
	ux, uy = u
	vx, vy = v
	
	z = ux*vy - uy*vx

	return z > 0


def main():
	n = io.read_int()

	x0, y0 = io.read_ints()
	x1, y1 = io.read_ints()

	pv = (x1 - x0, y1 - y0)
	ppx, ppy = x1, y1

	dang = 0
	for i in range(2, n+1):
		px, py = io.read_ints()
		v = (px - ppx, py - ppy)

		if left(pv, v):
			dang += 1

		pv = v
		ppx, ppy = px, py

	print(dang)

def __starting_point():
	main()

__starting_point()

n = int(input())
counter = 0
direction = 0
input()
x_0, y_0 = list(map(int, input().split()))
for i in range(n - 1):
    x_1, y_1 = list(map(int, input().split()))
    if direction == 0:
        if x_1 < x_0:
            counter += 1
    elif direction == 1:
        if y_1 > y_0:
            counter += 1
    elif direction == 2:
        if x_0 < x_1:
            counter += 1
    elif direction == 3:
        if y_1 < y_0:
            counter += 1
    if direction == 0 or direction == 2:
        if x_1 < x_0:
            direction = 3
        else:
            direction = 1
    else:
        if y_1 > y_0:
            direction = 0
        else:
            direction = 2
    x_0, y_0 = x_1, y_1
print(counter)


num = int(input())
track = []
for i in range(num+1):
    temp = list(map(int,input().split()))
    track.append(temp)
def checkDirection(pointOne, pointTwo):
    if pointOne[0] < pointTwo[0]:
        return "E"
    if pointOne[0] > pointTwo[0]:
        return "W"
    if pointOne[1] < pointTwo[1]:
        return "N"
    if pointOne[1] > pointTwo[1]:
        return "S"
def checkDanger(pointOne, pointTwo, pointThree):
    first = checkDirection(pointOne, pointTwo)
    second = checkDirection(pointTwo, pointThree)
    if (first == "W" and second == "S") or (first == "S" and second == "E") or (first == "N" and second == "W") or (first == "E" and second == "N"):
        return True
    else:
        return False
numDanger = 0
for i in range(1,len(track)-1):
    if checkDanger(track[i-1],track[i],track[i+1]):
        numDanger += 1
print(numDanger)

def clock(a, b, c):
    u = b - a
    v = c - b
    return u.real * v.imag - u.imag * v.real < 0


n = int(input())
p = []
for i in range(n + 1):
    x, y = list(map(int, input().split()))
    p.append(complex(x, y))

cnt = 0
for i in range(1, n):
    if not clock(p[i - 1], p[i], p[i + 1]):
        cnt += 1

print(cnt)


read = lambda: list(map(int, input().split()))   
vect = lambda a, b: a[0] * b[1] - a[1] * b[0]
vector = lambda A, B: (B[0] - A[0], B[1] - A[1])
n = int(input())
p = [tuple(read()) for i in range(n)]
cnt = 0
for i in range(2, n):
    v1 = vector(p[i], p[i - 1])
    v2 = vector(p[i - 1], p[i - 2])
    if vect(v1, v2) < 0:
        cnt += 1
print(cnt)


n = int(input())
sx, sy = (int(x) for x in input().split())
ax, ay = sx, sy
bx, by = (int(x) for x in input().split())
cx, cy = (int(x) for x in input().split())

ans = 0

for i in range(n - 3):
  fx = bx - ax
  fy = by - ay
  lx = cx - bx
  ly = cy - by
  if fx != 0: fx = fx/abs(fx)
  if fy != 0: fy = fy/abs(fy)
  if lx != 0: lx = lx/abs(lx)
  if ly != 0: ly = ly/abs(ly)
  if (fy ==  1 and lx == -1): ans += 1
  if (fx ==  1 and ly ==  1): ans += 1
  if (fy == -1 and lx ==  1): ans += 1
  if (fx == -1 and ly == -1): ans += 1


  ax, ay = bx, by
  bx, by = cx, cy
  cx, cy = (int(x) for x in input().split())

fx = bx - ax
fy = by - ay
lx = cx - bx
ly = cy - by
if fx != 0: fx = fx/abs(fx)
if fy != 0: fy = fy/abs(fy)
if lx != 0: lx = lx/abs(lx)
if ly != 0: ly = ly/abs(ly)
if (fy ==  1 and lx == -1): ans += 1
if (fx ==  1 and ly ==  1): ans += 1
if (fy == -1 and lx ==  1): ans += 1
if (fx == -1 and ly == -1): ans += 1


ax, ay = bx, by
bx, by = cx, cy
cx, cy = sx, sy

fx = bx - ax
fy = by - ay
lx = cx - bx
ly = cy - by
if fx != 0: fx = fx/abs(fx)
if fy != 0: fy = fy/abs(fy)
if lx != 0: lx = lx/abs(lx)
if ly != 0: ly = ly/abs(ly)
if (fy ==  1 and lx == -1): ans += 1
if (fx ==  1 and ly ==  1): ans += 1
if (fy == -1 and lx ==  1): ans += 1
if (fx == -1 and ly == -1): ans += 1


print(ans)

def direction(a, b):
    if a[0] == b[0]:
        if a[1] < b[1]:
            return "U"
        return "D"
    if a[0] < b[0]:
        return "R"
    return "L"

def dangerous(a, b):
    if a=="R" and b=="U":
        return True
    if a=="U" and b=="L":
        return True
    if a=="L" and b=="D":
        return True
    if a=="D" and b=="R":
        return True
    return False

n = int(input())+1
l = []
for i in range(n):
    l.append(list(map(int, input().split())))

l1 = []
for i in range(n-1):
    l1.append(direction(l[i],l[i+1]))
ans = 0
for i in range(n-2):
    if dangerous(l1[i],l1[i+1]):
        ans += 1

print(ans)


n = int(input())
points = []
for _ in range(n):
    x, y = map(int, input().split())
    points.append([x, y])
point_count = 0
for i in range(len(points) - 1):
    pre_point = points[i-1]
    point = points[i]
    next_point = points[i+1]
    if pre_point[0] == point[0] and next_point[1] == point[1]:
        if point[0] > next_point[0] and point[1] > pre_point[1] or point[0] < next_point[0] and point[1] < pre_point[1]:
            point_count += 1
            #print(point)
    elif next_point[0] == point[0] and pre_point[1] == point[1]:
        if point[0] > pre_point[0] and point[1] < next_point[1] or point[0] < pre_point[0] and point[1] > next_point[1]:
            point_count += 1
            #print(point)
print(point_count)

n = int(input())
points = []
ans = 0 
for i in range(n):
    x1,y1 = (int(i) for i in input().split())
    points+=[[x1,y1]]
for i in range(n):
    x1 = points[i][0]
    y1 = points[i][1]
    x2 = points[(i+1)%n][0]
    y2 = points[(i+1)%n][1]    
    x3 = points[(i+2)%n][0]
    y3 = points[(i+2)%n][1]   
    if y1 == y2:
        if x2 > x1:
            if y3 > y2 :
                ans+=1
                
        else:
            if y3 < y2:
                ans+=1
    else:
        if y2 > y1:
            if x3 < x2:
                ans+=1
        else:
            if x2 < x3:
                ans+=1
                
                
print(ans)


n=int(input())
s=[int(z) for z in input().split()]
q2=[int(z) for z in input().split()]
q1=s
q3=[int(z) for z in input().split()]
res=0
while q2!=s:
	if q2[0]-q1[0]<0 and q3[1]-q2[1]<0:
		res+=1
	elif q2[0]-q1[0]>0 and q3[1]-q2[1]>0:
		res+=1
	elif q2[1]-q1[1]>0 and q3[0]-q2[0]<0:
		res+=1
	elif q2[1]-q1[1]<0 and q3[0]-q2[0]>0:
		res+=1
	if q3!=s:
		q1,q2,q3=q2,q3,[int(z) for z in input().split()]
	else:
		q2=s
print(res)

def ccw(a, b, c):
    ab = (b[1]-a[1], b[0]-a[0])
    ac = (c[1]-a[1], c[0]-a[0])
    charge = (ab[0]*ac[1] - ab[1]*ac[0])
    return charge > 0
def countccw(points):
    c = 0
    for i in range(len(points)-2):
        if ccw(points[i], points[i+1], points[i+2]): c += 1
    return c
def countcw(points):
    c = 0
    for i in range(len(points)-2):
        if not ccw(points[i], points[i+1], points[i+2]): c += 1
    return c
def __starting_point():
    n = int(input())
    points = [ tuple(int(x) for x in input().split()) for i in range(n+1) ]
    if ccw(points[-3], points[-2], points[-1]):
        print(countcw(points))
    else:
        print(countccw(points))

__starting_point()

n = int(input())
x_b, y_b = list(map(int,input().split()))
dif_b = 0
cnt = 0

for i in range(n-1):
    x, y = list(map(int,input().split()))
    if x > x_b :
        dif = 1
    elif x < x_b :
        dif = 3
    elif y > y_b :
        dif = 0
    elif y < y_b :
        dif = 2

    if (dif_b == 1 and dif == 0) or (dif_b == 0 and dif == 3) or (dif_b == 3 and dif == 2) or (dif_b == 2 and dif == 1):
        cnt += 1

    x_b = x
    y_b = y
    dif_b = dif

print(cnt)


print((int(input())-4)//2)