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):
import sys


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



def direction_of_rotation(p1, p2, p3):
    d = p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y)
    if d < 0:
        direction = 'right'
    else:
        direction = 'left'
    return direction






for line in sys.stdin:
    a = map((lambda x: float(x)), line.split(' '))
    p1 = Point(a[0], a[1])
    p2 = Point(a[2], a[3])
    p3 = Point(a[4], a[5])
    p  = Point(a[6], a[7])
    d1 = direction_of_rotation(p, p1, p2)
    d2 = direction_of_rotation(p, p2, p3)
    d3 = direction_of_rotation(p, p3, p1)
    if d1 == d2 and d1 == d3:
        print "YES"
    else:
        print "NO"

Solution (Python):
import sys

class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def isLeft(self, vector):
        tmpVector = DirectedVector(vector.start, self)
        sin = tmpVector * vector
        if sin > 0:
            return True
        else:
            return False

class DirectedVector(object):
    def __init__(self, start, end):
        self.start = start
        self.end = end
    @property
    def x(self):
        return self.end.x - self.start.x
    @property
    def y(self):
        return self.end.y - self.start.y
    def __mul__(self, other):
        return self.x * other.y - self.y * other.x

def getDataSets():
    for line in sys.stdin.readlines():
        line = line.strip()
        x1, y1, x2, y2, x3, y3, xp, yp = [float(x) for x in line.split()]
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        px = Point(xp, yp)
        yield p1, p2, p3, px

def main():
    for p1, p2, p3, px in getDataSets():
        evaluate = [
                px.isLeft(DirectedVector(p1, p2)),
                px.isLeft(DirectedVector(p2, p3)),
                px.isLeft(DirectedVector(p3, p1)),
                ]
        if(all(evaluate) or not any(evaluate)):
            print 'YES'
        else:
            print 'NO'

if __name__ == "__main__":
    main()

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

while True:
    try:
        x = map(float, raw_input().split())
        p1 = x[0:2]
        p2 = x[2:4]
        p3 = x[4:6]
        p0 = x[6:]
        if (side(p1, p2, p0)==side(p2, p3, p0) and side(p2, p3, p0)==side(p3, p1, p0)):
            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())
        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):


import sys


def prod2d(vec1, vec2):
    return vec1[0]*vec2[1] - vec1[1]*vec2[0]

lineNumber = 0

for line in sys.stdin.readlines():
    lineNumber += 1

    
    List = map(float, line.strip().split())

    
    nodes = [ [List[0], List[1]], [List[2], List[3]], [List[4], List[5]] ]
    point = [List[6], List[7]]

    
    ABvec = [ nodes[1][0] - nodes[0][0], nodes[1][1] - nodes[0][1] ]
    BCvec = [ nodes[2][0] - nodes[1][0], nodes[2][1] - nodes[1][1] ]
    CAvec = [ nodes[0][0] - nodes[2][0], nodes[0][1] - nodes[2][1] ]
    APvec = [ point[0] - nodes[0][0], point[1] - nodes[0][1] ]
    BPvec = [ point[0] - nodes[1][0], point[1] - nodes[1][1] ]
    CPvec = [ point[0] - nodes[2][0], point[1] - nodes[2][1] ]

    a = prod2d(CAvec, APvec)
    b = prod2d(ABvec, BPvec)
    c = prod2d(BCvec, CPvec)

    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"

Solution (Python):
import math
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = math.sqrt((x1-x2)**2+(y1-y2)**2)
        b = math.sqrt((x1-x3)**2+(y1-y3)**2)
        c = math.sqrt((x2-x3)**2+(y2-y3)**2)
        xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
        xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
        xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
        s = (a+b+c)/2
        sa = (a+xb+xc)/2
        sb = (b+xa+xc)/2
        sc = (c+xa+xb)/2
        ss = math.sqrt(s*(s-a)*(s-b)*(s-c))
        ssa = math.sqrt(sa*(sa-a)*(sa-xb)*(sa-xc))
        ssb = math.sqrt(sb*(sb-xa)*(sb-b)*(sb-xc))
        ssc = math.sqrt(sc*(sc-xa)*(sc-xb)*(sc-c))
        
        if ssa+ssb+ssc - ss > 0.0000001:
            print "NO"
        else:
            print "YES"
    except:
        break

Solution (Python):
import math
def S(a,b,c):
	s = (a+b+c)/2
	return math.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 = math.sqrt((x1-x2)**2+(y1-y2)**2)
		b = math.sqrt((x1-x3)**2+(y1-y3)**2)
		c = math.sqrt((x2-x3)**2+(y2-y3)**2)
		xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
		xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
		xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
		if S(a,xb,xc)+S(b,xc,xa)+S(c,xa,xb)-S(a,b,c) > 0.0000001:
			print "NO"
		else:
			print "YES"
	except:
		break

Solution (Python):
import math
def S(a,b,c):
	s = (a+b+c)/2
	return math.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 = math.sqrt((x1-x2)**2+(y1-y2)**2)
		b = math.sqrt((x1-x3)**2+(y1-y3)**2)
		c = math.sqrt((x2-x3)**2+(y2-y3)**2)
		xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
		xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
		xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
		if S(a,xb,xc)+S(b,xc,xa)+S(c,xa,xb)-S(a,b,c) > 0.0000001:
			print "NO"
		else:
			print "YES"
	except:
		break

Solution (Python):
import math

def L(x1,y1,x2,y2):
	return math.sqrt((x1-x2)**2+(y1-y2)**2)
	
def S(a,b,c):
	s=(a+b+c)/2
	return math.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  = L(x1,y1,x2,y2)
        b  = L(x1,y1,x3,y3)
        c  = L(x2,y2,x3,y3)
        pa = L(x3,y3,xp,yp)
        pb = L(x2,y2,xp,yp)
        pc = L(x1,y1,xp,yp)
        if S(a,pb,pc)+S(b,pc,pa)+S(c,pa,pb)-S(a,b,c) > 0.0000001:
            print "NO"
        else:
            print "YES"
    except:
        break

Solution (Python):
import sys

def c(x1, y1, x2, y2, x, y):
  return (y2 - y1)*(x - x1) - (x2 - x1)*(y - y1)

for str in sys.stdin:
  x1,y1,x2,y2,x3,y3,xp,yp = map(float, str.split(' '))
  gx, gy = (x1 + x2 + x3)/3, (y1 + y2 + y3)/3

  r1 = c(x1, y1, x2, y2, gx, gy)*c(x1, y1, x2, y2, xp, yp) > 0
  r2 = c(x2, y2, x3, y3, gx, gy)*c(x2, y2, x3, y3, xp, yp) > 0
  r3 = c(x3, y3, x1, y1, gx, gy)*c(x3, y3, x1, y1, xp, yp) > 0
  print 'YES' if r1 and r2 and r3 else 'NO'

Solution (Python):
while 1:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())
    except EOFError:
        break
    Points = [(x1, y1), (x2, y2), (x3, y3)]
    for i in xrange(3):
        A = Points[i]
        B = Points[(i + 1) % 3]
        C = Points[(i + 2) % 3]
        if A[0] - B[0] == 0:
            mark1 = C[0] - A[0]
            mark2 = xp - A[0]
        else:
            a = (A[1] - B[1]) / (A[0] - B[0])
            b = A[1] - a * A[0]
            mark1 = C[1] - (a * C[0] + b)
            mark2 = yp - (a * xp + b)
        if not ((mark1 >= 0 and mark2 >= 0) or (mark1 <= 0 and mark2 <= 0)):
            print "NO"
            break
    else:
        print "YES"

Solution (Python):
import math

def L(x1,y1,x2,y2):
  return math.sqrt((x1-x2)**2+(y1-y2)**2)

def S(a,b,c):
  s=(a+b+c)/2
  return math.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  = L(x1,y1,x2,y2)
    b  = L(x1,y1,x3,y3)
    c  = L(x2,y2,x3,y3)
    pa = L(x3,y3,xp,yp)
    pb = L(x2,y2,xp,yp)
    pc = L(x1,y1,xp,yp)
    if S(a,pb,pc)+S(b,pc,pa)+S(c,pa,pb)-S(a,b,c) > 0.0000001:
      print "NO"
    else:
      print "YES"
  except:
    break

Solution (Python):
import math

def L(x1, y1, x2, y2):
  return math.sqrt((x1 - x2)**2+(y1 - y2)**2)

def S(a, b, c):
  s=(a + b + c)/2
  return math.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 = L(x1, y1, x2, y2)
    b = L(x1, y1, x3, y3)
    c = L(x2, y2, x3, y3)
    p1 = L(x1, y1, xp, yp)
    p2 = L(x2, y2, xp, yp)
    p3 = L(x3, y3, xp, yp)

    if S(a, p2, p1)+S(b, p1, p3)+S(c, p3, p2)-S(a, b, c) > 0.0000001:
      print "NO"
    else:
      print "YES"
  except:
    break

Solution (Python):
def r(x1, y1, x2, y2, x3, y3):
    return x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2) > 0

while True:
    try:
        line = input()
    except:
        break

    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.strip().split())

    abc = r(x1, y1, x2, y2, x3, y3)
    pab = r(xp, yp, x1, y1, x2, y2)
    pbc = r(xp, yp, x2, y2, x3, y3)
    pca = r(xp, yp, x3, y3, x1, y1)

    print('YES' if abc == pab == pbc == pca else 'NO')

Solution (Python):

def func(a, b, c, d):
    k = (d - b) / (c - a)
    h = d - k * c
    return k, h



def fx(a, b, c, d, x):
    k, h = func(a, b, c, d)
    return k * x + h


def main():
    import sys
    for dataset in sys.stdin:
        ans = 'NO'
        try :
            a, b, c, d, e, f, px, py = map(float, dataset.split())
        except:
            break
        T = [(a, b), (c, d), (e, f)]
        T.sort(key=lambda x: (x[0], x[1]))
        a, b, c, d, e, f = T[0][0], T[0][1], T[1][0], T[1][1], T[2][0], T[2][1]
        
        if a == c:
            if  a < px and fx(a, b, e, f, px) < py and fx(c, d, e, f, px) > py:
                ans = 'YES'
        elif c == e:
            if px < e and fx(a, b, c, d, px) < py and fx(a, b, e, f, px) > py:
                ans = 'YES'
        else:  
            if fx(a, b, e, f, c) < d:  
                if fx(a, b, c, d, px) > py and fx(c, d, e, f, px) > py and fx(a, b, e, f, px) < py:
                    ans = 'YES'
            else:
                if fx(a, b, c, d, px) < py and fx(c, d, e, f, px) < py and fx(a, b, e, f, px) > py:
                    ans = 'YES'

        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

def cross_product(a,b):
    return (a.conjugate()*b).imag

def abs_area_vector(ax,ay,bx,by):
    return abs(0.5 * (cross_product(complex(ax,ay),complex(bx,by))))

def abs_area_3point(ax,ay,bx,by,cx,cy):
    return abs_area_vector(bx-ax,by-ay,cx-ax,cy-ay)

try:
    while True:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,input().split())
        abc = abs_area_3point(x1,y1,x2,y2,x3,y3)
        pab = abs_area_3point(x1,y1,x2,y2,xp,yp)
        pbc = abs_area_3point(x2,y2,x3,y3,xp,yp)
        pca = abs_area_3point(x1,y1,x3,y3,xp,yp)
        
        print("NO" if pab * pbc * pca == 0 or abc != pab + pbc + pca else "YES")
except  (EOFError,ValueError):
    pass

Solution (Python):
try:
    while True:
        P= list(map(float,input().split()))
        a, b, c, q = [complex(P[i*2],P[i*2+1]) for i in range(4)]
        x,y,z= a-q,b-q,c-q
        xx= (x.conjugate()*y).imag
        yy= (y.conjugate()*z).imag
        zz= (z.conjugate()*x).imag
        if (xx>0 and yy>0 and zz>0) or (xx<0 and yy<0 and zz<0):
            print("YES")
        else:
            print("NO")
except EOFError: 
    pass

Solution (Python):
def cross_product(a,b):
  return (a.conjugate()*b).imag
try:
    while True:
        P = list(map(float,input().split()))
        a, b, c, p = [complex(P[i*2],P[i*2+1]) for i in range(4)]
        S = cross_product(p-a,p-b)
        T = cross_product(p-b,p-c)
        U = cross_product(p-c,p-a)
        if S*T > 0 and T*U >0:
            print('YES')
        else:
            print('NO')
except EOFError:
    pass

Solution (Python):
try:
    while True:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        a = complex(x1, y1)
        b = complex(x2, y2)
        c = complex(x3, y3)
        p = complex(xp, yp)
        s1 = ((a - p).conjugate() * (b - p)).imag
        s2 = ((b - p).conjugate() * (c - p)).imag
        s3 = ((c - p).conjugate() * (a - p)).imag
        if (s1 > 0) ^ (s2 > 0) == False and (s2 > 0) ^ (s3 > 0) == False:
            print('YES')
        else:
            print("NO")
except EOFError:
    exit()

Solution (Python):
import math
import cmath
def dot(a:complex,b:complex):
  return (a.conjugate()*b).real
def cross(a:complex,b:complex):
  return (a.conjugate()*b).imag
next=[1,2,0]
try:
  while True:
    l=list(map(float,input().split()))
    p=[complex(l[2*j],l[2*j+1]) for j in range(4)]
    flg_ans=True
    sgn=1 if cross(p[0]-p[3],p[1]-p[3])>0 else -1
    for i in range(3):
      flg_ans=flg_ans and (sgn*cross(p[i]-p[3],p[next[i]]-p[3]))>0
    print('YES' if flg_ans else 'NO')
except EOFError:
  pass

Solution (Python):
def stl1(x):
    if a == e:
        y = b
    else:
        y = (f-b)*(x-a)/(e-a) +b

    return(y)

def stl2(x):
    if c == e:
        y = f
    else:
        y = (d-f)*(x-e)/(c-e) +f

    return(y)

def stl3(x):
    if c == a:
        y = b
    else:
        y = (d-b)*(x-a)/(c-a) +b
        
    return(y)

while True:
    try:
        lst = list(map(float, input().split()))
        point1 = [lst[0], lst[1]]
        point2 = [lst[2], lst[3]]
        point3 = [lst[4], lst[5]]
        xp, yp = lst[6], lst[7]

        pointlst = [point1, point2, point3]
        pointlst.sort()
        a, b, e, f, c, d = pointlst[0][0], pointlst[0][1], pointlst[1][0], pointlst[1][1], pointlst[2][0], pointlst[2][1]

        if a <= xp and xp <= e:
            bdr1 = stl1(xp)
            bdr3 = stl3(xp)

            if min(bdr1, bdr3) <= yp and yp <= max(bdr1, bdr3):
                print("YES")

            else:
                print("NO")
        
        elif e < xp and xp <= c:
            bdr2 = stl2(xp)
            bdr3 = stl3(xp)

            if min(bdr2, bdr3) <= yp and yp <= max(bdr2, bdr3):
                print("YES")
            
            else:
                print("NO")

        else:
            print("NO")

    except EOFError:
        break

Solution (Python):
def cross3(a, b, c):
    return (b[0] - a[0])*(c[1] - a[1]) - (b[1] - a[1])*(c[0] - a[0])
for line in open(0).readlines():
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    p1 = (x1, y1); p2 = (x2, y2); p3 = (x3, y3); pp = (xp, yp)
    if cross3(p1, p2, p3) < 0:
        p1, p2 = p2, p1
    if cross3(p1, p2, pp) > 0 and cross3(p1, pp, p3) > 0 and cross3(p2, p3, pp) > 0:
        print("YES")
    else:
        print("NO")

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

        sign = lambda x1, y1, x2, y2, x3, y3: (x1 - x3) * (y2 - y3) - (x2 - x3) * (y1 - y3)
        b1 = sign(xp, yp, x1, y1, x2, y2) < 0.0
        b2 = sign(xp, yp, x2, y2, x3, y3) < 0.0
        b3 = sign(xp, yp, x3, y3, x1, y1) < 0.0


        if b1 == b2 and b2 == b3:
            print("YES")
        else:
            print("NO")
    except:
        break

Solution (Python):
import sys
  
for s in sys.stdin:
    x1,y1,x2,y2,x3,y3,xp,yp = [ float(x) for x in s.split() ]

    v12 = (x2-x1, y2-y1)
    v23 = (x3-x2, y3-y2)
    v31 = (x1-x3, y1-y3)
    v1p = (xp-x1, yp-y1)
    v2p = (xp-x2, yp-y2)
    v3p = (xp-x3, yp-y3)
    cp1 = v12[0]*v1p[1] - v1p[0]*v12[1]
    cp2 = v23[0]*v2p[1] - v2p[0]*v23[1]
    cp3 = v31[0]*v3p[1] - v3p[0]*v31[1]

    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):
while True :
    try :
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        
        
        
        
        
        
        
        
        
        a = xp * (y1 - y2) + x1 * (y2 - yp) + x2 * (yp - y1)
        b = xp * (y2 - y3) + x2 * (y3 - yp) + x3 * (yp - y2)
        c = xp * (y3 - y1) + x3 * (y1 - yp) + x1 * (yp - y3)
            
        if((a < 0 and b < 0 and c < 0) or (a > 0 and b > 0 and c > 0)) :
            print("YES")
        else :
            print("NO")
            
    except :
        break

Solution (Python):
def r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0
  
while True:
    try: line = list(map(float, input().split()))
    except: break
      
    x1, y1, x2, y2, x3, y3, xp, yp = line
    abc = r(x1, y1, x2, y2, x3, y3)
    pab = r(xp, yp, x1, y1, x2, y2)
    pbc = r(xp, yp, x2, y2, x3, y3)
    pca = r(xp, yp, x3, y3, x1, y1)
  
    print('YES' if abc == pab == pbc == pca else '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 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):
def r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0
 
while True:
    try: line = list(map(float, input().split()))
    except: break
     
    x1, y1, x2, y2, x3, y3, xp, yp = line
    abc = r(x1, y1, x2, y2, x3, y3)
    pab = r(xp, yp, x1, y1, x2, y2)
    pbc = r(xp, yp, x2, y2, x3, y3)
    pca = r(xp, yp, x3, y3, x1, y1)
 
    print('YES' if abc == pab == pbc == pca else 'NO')

Solution (Python):
import sys
def gaiseki(x0, y0, x1, y1):
    return x0*y1 - y0*x1
def muki(x0, y0, x1, y1, x2, y2):
    return gaiseki(x1-x0, y1-y0, x2-x1, y2-y1) > 0
for line in sys.stdin:
    x0, y0, x1, y1, x2, y2, xp, yp = map(float, line.split())
    m0 = muki(xp, yp, x0, y0, x1, y1)
    m1 = muki(xp, yp, x1, y1, x2, y2)
    m2 = muki(xp, yp, x2, y2, x0, y0)
    if m0 == m1 and m1 == m2:
        print('YES')
    else:
        print('NO')

Solution (Python):
def isPos(p,x,y):
    return ((x-p).conjugate()*(y-p)).imag>0

try:
    while True:
        X=list(map(float,input().split()))
        a,b,c,p=map(lambda x:complex(*x),[X[:2],X[2:4],X[4:6],X[6:]])
        print(['NO','YES'][isPos(p,a,b)==isPos(p,b,c)==isPos(p,c,a)])
except EOFError: pass

Solution (Python):
while True:
  try:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
  except EOFError:
    break
  vec_b = [x2-x1, y2-y1]
  vec_c = [x3-x1, y3-y1]
  vec_p = [xp-x1, yp-y1]
  a = (vec_p[0]*vec_c[1] - vec_p[1]*vec_c[0]) / (vec_b[0]*vec_c[1] - vec_b[1]*vec_c[0])
  b = (vec_p[0]*vec_b[1] - vec_p[1]*vec_b[0]) / (vec_b[1]*vec_c[0] - vec_b[0]*vec_c[1])
  if ((a > 0) and (b > 0) and (a+b < 1)):
    print("YES")
  else:
    print("NO")

Solution (Python):
while 1:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split())
        a=((x1-x2)**2+(y1-y2)**2)**0.5
        b=((x2-x3)**2+(y2-y3)**2)**0.5
        c=((x3-x1)**2+(y3-y1)**2)**0.5
        s=(a+b+c)/2
        S=(s*(s-a)*(s-b)*(s-c))**0.5
        d=((x1-xp)**2+(y1-yp)**2)**0.5
        e=((x2-xp)**2+(y2-yp)**2)**0.5
        f=((x3-xp)**2+(y3-yp)**2)**0.5
        sa=(a+d+e)/2
        sb=(b+e+f)/2
        sc=(c+f+d)/2
        Sa=(sa*(sa-a)*(sa-d)*(sa-e))**0.5
        Sb=(sb*(sb-b)*(sb-e)*(sb-f))**0.5
        Sc=(sc*(sc-c)*(sc-f)*(sc-d))**0.5
        Sp=Sa+Sb+Sc
        if abs(S-Sp)<=0.001**2:
            print("YES")
        else:
            print("NO")
    except:break

Solution (Python):
if __name__ == '__main__':
    while True:
        try:
            x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
            ab = [x2-x1, y2-y1]
            bp = [xp-x2, yp-y2]
            bc = [x3-x2, y3-y2]
            cp = [xp-x3, yp-y3]
            ca = [x1-x3, y1-y3]
            ap = [xp-x1, yp-y1]
            c1 = ab[0]*bp[1] - ab[1]*bp[0]
            c2 = bc[0]*cp[1] - bc[1]*cp[0]
            c3 = ca[0]*ap[1] - ca[1]*ap[0]
            if (c1 > 0 and c2 > 0 and c3 > 0) or (c1 < 0 and c2 < 0 and c3 < 0):
                print("YES")
            else:
                print("NO")
        except EOFError:
            break

Solution (Python):
def cross(a,b):
    return (a.conjugate()*b).imag
def is_in_triangle(X1,Y1,X2,Y2,X3,Y3,Xp,Yp):
    z1 = complex(X1-Xp,Y1-Yp)
    z2 = complex(X2-Xp,Y2-Yp)
    z3 = complex(X3-Xp,Y3-Yp)
    if cross(z1,z2) * cross(z2,z3) > 0:
        if cross(z2,z3) * cross(z3,z1) > 0:
            return True
    else:
        return False
lst = []
try:
    while True:
        P = tuple(map(float,input().strip().split()))
        lst.append(P)
except EOFError:
    pass
N = len(lst)
for i in range(N):
    if is_in_triangle(*lst[i]):
        print("YES")
    else:
        print("NO")

Solution (Python):
E = 10**-10

def cp(a, b):
    c = [a[1]*b[2] - a[2]*b[1],
        a[2]*b[0] - a[0]*b[2],
        a[0]*b[1] - a[1]*b[0]]
    return c

while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = [float(i) for i in input().split()]
        ax = x3-x1
        ay = y3-y1
        bx = x1-x2
        by = y1-y2
        cx = x2-x3
        cy = y2-y3
        pax = xp-x1
        pay = yp-y1
        pbx = xp-x2
        pby = yp-y2
        pcx = xp-x3
        pcy = yp-y3
        ca = [bx,by,0]
        ab = [cx,cy,0]
        bc = [ax,ay,0]
        pa = [pax,pay,0]
        pb = [pbx,pby,0]
        pc = [pcx,pcy,0]
        cp1 = cp(ca,pa)[2]
        cp2 = cp(ab,pb)[2]
        cp3 = cp(bc,pc)[2]
        if abs(cp1 - abs(cp1)) < E:
            sig1 = 1
        elif abs(cp1 + abs(cp1)) < E:
            sig1 = -1
        if abs(cp2 - abs(cp2)) < E:
            sig2 = 1
        elif abs(cp2 + abs(cp2)) < E:
            sig2 = -1
        if abs(cp3 - abs(cp3)) < E:
            sig3 = 1
        elif abs(cp3 + abs(cp3)) < E:
            sig3 = -1
        if abs(sig1 + sig2 + sig3) == 3:
            print('YES')
        else:
            print('NO')
    except EOFError:
        break

Solution (Python):
def r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0

while True:
    try: line = list(map(float, input().split()))
    except: break
    
    x1, y1, x2, y2, x3, y3, xp, yp = line
    abc = r(x1, y1, x2, y2, x3, y3)
    pab = r(xp, yp, x1, y1, x2, y2)
    pbc = r(xp, yp, x2, y2, x3, y3)
    pca = r(xp, yp, x3, y3, x1, y1)

    print('YES' if abc == pab == pbc == pca else 'NO')

Solution (Python):
while(True):
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, input().split())
        c1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1)
        c2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2)
        c3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3)
        if (c1<0 and c2<0 and c3<0) or (c1>0 and c2>0 and c3>0):
            print("YES")
            continue
        print("NO")
    except:
        break

Solution (Python):
from collections import namedtuple

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

def sign (p1, p2, p3):
  return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);

while True:
  try:
    x = list(map(float, input().split()))
    p1 = Point(x[0], x[1])
    p2 = Point(x[2], x[3])
    p3 = Point(x[4], x[5])
    pp = Point(x[6], x[7])
    b1 = sign(pp, p1, p2) < 0.0
    b2 = sign(pp, p2, p3) < 0.0
    b3 = sign(pp, p3, p1) < 0.0
    if (b1 == b2) and(b2 == b3):
      print('YES')
    else:
      print('NO')
  except:
    break

Solution (Python):
def rot(xa,ya,xb,yb,xc,yc):
    r=(xb-xa)*(yc-ya)-(xc-xa)*(yb-ya)
    if r>0:return 1
    if r==0:return 0
    if r<0:return -1
while 1:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split(" "))
        if rot(x1,y1,x2,y2,xp,yp)==rot(x2,y2,x3,y3,xp,yp)==rot(x3,y3,x1,y1,xp,yp):
            print("YES")
        else:
            print("NO")
    except:break

Solution (Python):
def point(a,b):
    return a[0]*b[0]+a[1]*b[1]
def euclid(a):
    return (a[0]**2+a[1]**2)**(1/2)
def cos(a,b):
    return point(a,b)/(euclid(a)*euclid(b))
while 1:
    try:
        ax,ay,bx,by,cx,cy,px,py = map(float, input().split(" "))
        ab = [bx-ax, by-ay]
        ac = [cx-ax, cy-ay]
        ba = [ax-bx, ay-by]
        bc = [cx-bx, cy-by]
        ap = [px-ax, py-ay]
        bp = [px-bx, py-by]
        if min(cos(ab,ap),cos(ac,ap)) > cos(ab,ac) and min(cos(ba,bp),cos(bc,bp)) > cos(ba,bc):
            print("YES")
        else:
            print("NO")
    except:
        break

Solution (Python):

import math
def simul_eq(a,b,c,d,e,f):
    
    C = [c,f]
    detA = a*e - b*d
    
    At = [[e,-b],[-d,a]]
    x = sum(map((lambda x,y: x*y), At[0], C)) / detA
    y = sum(map((lambda x,y: x*y), At[1], C)) / detA
    return (x,y)
ss = input().split()
while 1:
    x1,y1,x2,y2,x3,y3,xp,yp = map(float,ss)
    s,t = simul_eq(x2-x1, x3-x1, xp-x1, y2-y1, y3-y1, yp-y1)
    if 0 < s < 1 and 0 < t < 1 and 0 < s + t < 1:
        print('YES')
    else:
        print('NO')
    try: ss = input().split()
    except EOFError: break