Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



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


Sample output:
YES
NO

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        return(-1,-1)
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >=0 and res[1] >=0 and res[0]+res[1]<1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        return(-1,-1)
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >=0 and res[1] >=0 and res[0]+res[1]<=1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        res_x=c/a;
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >=0 and res[1] >=0 and res[0]+res[1]<=1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        res_x=c/a;
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >=0 and res[1] >=0 and res[0]+res[1]<=1:
    print("YES ")
else:
    print("NO ")

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        res_x=c/a;
        return(res_x,0)
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >=0 and res[1] >=0 and res[0]+res[1]<=1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        res_x=c/a;
        return(res_x,0)
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >0 and res[1] >0 and res[0]+res[1]<1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:

x1,y1,x2,y2,x3,y3,xp,yp=[float(p) for p in input().split()]

x_vector_1to2=x2-x1;
y_vector_1to2=y2-y1;
x_vector_1to3=x3-x1;
y_vector_1to3=y3-y1;
x_vector_p=xp-x1;
y_vector_p=yp-y1;

def renritu(p,q,r,s,t,u):  # renritu(p,q,r,s,t,u) px + qy = r  sx+ty=u
    a=p; b=q; c=r; d=s; e=t; f=u;
    a1=a*d; b1=b*d; c1=c*d; d1=d*a; e1=e*a; f1=f*a;
    res_y=b1-e1;
    if res_y != 0 :
        res_y =(c1-f1)/res_y;
        res_x =(c-b*res_y)/a;
        return(res_x,res_y)
    else:
        return(-1,-1)
    
res=renritu(x_vector_1to2,x_vector_1to3,x_vector_p,y_vector_1to2,y_vector_1to3,y_vector_p)
if res[0] >0 and res[1] >0 and (res[0]+res[1])<1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
g=lambda a,b:a[0]*b[1]-a[1]*b[0]

while True:
    try:l=[float(i) for i in input().split()]
    except:break
    ba=[l[0]-l[2],l[1]-l[3]]
    ab=[-i for i in ba]
    cb=[l[2]-l[4],l[3]-l[5]]
    bc=[-i for i in cb]
    ca=[l[0]-l[4],l[1]-l[5]]
    ac=[-i for i in ca]
    ap=[l[6]-l[0],l[7]-l[1]]
    bp=[l[6]-l[2],l[7]-l[3]]
    cp=[l[6]-l[4],l[7]-l[5]]
    if g(ab,ac)<g(ab,ap) or g(ba,bc)<g(ba,bp):
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

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

while True:
    try:t=input()
    except:break
    l=[float(i) for i in t.split()]
    ba=[l[0]-l[2],l[1]-l[3]]
    ab=[-i for i in ba]
    cb=[l[2]-l[4],l[3]-l[5]]
    bc=[-i for i in cb]
    ca=[l[0]-l[4],l[1]-l[5]]
    ac=[-i for i in ca]
    ap=[l[6]-l[0],l[7]-l[1]]
    bp=[l[6]-l[2],l[7]-l[3]]
    cp=[l[6]-l[4],l[7]-l[5]]
    if g(ab,ac)<g(ab,ap) or g(ba,bc)<g(ba,bp) or g(ca,cb)<g(ca,cp):
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
g=lambda a,b:a[0]*b[1]-a[1]*b[0]

while True:
    try:t=input()
    except:break
    l=[float(i) for i in t.split()]
    ba=[l[0]-l[2],l[1]-l[3]]
    ab=[-i for i in ba]
    cb=[l[2]-l[4],l[3]-l[5]]
    bc=[-i for i in cb]
    ca=[l[0]-l[4],l[1]-l[5]]
    ac=[-i for i in ca]
    ap=[l[6]-l[0],l[7]-l[1]]
    bp=[l[6]-l[2],l[7]-l[3]]
    cp=[l[6]-l[4],l[7]-l[5]]
    p=[g(ab,ac) , g(ab,ap) , g(ba,bc) , g(ba,bp) , g(ca,cb) , g(ca,cp)]
    if p[0]*p[1]<0 or p[2]*p[3]<0 or p[4]<p[5]<0 or abs(p[0])<abs(p[1]) or abs(p[2])<abs(p[3]) or abs(p[4])<abs(p[5]):
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
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):
    for a, b in ((p1, p2), (p2, p3), (p3, p1)):
        vec1 = sub(a, b)
        vec2 = sub(a, pp)
        if cross_product(vec2, vec1) >= 0:
            print("NO")
            return
    print("YES")


if __name__ == '__main__':
    inputs = [float(s) for s in input().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)

Submission status: Wrong Answer

Solution code:
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__':
    inputs = [float(s) for s in input().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)

Submission status: Wrong Answer

Solution code:
def f(x):
    x1, y1, x2, y2, x3, y3, xp, yp = x
    if not x2 == x1:
        a1 = ((y2 - y1) / (x2 - x1)) * (xp -x1) + y1
    else:
        a1 = x1
    if not x3 == x1:
        a2 = ((y3 - y1) / (x3 - x1)) * (xp - x1) + y1
    else:
        a2 = x1
    if not x3 == x2:
        a3 = ((y3 - y2) / (x3 - x2)) * (xp - x2) + y2
    else:
        a3 = x2

    if (yp > a1 and yp < a2 and yp < a3) or (yp < a1 and yp > a2 and yp < a3) or (yp < a1 and yp < a2 and yp > a3):
        print('YES')
    else:
        print('NO')
while True:
    try:
        point = list(map(float, input().split()))
        f(point)
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
def f(x):
    x1, y1, x2, y2, x3, y3, xp, yp = x
    ax = x3 - x1
    ay = y3 - y1
    bx = x2 - x1
    by = y2 - 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

Submission status: Wrong Answer

Solution code:
import sys

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

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 = int(x / abs(x))
	for i in l[1:]:
		y = ccw(i[0], i[1], p)
		if y != 0:
			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)

Submission status: Wrong Answer

Solution code:
import sys

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

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)

Submission status: Wrong Answer

Solution code:
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):
	if any(ccw(i[0], i[1], p) == ccw(l[0][0], l[0][1], p) 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)

Submission status: Wrong Answer

Solution code:
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), x) 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(complex, t[0::2], t[1::2])
	solve([(a, b), (b, c), (c, a)], p)

Submission status: Wrong Answer

Solution code:
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)]
        sorted(cross)
        if (cross[2]>0 and cross[0]>0) or (cross[2]<0 and cross[0]<0): 
            print "YES"
        else:
            print "NO"
    except:
        pass
#temp

Submission status: Wrong Answer

Solution code:
import sys

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

for i in sys.stdin:
    l = [float(x.rstrip()) for x in i.split()]
    if len(l) is 8:
        a,b,c,p = [l[:2],l[2:4],l[4:6],l[6:]]

        if cross(a,b,p)<=0 and cross(b,c,p)<=0 and cross(c,a,p)<=0 :
            print "YES"
        elif cross(a,b,p)>=0 and cross(b,c,p)>=0 and cross(c,a,p)>=0 :
            print "YES"
        else:
            print "N0"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,px,py = map(float,raw_input().split(' '))
        v1 = [x1-px,y1-py]
        v2 = [x2-px,y2-py]
        v3 = [x3-px,y3-py]
        v12 =[v1[0]+v2[0],v1[1]+v2[1]]
        if v12[0]*v3[0]+v12[1]*v3[1] < 0:
            print 'YES'
        else:
            print 'NO'
 
    except ValueError:
        break

Submission status: Wrong Answer

Solution code:
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)
    #cross
    def __mul__(left, right):
        return left.x * right.x + left.y * right.y

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)
        c2 = (p23 * pp2 < 0)
        c3 = (p31 * pp3 < 0)
        if(c1 ^ c2 or c2 ^ c3):
            print 'NO'
        else:
            print 'YES'
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
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)
    #cross
    def __mul__(left, right):
        return left.x * right.x + left.y * right.y

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

Submission status: Wrong Answer

Solution code:
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)
    #cross
    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

Submission status: Wrong Answer

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    sets = [float(s) for s in line.split()]
    xa, xb = sorted(sets[:5:2])[::2]
    ya, yb = sorted(sets[1:6:2])[::2]
    if xa < sets[6] < xb and ya < sets[7] < yb:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
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())

    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')

Submission status: Wrong Answer

Solution code:
ans=[]
def inside(t1x,t1y,t2x,t2y,t3x,t3y,px,py):
    if ((t1x-t2x) * (t3y-t1y) + (t1y-t2y)* (t1x-t3x))*((t1x-t2x) * (py-t1y) + (t1y-t2y) * (t1x-px)) > 0:
        return False
    else:
        return True
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,raw_input().split())
    except EOFError:
        break
    if not (
            inside(x1,y1,x2,y2,x3,y3,xp,yp) and 
            inside(x1,y1,x2,y2,x3,y3,xp,yp) and 
            inside(x1,y1,x2,y2,x3,y3,xp,yp)
            ):
        ans.append("YES")
    else:
        ans.append("NO")


for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
import sys
def inp(a,b): return a[0]*b[0]+a[1]*b[1]
def area(a,b): return inp(a,a)*inp(b,b) - inp(a,b)
for line in sys.stdin:
    [x1,y1,x2,y2,x3,y3,xp,yp] = [float(x) for x in line.split()]
    ap = [x1-xp,y1-yp]
    bp = [x2-xp,y2-yp]
    cp = [x3-xp,y3-yp]
    s = [x1-x2,y1-y2]
    t = [x1-x3,y1-y3]
    res = (area(s,t) >= (area(ap,bp) + area(ap,cp) + area(bp,cp)))
    print area(s,t)
    print area(ap,bp) + area(ap,cp) + area(bp,cp)
    print "YES" if res else "NO"

Submission status: Wrong Answer

Solution code:
import sys
def inp(a,b): return a[0]*b[0]+a[1]*b[1]
def area(a,b): return inp(a,a)*inp(b,b) - inp(a,b)
for line in sys.stdin:
    [x1,y1,x2,y2,x3,y3,xp,yp] = [float(x) for x in line.split()]
    ap = [x1-xp,y1-yp]
    bp = [x2-xp,y2-yp]
    cp = [x3-xp,y3-yp]
    s = [x1-x2,y1-y2]
    t = [x1-x3,y1-y3]
    res = (area(s,t) >= (area(ap,bp) + area(ap,cp) + area(bp,cp)))
    print "YES" if res else "NO"

Submission status: Wrong Answer

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

        a = [x1-xp,y1-yp]
        b = [x2-xp,y2-yp]
        c = [x3-xp,y3-yp]

        j1 = a[0]*b[0]+a[1]*b[1]
        j2 = b[0]*c[0]+b[1]*c[1]
        j3 = a[0]*c[0]+a[1]*c[1]
        j = [j1,j2,j3]

        count = 0

        for jug in j:
            if jug < 0:
                count += 1

        if count >= 2:
            print 'YES'
        else:
            print 'NO'

    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def dist2(p1, p2):
    return (p1[0] - p2[0])**2 + (p1[1] - p2[1])**2

def MinDistIdx(nodes, point):
    Min = dist2(nodes[0], point)
    idx = 0
    if dist2(nodes[1], point) < Min:
        Min = dist2(nodes[1], point)
        idx = 1
    if dist2(nodes[2], point) < Min:
        Min = dist2(nodes[2], point)
        idx = 2
    return idx        

lineNumber = 0
#for line in [ "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"]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # get data
    List = map(float, line.strip().split())

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

    idx = MinDistIdx(nodes, point)
    distsum = [0, 0]
    for i in xrange(3):
        if i == idx: continue
        distsum[0] += dist2(nodes[i], point)
        distsum[1] += dist2(nodes[i], nodes[idx])

    if distsum[0] < distsum[1]: print "YES"
    else                      : print "NO"

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def dist2(p1, p2):
    return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5

def MinDistIdx(nodes, point):
    Min = dist2(nodes[0], point)
    idx = 0
    if dist2(nodes[1], point) < Min:
        Min = dist2(nodes[1], point)
        idx = 1
    if dist2(nodes[2], point) < Min:
        Min = dist2(nodes[2], point)
        idx = 2
    return idx        

lineNumber = 0
#for line in [ "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"]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # get data
    List = map(float, line.strip().split())

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

    idx = MinDistIdx(nodes, point)
    distsum = [0, 0]
    for i in xrange(3):
        if i == idx: continue
        distsum[0] += dist2(nodes[i], point)
        distsum[1] += dist2(nodes[i], nodes[idx])

    if distsum[0] < distsum[1]: print "YES"
    else                      : print "NO"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = (x1-x2)**2+(y1-y2)**2
        b = (x1-x3)**2+(y1-y3)**2
        c = (x2-x3)**2+(y2-y3)**2
        xa = (x3-xp)**2+(y3-yp)**2
        xb = (x2-xp)**2+(y2-yp)**2
        xc = (x1-xp)**2+(y1-yp)**2
        cosa = 2*math.sqrt(b)*math.sqrt(c)/(b+c)
        cosb = 2*math.sqrt(a)*math.sqrt(c)/(a+c)
        cosc = 2*math.sqrt(a)*math.sqrt(b)/(a+b)
        cos1 = 2*math.sqrt(xa)*math.sqrt(b)/(xa+b)
        cos2 = 2*math.sqrt(xb)*math.sqrt(c)/(xb+c)    
        cos3 = 2*math.sqrt(xc)*math.sqrt(a)/(xc+a)
        
        if cos1<cosa or cos2<cosb or cos3<cosc:
            print "YES"
        else:
            print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = (x1-x2)**2+(y1-y2)**2
        b = (x1-x3)**2+(y1-y3)**2
        c = (x2-x3)**2+(y2-y3)**2
        xa = (x3-xp)**2+(y3-yp)**2
        xb = (x2-xp)**2+(y2-yp)**2
        xc = (x1-xp)**2+(y1-yp)**2
        cosa = 2*math.sqrt(b)*math.sqrt(c)/(b+c)
        cosb = 2*math.sqrt(a)*math.sqrt(c)/(a+c)
        cosc = 2*math.sqrt(a)*math.sqrt(b)/(a+b)
        cos1 = 2*math.sqrt(xa)*math.sqrt(b)/(xa+b)
        cos2 = 2*math.sqrt(xb)*math.sqrt(c)/(xb+c)    
        cos3 = 2*math.sqrt(xc)*math.sqrt(a)/(xc+a)
        cos4 = 2*math.sqrt(xa)*math.sqrt(c)/(xa+c)
        cos5 = 2*math.sqrt(xb)*math.sqrt(a)/(xb+a)
        cos6 = 2*math.sqrt(xc)*math.sqrt(b)/(xc+b)
        
        if cos1<cosa or cos2<cosb or cos3<cosc:
            print "YES"
        elif cos4<cosa or cos5<cosb or cos6<cosc:
            print "YES"
        else:
            print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = (x1-x2)**2+(y1-y2)**2
        b = (x1-x3)**2+(y1-y3)**2
        c = (x2-x3)**2+(y2-y3)**2
        xa = (x3-xp)**2+(y3-yp)**2
        xb = (x2-xp)**2+(y2-yp)**2
        xc = (x1-xp)**2+(y1-yp)**2
        cosa = (a-b+c)/(2*math.sqrt(b)*math.sqrt(c))
        cosb = (b-a+c)/(2*math.sqrt(a)*math.sqrt(c))
        cosc = (c-a+b)/(2*math.sqrt(a)*math.sqrt(b))
        cos1 = (xc-xa+b)/(2*math.sqrt(xa)*math.sqrt(b))
        cos2 = (xa-xb+c)/(2*math.sqrt(xb)*math.sqrt(c))
        cos3 = (xb-xc+a)/(2*math.sqrt(xc)*math.sqrt(a))
        
        if cos1<cosa or cos2<cosb or cos3<cosc:
            print "YES"
        else:
            print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = (x1-x2)**2+(y1-y2)**2
        b = (x1-x3)**2+(y1-y3)**2
        c = (x2-x3)**2+(y2-y3)**2
        xa = (x3-xp)**2+(y3-yp)**2
        xb = (x2-xp)**2+(y2-yp)**2
        xc = (x1-xp)**2+(y1-yp)**2
        cosa = -(a-b+c)/(2*math.sqrt(b)*math.sqrt(c))
        cosb = -(b-a+c)/(2*math.sqrt(a)*math.sqrt(c))
        cosc = -(c-a+b)/(2*math.sqrt(a)*math.sqrt(b))
        cos1 = -(xc-xa+b)/(2*math.sqrt(xa)*math.sqrt(b))
        cos2 = -(xa-xb+c)/(2*math.sqrt(xb)*math.sqrt(c))
        cos3 = -(xb-xc+a)/(2*math.sqrt(xc)*math.sqrt(a))
        
        if cos1<cosa or cos2<cosb or cos3<cosc:
            print "YES"
        else:
            print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = (x1-x2)**2+(y1-y2)**2
        b = (x1-x3)**2+(y1-y3)**2
        c = (x2-x3)**2+(y2-y3)**2
        xa = (x3-xp)**2+(y3-yp)**2
        xb = (x2-xp)**2+(y2-yp)**2
        xc = (x1-xp)**2+(y1-yp)**2
        cosa = -(a-b+c)/(2*math.sqrt(b)*math.sqrt(c))
        cosb = -(b-a+c)/(2*math.sqrt(a)*math.sqrt(c))
        cosc = -(c-a+b)/(2*math.sqrt(a)*math.sqrt(b))
        cos1 = -(xc-xa+b)/(2*math.sqrt(xa)*math.sqrt(b))
        cos2 = -(xa-xb+c)/(2*math.sqrt(xb)*math.sqrt(c))
        cos3 = -(xb-xc+a)/(2*math.sqrt(xc)*math.sqrt(a))
        
        if cos1<=cosa or cos2<=cosb or cos3<=cosc:
            print "YES"
        else:
            print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())
        l = [sorted([x1, x2, x3]), sorted([y1, y2, y3])]
        if (xp > l[0][0]) and (xp < l[0][2]) and (yp > l[1][0]) and (yp <l[1][2]):
            print "YES"
        else:
            print "NO"
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import math, sys

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

def area(x1, y1, x2, y2, x3, y3):
  a = length(x1, y1, x2, y2)
  b = length(x2, y2, x3, y3)
  c = length(x3, y3, x1, y1)
  s = (a + b + c)/2.0
  return math.sqrt(s*(s - a)*(s - b)*(s - c))

for s in sys.stdin:
  x1, y1, x2, y2, x3, y3, xp, yp = map(float, s.split(' '))
  s_all = area(x1, y1, x2, y2, x3, y3)
  s1 = area(x1, y1, x2, y2, xp, yp)
  s2 = area(x2, y2, x3, y3, xp, yp)
  s3 = area(x3, y3, x1, y1, xp, yp)

  if math.fabs(s_all - (s1 + s2 + s3)) <= 0.000000001:
    print 'YES'
  else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
import math

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

def area(x1, y1, x2, y2, x3, y3):
  a = length(x1, y1, x2, y2)
  b = length(x2, y2, x3, y3)
  c = length(x3, y3, x1, y1)
  s = (a + b + c)/2.0
  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(' '))
    s_all = area(x1, y1, x2, y2, x3, y3)
    s1 = area(x1, y1, x2, y2, xp, yp)
    s2 = area(x2, y2, x3, y3, xp, yp)
    s3 = area(x3, y3, x1, y1, xp, yp)

    if math.fabs(s_all - (s1 + s2 + s3)) <= 0.000000001:
      print 'YES'
    else:
      print 'NO'
  except:
    break

Submission status: Wrong Answer

Solution code:
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(x2, y2, x3, y3)
    c = L(x3, y3, x1, y1)
    p1 = L(x1, y1, xp, yp)
    p2 = L(x2, y2, xp, yp)
    p3 = L(x3, y3, xp, yp)

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

Submission status: Time Limit Exceeded

Solution code:
while True:
 try:
  x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split())
  if xp<0 or yp<0:
    print('No')
  else:
    print('Yes')
 except: pass

Submission status: Accepted

Solution code:
import sys

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

    def __repr__(self):
        return 'P:{0:.3f} {1:.3f}'.format(self.x, self.y)

class Line(object):
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2
        self.epsilon = 1e-8

    def is_over(self, p):
        if abs(self.p2.x - self.p1.x) < self.epsilon:
            return self.p1.x > p.x
        elif abs(self.p2.y - self.p1.y) < self.epsilon:
            return self.p1.y > p.y
        else:
            a = (self.p2.y - self.p1.y) / (self.p2.x - self.p1.x)
            b = self.p1.y
            y = a * (p.x - self.p1.x) + b
            return y > p.y

def run():
    for i in sys.stdin:
        x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, i.split()))
        p1, p2, p3, p = P(x1, y1), P(x2, y2), P(x3, y3), P(xp, yp)
        l_12 = Line(p1, p2)
        l_23 = Line(p2, p3)
        l_31 = Line(p3, p1)

        res = l_12.is_over(p3) == l_12.is_over(p)
        res &= l_23.is_over(p1) == l_23.is_over(p)
        res &= l_31.is_over(p2) == l_31.is_over(p)

        if res:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    run()