def point_in_polygon(x, y, polygon):
    """ Check if a point is inside a polygon
        - x,y - Coordinates of the point
        - polygon - List of the vertices of the polygon [(x1, x2), (x2, y2), ..., (xn, yn)]"""
    i = 0
    j = len(polygon) - 1
    res = False
    for i in range(len(polygon)):
        if (polygon[i][1] < y and polygon[j][1] >= y) \
                or (polygon[j][1] < y and polygon[i][1] >= y):
            if polygon[i][0] + (y - polygon[i][1]) / (polygon[j][1] - polygon[i][1]) * (
                    polygon[j][0] - polygon[i][0]) < x:
                res = not res
        j = i
    return res