Problem:
A Point in a Triangle There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain. Write a program which prints " YES " if a point $P$ $(x_p, y_p)$ is in the triangle and " NO " if not. Input Input consists of several datasets. Each dataset consists of:  $x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$  All the input are real numbers. Input ends with EOF. The number of datasets is less than or equal to 100. Constraints You can assume that:  $ -100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$  1.0 $\leq$ Length of each side of a tringle  0.001 $\leq$ Distance between $P$ and each side of a triangle  Output For each dataset, print " YES " or " NO " in a line. Sample Input 0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5
0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0 Output for the Sample Input YES
NO

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0012&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline



class Point(object):
    epsilon = 1e-10

    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        else:
            self.x = x
            self.y = y

    
    def __add__(self, other):
        return Point(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return Point(other * self.x, other * self.y)

    def __truediv__(self, other):
        return Point(self.x / other, self.y / other)

    def __lt__(self, other):
        if self.x == other.x:
            return self.y < other.y
        else:
            return self.x < other.x

    def __eq__(self, other):
        from math import fabs
        if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
            return True
        else:
            return False

    def norm(self):
        return self.x * self.x + self.y * self.y

    def __abs__(self):
        return sqrt(self.norm())

    def ccw(self, p0, p1):
        
        a = Vector(p1 - p0)
        b = Vector(self - p0)
        if Vector.cross(a, b) > Point.epsilon:
            return 1 
        elif Vector.cross(a, b) < -Point.epsilon:
            return -1 
        elif Vector.dot(a, b) < -Point.epsilon:
            return 2 
        elif a.norm() < b.norm():
            return -2 
        else:
            return 0 

    def project(self, s):
        
        base = Vector(s.p2 - s.p1)
        a = Vector(self - s.p1)
        r = Vector.dot(a, base)
        r /= base.norm()
        return s.p1 + base * r

    def reflect(self, s):
        
        proj = self.project(s)
        return self + (proj - self)*2

    def distance(self, s):
        
        if Vector.dot(s.p2-s.p1, self-s.p1) < 0.0:
            return abs(self - s.p1)
        if Vector.dot(s.p1-s.p2, self-s.p2) < 0.0:
            return abs(self - s.p2)
        return abs(Vector.cross(s.p2-s.p1, self-s.p1) / abs(s.p2-s.p1))


class Vector(Point):
    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        elif isinstance(x, Point):
            self.x = x.x
            self.y = x.y
        else:
            self.x = x
            self.y = y

    
    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return Vector(other * self.x, other * self.y)

    def __truediv__(self, other):
        return Vector(self.x / other, self.y / other)


    @classmethod
    def dot(cls, a, b):
        return a.x * b.x + a.y * b.y

    @classmethod
    def cross(cls, a, b):
        return a.x * b.y - a.y * b.x

    @classmethod
    def is_orthogonal(cls, a, b):
        return Vector.dot(a, b) == 0.0

    @classmethod
    def is_parallel(cls, a, b):
        return Vector.cross(a, b) == 0.0


class Segment(object):
    def __init__(self, p1=Point(), p2=Point()):
        if isinstance(p1, Point):
            self.p1 = p1
            self.p2 = p2
        elif isinstance(p1, tuple):
            self.p1 = Point(p1[0], p1[1])
            self.p2 = Point(p2[0], p2[1])

    def intersect(self, s):
        
        ans1 = s.p1.ccw(self.p1, self.p2) * s.p2.ccw(self.p1, self.p2)
        ans2 = self.p1.ccw(s.p1, s.p2) * self.p2.ccw(s.p1, s.p2)
        return ans1 <= 0 and ans2 <= 0

    def cross_point(self, s):
        
        base = s.p2 - s.p1
        d1 = abs(Vector.cross(base, self.p1-s.p1))
        d2 = abs(Vector.cross(base, self.p2-s.p1))
        t = d1 / (d1 + d2)
        return self.p1 + (self.p2 - self.p1) * t

    def distance(self, s):
        
        if self.intersect(s):
            return 0.0
        d1 = s.p1.distance(self)
        d2 = s.p2.distance(self)
        d3 = self.p1.distance(s)
        d4 = self.p2.distance(s)
        return min(d1, d2, d3, d4)


    @classmethod
    def is_orthogonal(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_orthogonal(a, b)

    @classmethod
    def is_parallel(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_parallel(a, b)


class Line(Segment):
    pass


class Cirle(object):
    def __init__(self, x, y=Point(), r=1.0):
        if isinstance(x, Point):
            self.c = x
            self.r = y
        elif isinstance(x, tuple):
            self.c = Point(x[0], x[1])
            self.r = r

    def cross_points(self, s):
        if isinstance(s, Segment):
            pr = self.c.project(s)
            e = (s.p2 - s.p1) / abs(s.p2 - s.p1)
            base = sqrt(self.r * self.r - (pr - self.c).norm())
            return pr + e * base, pr - e * base
        elif isinstance(s, Cirle):
            c2 = s
            d = abs(self.c - c2.c)
            a = acos((self.r * self.r + d * d - c2.r * c2.r) / (2 * self.r * d))
            t = atan2(c2.c.y - self.c.y, c2.c.x - self.c.x)
            temp1 = Point(cos(t+a)*self.r, sin(t+a)*self.r)
            temp2 = Point(cos(t-a)*self.r, sin(t-a)*self.r)
            return self.c + temp1, self.c + temp2


def contains(polygon, p):
    n = len(polygon)
    x = False
    for i in range(n):
        a = polygon[i] - p
        b = polygon[(i+1)%n] - p
        if abs(Vector.cross(a, b)) < Point.epsilon and Vector.dot(a, b) < Point.epsilon:
            return 1
        if a.y > b.y:
            temp = a
            a = b
            b = temp
        if a.y < Point.epsilon and Point.epsilon < b.y and Vector.cross(a, b) > Point.epsilon:
            x = not x
    return 2 if x else 0


def main(args):
    for line in sys.stdin:
        polygon = []
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
        polygon.append(Point(x1, y1))
        polygon.append(Point(x2, y2))
        polygon.append(Point(x3, y3))
        result = contains(polygon, Point(xp, yp))
        if result == 2:
            print('YES')
        else:
            print('NO')


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
length=[float(0) for i in range(3)]
while 1:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4=[float(i) for i in input().split( )]
        x12=x1-x2
        y12=y1-y2
        x23=x2-x3
        y23=y2-y3
        x31=x3-x1
        y31=y3-y1
        x14=x1-x4
        y14=y1-y4
        x24=x2-x4
        y24=y2-y4
        x34=x3-x4
        y34=y3-y4
        gai1=x12*y14-x14*y12
        gai2=x23*y24-x24*y23
        gai3=x31*y34-x34*y31
        if (((gai1>0)and(gai2>0)and(gai3>0))or((gai1<0)and(gai2<0)and(gai3<0))):
            print("YES")
        else:
            print("NO")
    except EOFError:
        break

Solution (Python):
import math
import sys


def get_triangle_area(x1, y1, x2, y2, x3, y3):
    l1 = math.sqrt(abs(x1-x2)**2+abs(y1-y2)**2)
    l2 = math.sqrt(abs(x2-x3)**2+abs(y2-y3)**2)
    l3 = math.sqrt(abs(x3-x1)**2+abs(y3-y1)**2)
    s = (l1+l2+l3)/2
    return math.sqrt(s*(s-l1)*(s-l2)*(s-l3))


for l in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, l.split())
    s1 = get_triangle_area(x1, y1, x2, y2, x3, y3)
    s2 = get_triangle_area(xp, yp, x1, y1, x2, y2)
    s2 += get_triangle_area(xp, yp, x2, y2, x3, y3)
    s2 += get_triangle_area(xp, yp, x3, y3, x1, y1)
    print("YES" if round(s1, 5) == round(s2, 5) else "NO")

Solution (Python):



def direction_vector(p1: list, p2: list)->list:
    return [p2[0]-p1[0], p2[1]-p1[1]]


def cross_product(v1: list, v2: list)->float:
    return v1[0]*v2[1] - v1[1]*v2[0]


if __name__ == '__main__':
    while True:
        try:
            points_receive = list(map(float, input().split()))
        except EOFError:
            break

        points_list = [[points_receive[2*i], points_receive[2 * i + 1]] for i in range(4)]
        p1_to_p2 = direction_vector(points_list[0], points_list[1])
        p2_to_p3 = direction_vector(points_list[1], points_list[2])
        p3_to_p1 = direction_vector(points_list[2], points_list[0])
        p1_to_pp = direction_vector(points_list[0], points_list[3])
        p2_to_pp = direction_vector(points_list[1], points_list[3])
        p3_to_pp = direction_vector(points_list[2], points_list[3])
        cp1 = cross_product(p1_to_p2, p1_to_pp)
        cp2 = cross_product(p2_to_p3, p2_to_pp)
        cp3 = cross_product(p3_to_p1, p3_to_pp)

        if cp1 > 0 and cp2 > 0 and cp3 > 0:
            print('YES')
        elif cp1 < 0 and cp2 < 0 and cp3 < 0:
            print('YES')
        else:
            print('NO')

Solution (Python):
import sys


def outer(vec_a, vec_b):
    return vec_a[0] * vec_b[1] - vec_a[1] * vec_b[0]

try:
    while True:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        vec_12 = [x2-x1, y2-y1]
        vec_23 = [x3-x2, y3-y2]
        vec_31 = [x1-x3, y1-y3]
        vec_1p = [xp-x1, yp-y1]
        vec_2p = [xp-x2, yp-y2]
        vec_3p = [xp-x3, yp-y3]
        if (outer(vec_12, vec_1p) > 0 and
                outer(vec_23, vec_2p) > 0 and
                outer(vec_31, vec_3p) > 0):
            print('YES')
        elif (outer(vec_12, vec_1p) < 0 and
                outer(vec_23, vec_2p) < 0 and
                outer(vec_31, vec_3p) < 0):
            print('YES')
        else:
            print('NO')

except:
    sys.exit()

Solution (Python):
def tri(x1, y1, x2, y2, x3, y3):
    return abs((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)) / 2
 
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    abc = tri(x1, y1, x2, y2, x3, y3)
    abp = tri(x1, y1, x2, y2, xp, yp)
    acp = tri(x1, y1, x3, y3, xp, yp)
    bcp = tri(x2, y2, x3, y3, xp, yp)
    x, y = int(abc*pow(10, 5)), int((abp+acp+bcp)*pow(10, 5))
    print("YES" if x >= y else "NO")

Solution (Python):
import math

while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        s1 = (x2-x1)*(yp-y1) - (y2-y1)*(xp-x1)
        s2 = (x3-x2)*(yp-y2) - (y3-y2)*(xp-x2)
        s3 = (x1-x3)*(yp-y3) - (y1-y3)*(xp-x3)
        if math.copysign(1, s1) == math.copysign(1, s2) and math.copysign(1, s1) == math.copysign(1, s3):
            print("YES")
        else:
            print("NO")
    except:
        break

Solution (Python):
def f(a,b,c,d):
    return a*d-b*c

while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,raw_input().split())
        AB=[x2-x1,y2-y1]
        AP=[xp-x1,yp-y1]
        BC=[x3-x2,y3-y2]
        BP=[xp-x2,yp-y2]
        CA=[x1-x3,y1-y3]
        CP=[xp-x3,yp-y3]
        
        
        
        
        
        
        
        
        
        if (f(AB[0],AB[1],AP[0],AP[1]) < 0 and f(BC[0],BC[1],BP[0],BP[1]) < 0 and f(CA[0],CA[1],CP[0],CP[1]) < 0) or\
        (f(AB[0],AB[1],AP[0],AP[1]) > 0 and f(BC[0],BC[1],BP[0],BP[1]) > 0 and f(CA[0],CA[1],CP[0],CP[1]) > 0):
            print "YES"
        else:
            print "NO"
    except:
        break

Solution (Python):


while True:
	try:
		x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())







		xg = 1./3 * (x1 + x2 + x3)
		yg = 1./3 * (y1 + y2 + y3)

		
		def line(xi, yi, xj, yj, x, y):
			return (yi-yj)*x/(xi-xj) + (xi*yj-xj*yi)/(xi-xj)
		
		if x1 != x2:
			def line12(x, y):
				if y < line(x1, y1, x2, y2, x, y):

					return 2
				elif y > line(x1, y1, x2, y2, x, y):

					return 3
				else:

					return 0
		else:
			def line12(x, y):
				if x1 < x:

					return 2
				elif x1 > x:

					return 3
				else:

					return 0

		if x2 != x3:
			def line23(x, y):
				if y < line(x2, y2, x3, y3, x, y):

					return 5
				elif y > line(x2, y2, x3, y3, x, y):

					return 7
				else:

					return 0
		else:
			def line23(x, y):
				if x2 < x:

					return 5
				elif x2 > x:

					return 7
				else:

					return 0

		if x1 != x3:
			def line13(x, y):
				if y < line(x1, y1, x3, y3, x, y):

					return 11
				elif y > line(x1, y1, x3, y3, x, y):

					return 13
				else:

					return 0
		else:
			def line13(x, y):
				if x1 < x:

					return 11
				elif x1 > x:

					return 13
				else:

					return 0

		if line12(xp, yp)*line23(xp, yp)*line13(xp, yp) == line12(xg, yg)*line23(xg, yg)*line13(xg, yg):
			print("YES")
		else:
			print("NO")

	except EOFError:
		break

Solution (Python):
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    AB = [x2-x1, y2-y1]
    BC = [x3-x2, y3-y2]
    CA = [x1-x3, y1-y3]
    BP = [xp-x2, yp-y2]
    CP = [xp-x3, yp-y3]
    AP = [xp-x1, yp-y1]
    v1 = AB[0]*BP[1]-AB[1]*BP[0]
    v2 = BC[0]*CP[1]-BC[1]*CP[0]
    v3 = CA[0]*AP[1]-CA[1]*AP[0]
    print(["NO", "YES"][(v1<0 and v2<0 and v3<0) or (v1>0 and v2>0 and v3>0)])

Solution (Python):
import sys
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 f=lambda h,i,j,k:(h-p)*(i-q)-(j-q)*(k-p)
 a,b=f(x,u,y,t)/f(r,u,s,t),f(x,s,y,r)/f(t,s,u,r)
 print(['NO','YES'][0<a<1-b and 0<b<1-a])

Solution (Python):
import sys
def f(h,i,j,k):
 z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 a,b,c=f(p,q,r,s),f(r,s,t,u),f(t,u,p,q)
 print(['NO','YES'][a==b==c])

Solution (Python):
import sys
def f(h,i,j,k):
 z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 g=[p,q,r,s,t,u]
 print(['NO','YES'][f(*g[:4])==f(*g[2:6])==f(*g[4:],*g[:2])])

Solution (Python):
import sys
def f(h,i,j,k):
 z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 g=[p,q,r,s,t,u]
 print(['NO','YES'][f(*g[:4])==f(*g[2:6])==f(*g[4:],*g[:2])])

Solution (Python):
import sys
def f(h,i,j,k):
 z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 print(['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)])

Solution (Python):
import sys
def f(h,i,j,k):z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 print(['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)])

Solution (Python):
import sys
def f(h,i,j,k):z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 print(['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)])

Solution (Python):
import sys
def f(a,b,c,d):z=(c-a)*(y-d)-(d-b)*(x-c);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 print(['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)])

Solution (Python):
def cross(x, y):
    return (x.conjugate() * y).imag
 
def inside_triangle(p, x, y, z):
    a = cross(y-x, p-y)
    b = cross(z-y, p-z)
    c = cross(x-z, p-x)
    if a*b > 0 and b*c > 0:
        return True
    return False
 
import sys
 
for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    x = complex(x1, y1)
    y = complex(x2, y2)
    z = complex(x3, y3)
    p = complex(xp, yp)
    if inside_triangle(p, x, y, z):
        print('YES')
    else:
        print('NO')

Solution (Python):
g=lambda a,b,c:(a[0]-b[0])*(b[1]-c[1])-(b[0]-c[0])*(a[1]-b[1])

while True:
    try:t=input()
    except:break
    l=[float(i) for i in t.split()]
    b=[g(l[0:2],l[2:4],l[6:8]),g(l[2:4],l[4:6],l[6:8]),g(l[4:6],l[0:2],l[6:8])]
    if len([i for i in b if i>0])==3 or len([i for i in b if i<0])==3:
        print("YES")
    else:
        print("NO")

Solution (Python):
import sys
def f(a,b,c,d):z=(c-a)*(y-d)-(d-b)*(x-c);return[-1*(z==0),1][z>0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 print(['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)])

Solution (Python):
import sys
def calc(x, y, xp, yp):
    a = [(y[i] - y[i -1]) * (xp - x[i]) - (x[i] - x[i - 1]) * (yp - y[i]) for i in range(3)]
    print("YES" if (a[0] > 0 and a[1] > 0 and a[2] > 0) or (a[0] < 0 and a[1] < 0 and a[2] < 0) else "NO")
for s in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, s.split())
    x = [x1, x2, x3]
    y = [y1, y2, y3]
    calc(x, y, xp, yp)

Solution (Python):
import sys

def cross_product(a, b):
    ax, ay = a
    bx, by = b
    return ax * by - ay * bx


def sub(a, b):
    a1, a2 = a
    b1, b2 = b
    return b1 - a1, b2 - a2


def judge(p1, p2, p3, pp):

    cnt = 0
    for a, b in ((p1, p2), (p2, p3), (p3, p1)):
        vec1 = sub(a, b)
        vec2 = sub(a, pp)
        if cross_product(vec2, vec1) > 0:
            cnt += 1
    if cnt == 0 or cnt == 3:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    for line in sys.stdin:
        inputs = [float(s) for s in line.split()]
        p1 = (inputs.pop(0), inputs.pop(0))
        p2 = (inputs.pop(0), inputs.pop(0))
        p3 = (inputs.pop(0), inputs.pop(0))
        pp = (inputs.pop(0), inputs.pop(0))
        judge(p1, p2, p3, pp)

Solution (Python):
import math

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

def CP(p1, p2, p3):
    ax = p2.x-p1.x
    ay = p2.y-p1.y
    bx = p3.x-p1.x
    by = p3.y-p1.y
    return ax*by - ay*bx

def Judge(a,b,c):
    if a > 0 and b > 0 and c > 0:
        print("YES")
    elif a < 0 and b < 0 and c < 0:
        print("YES")
    else:
        print("NO")

def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    x1,y1,x2,y2,x3,y3,xp,yp = [float(i) for i in N[l].split()]
    P1 = Point(x1,y1)
    P2 = Point(x2,y2)
    P3 = Point(x3,y3)
    PP = Point(xp,yp)

    cp1 = CP(PP, P1, P2)
    cp2 = CP(PP, P2, P3)
    cp3 = CP(PP, P3, P1)

    Judge(cp1,cp2,cp3)

Solution (Python):
def f(x):
    x1, y1, x2, y2, x3, y3, xp, yp = x
    ax = x3 - x1
    ay = y3 - y1
    bx = x2 - x1
    by = y2 - y1
    xp -= x1
    yp -= y1
    k = (by * xp - bx * yp) / (ax * by - ay * bx)
    l = (ay * xp - ax * yp) / (ay * bx - ax * by)
    if (k > 0 and l > 0 and k + l < 1):
        print('YES')
    else:
        print('NO')
while True:
    try:
        point = list(map(float, input().split()))
        f(point)
    except EOFError:
        break

Solution (Python):



EPS = 0.0001


def is_atSameSide(a, b, line):
	sa = (line[1].real-line[0].real)*(a.imag-line[0].imag) \
		 + (line[1].imag-line[0].imag)*(line[0].real-a.real);
	sb = (line[1].real-line[0].real)*(b.imag-line[0].imag) \
		 + (line[1].imag-line[0].imag)*(line[0].real-b.real);
	if -EPS <= sa and sa <= EPS: return False 		 
	if -EPS <= sb and sb <= EPS: return False 		 
	if sa*sb >= 0: return True           
	return False  
	
while True:
	try: p = list(map(float, input().split()))
	except: break
	
	p1 = complex(p[0], p[1])
	p2 = complex(p[2], p[3])
	p3 = complex(p[4], p[5])
	pp = complex(p[6], p[7])
	if is_atSameSide(p3, pp, [p1,p2]) and \
	   is_atSameSide(p1, pp, [p2,p3]) and \
	   is_atSameSide(p2, pp, [p3,p1]): print('YES')
	else: print('NO')

Solution (Python):
def vec(s,t):
    return [t[0]-s[0], t[1]-s[1]]

def area(a,b):
    return a[0]*b[1] - a[1]*b[0]

while True:
    try:
        l = [float(x) for x in input().split()]

        a = [l[0],l[1]]
        b = [l[2],l[3]]
        c = [l[4],l[5]]
        p = [l[6],l[7]]

        x = area(vec(p,a),vec(p,b))
        y = area(vec(p,b),vec(p,c))
        z = area(vec(p,c),vec(p,a))

        if (x<0 and y<0 and z<0) or (x>0 and y>0 and z>0):
            print('YES')
        else:
            print('NO')
    except:
        break

Solution (Python):

import math

PI = math.pi
EPS = 10**-10

def edge(a, b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**.5

def area(a, b, c):
    s = (a+b+c)/2
    return (s*(s-a)*(s-b)*(s-c))**.5

def LawOfCosines(a, b, c): 
    return math.acos( (b*b+c*c-a*a) / (2.0*b*c) );

def is_same(x, y): 
    return abs(x-y) < EPS

class Triangle:
    def __init__(self, p):
        a, b, c = p
        self.a = a
        self.b = b
        self.c = c

        self.edgeA = edge(b, c)
        self.edgeB = edge(c, a)
        self.edgeC = edge(a, b)

        self.area = area(self.edgeA, self.edgeB, self.edgeC)

        self.angleA = LawOfCosines(self.edgeA, self.edgeB, self.edgeC)
        self.angleB = LawOfCosines(self.edgeB, self.edgeC, self.edgeA)
        self.angleC = LawOfCosines(self.edgeC, self.edgeA, self.edgeB)

    def circumscribeadCircleRadius(self): 
        return self.edgeA / math.sin(self.angleA) / 2.0

    def circumscribedCircleCenter(self): 
        a = math.sin(2.0*self.angleA);
        b = math.sin(2.0*self.angleB);
        c = math.sin(2.0*self.angleC);
        X = (self.a[0] * a + self.b[0] * b + self.c[0] * c) / (a+b+c);
        Y = (self.a[1] * a + self.b[1] * b + self.c[1] * c) / (a+b+c);
        return X, Y

    def inscribedCircleRadius(self): 
        return 2 * self.area / (self.edgeA + self.edgeB + self.edgeC)

    def inscribedCircleCenter(self): 
        points = [self.a, self.b, self.c]
        edges = [self.edgeA, self.edgeB, self.edgeC]
        s = sum(edges)
        return [sum([points[j][i]*edges[j] for j in range(3)])/s for i in range(2)]

    def isInner(self, p): 
        cross = lambda a, b: a[0]*b[1]-a[1]*b[0]

        c1 = 0
        c2 = 0
        points = [self.a, self.b, self.c]
        for i in range(3):
            a = [points[i][0]-points[(i+1)%3][0], points[i][1]-points[(i+1)%3][1]]
            b = [points[i][0]-p[0],  points[i][1]-p[1]]
            c = cross(a, b)
            if c > 0:
                c1 += 1
            elif c < 0:
                c2 += 1
        if c1 == 3 or c2 == 3:
            return True
        else:
            return c1+c2 != 3 and (c1 == 0 or c2 == 0)

if __name__ == "__main__":
    while True:
        try:
            c = list(map(float, input().split()))
            points = [(c[i], c[i+1]) for i in range(0, 6, 2)]
            point = [c[6], c[7]] 
            t = Triangle(points)
            print(["NO","YES"][t.isInner(point)])
        except:
            break

Solution (Python):
import sys

def cross(a, b):
	return (a.conjugate() * b).imag
def dot(a, b):
	return (a.conjugate() * b).real

def ccw(a, b, c):
	x = b - a
	y = c - a;
	if cross(x, y) > 0: return 1
	if cross(x, y) < 0: return -1
	if dot(x, y) < 0: return 2
	if abs(x) < abs(y): return -2
	return 0

def solve(l, p):
	x = ccw(l[0][0], l[0][1], p)
	if x == 0: x = 1
	else: x = int(x / abs(x))
	for i in l[1:]:
		y = ccw(i[0], i[1], p)
		if y == 0: y = 1
		else: y = int(y / abs(y))
		if x != y:
			print "NO"
			return
	print "YES"

for line in sys.stdin:
	try:
		ax, ay, bx, by, cx, cy, px, py = map(float, line.split())
	except ValueError:
		sys.exit(0)
	a = complex(ax, ay)
	b = complex(bx, by)
	c = complex(cx, cy)
	p = complex(px, py)
	solve([(a, b), (b, c), (c, a)], p)

Solution (Python):
import sys

def cross(a, b):
	return (a.conjugate() * b).imag
def dot(a, b):
	return (a.conjugate() * b).real

def ccw(a, b, c):
	x = b - a
	y = c - a;
	cr = cross(x, y)
	if cr != 0: return cr
	if dot(x, y) < 0: return 2
	if abs(x) < abs(y): return -2
	return 0

def solve(l, p):
	x = cmp(ccw(l[0][0], l[0][1], p), 0)
	if any([x != cmp(ccw(i[0], i[1], p), 0) for i in l[1:]]):
		print "NO"
	else: print "YES"

for line in sys.stdin:
	t = map(float, line.split())
	if len(t) == 0: continue
	a, b, c, p = map(lambda x, y: complex(x, y), t[0::2], t[1::2])
	solve([(a, b), (b, c), (c, a)], p)

Solution (Python):
import sys

def cross(a, b):
	return (a.conjugate() * b).imag
def dot(a, b):
	return (a.conjugate() * b).real

def ccw(a, b, c):
	x = b - a
	y = c - a;
	cr = cross(x, y)
	if cr != 0: return cr
	if dot(x, y) < 0: return 2
	if abs(x) < abs(y): return -2
	return 0

def solve(l, p):
	x = cmp(ccw(l[0][0], l[0][1], p), 0)
	if all(cmp(ccw(i[0], i[1], p), 0) == x for i in l[1:]):
		print "YES"
	else:
		print "NO"

for line in sys.stdin:
	t = map(float, line.split())
	if len(t) == 0: continue
	a, b, c, p = map(complex, t[0::2], t[1::2])
	solve([(a, b), (b, c), (c, a)], p)

Solution (Python):
import sys
def cross(a, b):
	return (a.conjugate() * b).imag
def dot(a, b):
	return (a.conjugate() * b).real
def ccw(a, b, c):
	x = b - a
	y = c - a;
	cr = cross(x, y)
	if cr != 0: return cr
	if dot(x, y) < 0: return 2
	if abs(x) < abs(y): return -2
	return 0
for line in sys.stdin:
	t = map(float, line.split())
	if len(t) == 0: continue
	a, b, c, p = map(complex, t[0::2], t[1::2])
	l = [(a, b), (b, c), (c, a)]
	x = cmp(ccw(l[0][0], l[0][1], p), 0)
	if all(cmp(ccw(i[0], i[1], p), 0) == x for i in l[1:]):
		print "YES"
	else:
		print "NO"

Solution (Python):
import sys
for line in sys.stdin.readlines():
    try:
        list=map(float,line.split())
        x=list[0:6:2]
        y=list[1:6:2]
        xp=list[6]
        yp=list[7]
        xv=[x[a%3]-x[(a+1)%3] for a in xrange(4)]
        yv=[y[a%3]-y[(a+1)%3] for a in xrange(4)]
        xpv=[xp-x[a] for a in xrange(3)]
        ypv=[yp-y[a] for a in xrange(3)]
        cross=[xv[i]*ypv[i]-yv[i]*xpv[i] for i in xrange(3)]
        if (cross[2]>0 and cross[1]>0  and cross[0]>0) or (cross[2]<0 and cross[1]<0 and cross[0]<0): 
            print "YES"
        else:
            print "NO"
    except:
        pass

Solution (Python):
def dot(a, b):
    return (a.real*b.real - a.imag*b.imag)
def cross(a, b):
    return (a.real*b.imag - a.imag*b.real)

EPS = 10**(-7)

def isIntersectedLS(a1, a2, b1, b2):
    return ((cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1)) < EPS and
            (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1)) < EPS)

while 1:
    try:
        x,y = [[0. for i in xrange(3)] for j in xrange(2)]
        a = []
        z = [0. for i in xrange(2)]
        line = raw_input().split()
        if line == []: break
        x[0],y[0],x[1],y[1],x[2],y[2],z[0],z[1] = map(float, line)
        for i in xrange(3):
            a.append((x[i]+(y[i])*1j))
        c = (sum(x)/3)+(sum(y)/3)*1j
        p = z[0]+z[1]*1j
           
        for i in xrange(3):
            
            if isIntersectedLS(a[i-1], a[i], c, p) is True:
                print "NO"
                break
        else:
            print "YES"
           
    except EOFError:
        break

Solution (Python):
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

class DirectedSegment:
    def __init__(self, s, e):
        self.start = s
        self.end = e

LEFT = -1
ONLINE = 0
RIGHT = 1

def datasets():
    import sys
    while True:
        s = sys.stdin.readline()
        if len(s) < 2:
            break
        x1, y1, x2, y2, x3, y3, xp, yp = [float(d) for d in s.split()]
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        x = Point(xp,yp)
        yield p1, p2, p3, x

def side(ds, p):
    return cmp(p.x * (ds.start.y - ds.end.y) + ds.start.x * (ds.end.y - p.y) + ds.end.x * (p.y - ds.start.y), 0)

for p1, p2, p3, x in datasets():
    r = [
            side(DirectedSegment(p1, p2), x),
            side(DirectedSegment(p2, p3), x),
            side(DirectedSegment(p3, p1), x)
        ]
    if all(0 < n for n in r) or all(0 > n for n in r):
        print "YES"
    else:
        print "NO"

Solution (Python):
class Point(object):
    x = 0.0
    y = 0.0
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __sub__(left, right):
        return Point(left.x - right.x, left.y - right.y)
    
    def __mul__(left, right):
        return left.x * right.y - left.y * right.x

while True:
    try:
        (x1, y1, x2, y2, x3, y3, xp, yp) = map(float, raw_input().split())
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        pp = Point(xp, yp)
        p12 = p1 - p2
        p23 = p2 - p3
        p31 = p3 - p1
        pp1 = pp - p1
        pp2 = pp - p2
        pp3 = pp - p3
        c1 = (p12 * pp1 < 0.0)
        c2 = (p23 * pp2 < 0.0)
        c3 = (p31 * pp3 < 0.0)
        if(c1 ^ c2 or c2 ^ c3):
            print 'NO'
        else:
            print 'YES'
    except EOFError:
        break

Solution (Python):
if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
			if vec > 0:
				r += 1
			elif vec < 0:
				r -= 1
			vec = (x3 - x2) * (yp - y2) - (y3 - y2) * (xp - x2)
			if vec > 0:
				r += 1
			elif vec < 0:
				r -= 1
			vec = (x1 - x3) * (yp - y3) - (y1 - y3) * (xp - x3)
			if vec > 0:
				r += 1
			elif vec < 0:
				r -= 1
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

Solution (Python):
def checker(x1,y1,x2,y2,xp,yp):
	r = 0
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		r = 1
	elif vec < 0:
		r = -1
	return r

if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			r += int(checker(x1,y1,x2,y2,xp,yp))
			r += int(checker(x2, y2, x3, y3, xp, yp))
			r += int(checker(x3, y3, x1, y1, xp, yp))
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

Solution (Python):
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from operator import attrgetter
from collections import namedtuple

Point = namedtuple('Point', 'x y')

def linear(p1, p2):
    gradient = (p1.y - p2.y) / (p1.x - p2.x)
    y_intercept = p1.y - gradient * p1.x
    return lambda x: gradient * x + y_intercept

def takeout(seq):
    gen = (Point(next(seq), next(seq)) for _ in xrange(3))
    for p in sorted(gen, key=attrgetter('x')):
        yield p
    yield Point(next(seq), next(seq))

for line in stdin:
    A, B, C, P = takeout(float(s) for s in line.split())
    assert A.x <= B.x <= C.x
    if P.x <= A.x or C.x <= P.x:
        print('NO')
        continue
    if A.x == B.x or B.x <= P.x <= C.x:
        L = (linear(B, C), linear(A, C))
    elif B.x == C.x or A.x <= P.x <= B.x:
        L = (linear(A, B), linear(A, C))
    else:
        print('NO')
        continue

    y1, y2 = sorted(f(P.x) for f in L)
    if y1 < P.y < y2:
        print('YES')
    else:
        print('NO')

Solution (Python):
from math import sqrt
dis = lambda x1,y1,x2,y2: sqrt((x1-x2)**2+(y1-y2)**2)
def heron(a,b,c):
    s = (a+b+c)*1.0/2
    return sqrt(s*(s-a)*(s-b)*(s-c))
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
        a,b,c = dis(x1,y1,x2,y2),dis(x1,y1,x3,y3),dis(x3,y3,x2,y2)
        d,e,f = dis(x1,y1,xp,yp),dis(xp,yp,x2,y2),dis(xp,yp,x3,y3)
        AnsS = heron(a,b,c)
        FakS = heron(a,e,d)+heron(e,c,f)+heron(d,b,f)
        q1,q2 = str(AnsS),str(FakS)
        Ans = "YES" if q1 == q2 else "NO"
        print Ans
    except EOFError: break