Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		buf := make([]float64, len(input))
		for j := range buf {
			buf[j], _ = strconv.ParseFloat(input[j], 64)
		}
		p1 := complex(buf[0], buf[1])
		p2 := complex(buf[2], buf[3])
		p3 := complex(buf[4], buf[5])
		pk := complex(buf[6], buf[7])
		ps := complex(buf[8], buf[9])
		kin := isAtSameSide(p3, pk, []complex128{p1, p2}) &&
			isAtSameSide(p1, pk, []complex128{p2, p3}) &&
			isAtSameSide(p2, pk, []complex128{p3, p1})
		sin := isAtSameSide(p3, ps, []complex128{p1, p2}) &&
			isAtSameSide(p1, ps, []complex128{p2, p3}) &&
			isAtSameSide(p2, ps, []complex128{p3, p1})
		if (kin || sin) && !(kin && sin) {
			fmt.Println("OK")
		} else {
			fmt.Println("NG")
		}
	}
}

func isAtSameSide(a, b complex128, line []complex128) bool {
	sa := (real(line[1]) - real(line[0]))*(imag(a)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(a))
	sb := (real(line[1]) - real(line[0]))*(imag(b)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(b))
	return (sa > 0 && sb > 0) || (sa < 0 && sb < 0)
}

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


def check(triangle, pt):
    v1 = [triangle[0], triangle[1]]
    v2 = [triangle[2], triangle[3]]
    v3 = [triangle[4], triangle[5]]

    b1 = sign(pt, v1, v2)
    if b1 > 0:
        flag1 = 1
    else:
        flag1 = 0

    b2 = sign(pt, v2, v3)
    if b2 > 0:
        flag2 = 1
    else:
        flag2 = 0

    b3 = sign(pt, v3, v1)
    if b3 > 0:
        flag3 = 1
    else:
        flag3 = 0

    return ((flag1 == flag2) and (flag2 == flag3))


n = int(input())

for _ in range(n):
    query = list(map(int, input().split()))
    triangle = query[0:6]
    hikoboshi = query[6:8]
    orihime = query[8:10]

    check1 = check(triangle, hikoboshi)
    check2 = check(triangle, orihime)
    if check1 == check2:
        print("NG")
    else:
        print("OK")

Python: def side(a, b, c):
  return (c[1]-a[1])*(b[0]-a[0])-(b[1]-a[1])*(c[0]-a[0])>0
def isIn(x):
  return (side(p0, p1, x)==side(p1, p2, x)==side(p2, p0, x))

for _ in [0]*input():
  P = map(int, raw_input().split())
  p0 = P[0:2]
  p1 = P[2:4]
  p2 = P[4:6]
  print ['NG','OK'][isIn(P[6:8])!=isIn(P[8:])]

Python: import numpy as np
def crossP(a, b, c, d):
    e = b - a
    f = c - d
    g = c - a
    A = np.matrix([[e.real,f.real],[e.imag, f.imag]])
    B = np.matrix([[g.real],[g.imag]])
    try:
        C = np.linalg.solve(A, B)
    except:
        return(-9999+(-9999)*1j)
    return(C[0,0]+C[1,0]*1j)

def rangeP(st):
    return((0.0<=st.real<=1.0) and (0.0<=st.imag<=1.0))

if __name__ == '__main__':
	n = int(input().strip())
	for i in range(n):
	    [xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys] = map(int, input().strip().split())
	    a = xp1+yp1*1j
	    b = xp2+yp2*1j
	    c = xp3+yp3*1j
	    k = xk+yk*1j
	    s = xs+ys*1j
	    shut = 0
	    if rangeP(crossP(a,b,k,s)):
	        shut += 1
	    if rangeP(crossP(b,c,k,s)):
	        shut += 1
	    if rangeP(crossP(c,a,k,s)):
	        shut += 1
	    if shut == 1:
	        print("OK")
	    else:
	        print("NG")

Python: EPS=1e-10
def crossP(aa,bb,cc,dd):
    a = (bb-aa).real
    b = (cc-dd).real
    c = (bb-aa).imag
    d = (cc-dd).imag
    e = (cc-aa).real
    f = (cc-aa).imag
    det = a*d - b*c
    if abs(det) <EPS:
        return(-9999+(-9999)*1j)
    x = (d*e-b*f)/det
    y = (-c*e+a*f)/det
    return(x+y*1j)

def rangeP(st):
    return((0.0<=st.real<=1.0) and (0.0<=st.imag<=1.0))

if __name__ == '__main__':
	n = int(input().strip())
	for i in range(n):
	    [xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys] = map(int, input().strip().split())
	    a = xp1+yp1*1j
	    b = xp2+yp2*1j
	    c = xp3+yp3*1j
	    k = xk+yk*1j
	    s = xs+ys*1j
	    shut = 0
	    if rangeP(crossP(a,b,k,s)):
	        shut += 1
	    if rangeP(crossP(b,c,k,s)):
	        shut += 1
	    if rangeP(crossP(c,a,k,s)):
	        shut += 1
	    if shut == 1:
	        print("OK")
	    else:
	        print("NG")

Python: # AOJ 0143 Altair and Vega
# Python3 2018.6.18 bal4u

# a, b, はラインの同一側にあるか
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);
	return (sa > 0 and sb > 0) or (sa < 0 and sb < 0)    # a, b at same side

for i in range(int(input())):
	buf = list(map(int, input().split()))
	p1 = complex(buf[0], buf[1])
	p2 = complex(buf[2], buf[3])
	p3 = complex(buf[4], buf[5])
	pk = complex(buf[6], buf[7])
	ps = complex(buf[8], buf[9])

	kin = is_atSameSide(p3, pk, [p1, p2]) & \
		  is_atSameSide(p1, pk, [p2, p3]) & \
		  is_atSameSide(p2, pk, [p3, p1])
	sin = is_atSameSide(p3, ps, [p1, p2]) & \
		  is_atSameSide(p1, ps, [p2, p3]) & \
		  is_atSameSide(p2, ps, [p3, p1])
	print("OK" if kin ^ sin else "NG")

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int hantei(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy) {
	double x,y,m,n,d;
	if (dx-cx!=0) m=(dy-cy)/(dx-cx);
	if (bx-ax!=0) n=(by-ay)/(bx-ax);
	if (ay==by) {
		if (cy==dy && cy==ay && ((ax>cx && ax<dx) || (ax<cx && ax>dx))) return 1;
		if (cx==dx && ((cx>ax && cx<bx) || (cx>bx && cx<ax)) && ((cy<ay && dy>ay) || (dy<ay && cy>ay))) return 1;
        x=(ay-cy+m*cx)/m;
        if ((x>ax && x<bx) || (x>bx && x<ax)) return 1;
		return 0;
	}
	if (ax==bx) {
        if (cx==dx && cx==ax && (ay>cy && ay<dy || ay<cy && ay>dy)) return 1;
		if (cy==dy && ((cy>ay && cy<by) || (cy>by && cy<ay)) && ((cx<ax && dx>ax) || (dx<ax && cx>ax))) return 1;
        y=cy+m*(ax-cx);
		if ((y>ay && y<by) || (y>by && y<ay)) return 1;
		return 0;
	}
	if (cy==dy) { x=(cy-ay+n*ax)/m;	if ((x>cx && x<dx) || (x>dx && x<cx)) return 1; else return 0; }
	if (cx==dx) { y=ay+n*(cx-ax); cout << y;if ((y>cy && y<dy) || (y>dy && y<cy)) return 1; else return 0;}
	if (m==n) { d=(cy-ay)/(cx-ax); if ((d==m) && ((ax>cx && ax<dx) || (ax>dx && ax<cx))) return 1; else return 0; }
    d=(ay-cy+m*cx-n*ax)/(m-n);
	if ((d>cx && d<dx) || (d>dx && d<cx)) return 1;
	return 0;
}

int main() {
	int n,f;
	double xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
	cin >> n;
	for (;n>0;n--) {
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
        f=hantei(xp1,yp1,xp2,yp2,xk,yk,xs,ys)+hantei(xp2,yp2,xp3,yp3,xk,yk,xs,ys)+hantei(xp1,yp1,xp3,yp3,xk,yk,xs,ys);
		if (f==1) cout << "OK"; else cout << "NG";
		cout << endl;
	}
return 0;
	}