Supercentral Point (Codeforces 165A)
Tags: Implement, implementation

One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):   point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y  point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y  point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y  point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.

Input: The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.

Output: Print the only number — the number of supercentral points of the given set.

Note: In the first sample the supercentral points are only points (1, 1) and (1, 2).In the second sample there is one supercental point — point (0, 0).

Sample Inputs:
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3

5
0 0
0 1
1 0
0 -1
-1 0

Sample Outputs:
2

1

Solution (Python):
class Solution:

    def __init__(self):
        pass

    @staticmethod
    def right(arr, point):
        for x in arr:
            if x[1] == point[1] and x[0] < point[0]:
                return True
        return False

    @staticmethod
    def left(arr, point):
        for x in arr:
            if x[1] == point[1] and x[0] > point[0]:
                return True
        return False

    @staticmethod
    def upper(arr, point):
        for x in arr:
            if x[0] == point[0] and x[1] < point[1]:
                return True
        return False

    @staticmethod
    def lower(arr, point):
        for x in arr:
            if x[0] == point[0] and x[1] > point[1]:
                return True
        return False

    def solve(self):
        t = int(input())
        count = 0
        arr = []
        for i in range(t):
            point = tuple(map(int, input().split()))
            arr.append(point)
        for x in arr:
            if self.right(arr, x) and self.left(arr, x) and self.upper(arr, x) and self.lower(arr, x):
                count += 1
        print(count)
if __name__ == '__main__':
    sol = Solution()
    sol.solve()

Solution (Python):
points = []
for _ in range(int(input())):
    (x, y) = list(map(int, input().split()))
    points.append((x, y))

def has_upper_lower(point, points):
    has_upper = False
    has_lower = False
    for i in range(len(points)):
        (x1, y1) = points[i]
        if point[0] == x1:
            if point[1] > y1:
                has_lower = True
            if point[1] < y1:
                has_upper = True
    return has_upper and has_lower

def has_left_right(point, points):
    has_left = False
    has_right = False
    for i in range(len(points)):
        (x1, y1) = points[i]
        if point[1] == y1:
            if point[0] < x1:
                has_right = True
            if point[0] > x1:
                has_left = True
    return has_left and has_right
centers = 0
for i in range(len(points)):
    if has_left_right(points[i], points) and has_upper_lower(points[i], points):
        centers += 1
print(centers)

Solution (Python):
n = int(input())
list_c = []
for i in range(n):
    str_input = input().split()
    list_input = list(map(int, str_input))
    list_c.append(list_input)

def rightn(point):
    for x in list_c:
        if x[1] == point[1]:
            if x[0] > point[0]:
                return True

def leftn(point):
    for x in list_c:
        if x[1] == point[1]:
            if x[0] < point[0]:
                return True

def lowern(point):
    for x in list_c:
        if x[0] == point[0]:
            if x[1] < point[1]:
                return True

def uppern(point):
    for x in list_c:
        if x[0] == point[0]:
            if x[1] > point[1]:
                return True
count = 0
for x in list_c:
    if rightn(x) and leftn(x) and uppern(x) and lowern(x):
        count += 1
print(count)