Problem:
Counter-Clockwise   For given three points p0, p1, p2 , print COUNTER_CLOCKWISE if p0, p1, p2 make a counterclockwise turn (1), CLOCKWISE if p0, p1, p2 make a clockwise turn (2), ONLINE_BACK if p2 is on a line p2, p0, p1 in this order (3), ONLINE_FRONT if p2 is on a line p0, p1, p2 in this order (4), ON_SEGMENT if p2 is on a segment p0p1 (5). Input  x p0  y p0  x p1  y p1  q  x p2 0  y p2 0  x p2 1  y p2 1 ... x p2 q-1  y p2 q-1  In the first line, integer coordinates of p0 and p1 are given. Then, q queries are given for integer coordinates of p2 . Output For each query, print the above mentioned status. Constraints   1 ≤ q ≤ 1000    -10000 ≤ x i , y i ≤ 10000    p0 and p1 are not identical.  Sample Input 1 0 0 2 0
2
-1 1
-1 -1 Sample Output 1 COUNTER_CLOCKWISE
CLOCKWISE Sample Input 2 0 0 2 0
3
-1 0
0 0
3 0 Sample Output 2 ONLINE_BACK
ON_SEGMENT
ONLINE_FRONT

Solution (Python):
import cmath
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



INF = float("inf")
PI = cmath.pi
TAU = cmath.pi * 2
EPS = 1e-10

class Point:
    """
    2次元空間上の点
    """

    
    CCW_COUNTER_CLOCKWISE = 1
    
    CCW_CLOCKWISE = -1
    
    CCW_ONLINE_BACK = 2
    
    CCW_ONLINE_FRONT = -2
    
    CCW_ON_SEGMENT = 0

    def __init__(self, x: float, y: float):
        self.c = complex(x, y)

    @property
    def x(self):
        return self.c.real

    @property
    def y(self):
        return self.c.imag

    @staticmethod
    def from_complex(c: complex):
        return Point(c.real, c.imag)

    @staticmethod
    def from_polar(r: float, phi: float):
        c = cmath.rect(r, phi)
        return Point(c.real, c.imag)

    def __add__(self, p):
        """
        :param Point p:
        """
        c = self.c + p.c
        return Point(c.real, c.imag)

    def __iadd__(self, p):
        """
        :param Point p:
        """
        self.c += p.c
        return self

    def __sub__(self, p):
        """
        :param Point p:
        """
        c = self.c - p.c
        return Point(c.real, c.imag)

    def __isub__(self, p):
        """
        :param Point p:
        """
        self.c -= p.c
        return self

    def __mul__(self, f: float):
        c = self.c * f
        return Point(c.real, c.imag)

    def __imul__(self, f: float):
        self.c *= f
        return self

    def __truediv__(self, f: float):
        c = self.c / f
        return Point(c.real, c.imag)

    def __itruediv__(self, f: float):
        self.c /= f
        return self

    def __repr__(self):
        return "({}, {})".format(round(self.x, 10), round(self.y, 10))

    def __neg__(self):
        c = -self.c
        return Point(c.real, c.imag)

    def __eq__(self, p):
        return abs(self.c - p.c) < EPS

    def __abs__(self):
        return abs(self.c)

    @staticmethod
    def ccw(a, b, c):
        """
        線分 ab に対する c の位置
        線分上にあるか判定するだけなら on_segment とかのが速い
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
        :param Point a:
        :param Point b:
        :param Point c:
        """
        b = b - a
        c = c - a
        det = b.det(c)
        if det > EPS:
            return Point.CCW_COUNTER_CLOCKWISE
        if det < -EPS:
            return Point.CCW_CLOCKWISE
        if b.dot(c) < -EPS:
            return Point.CCW_ONLINE_BACK
        if b.dot(b - c) < -EPS:
            return Point.CCW_ONLINE_FRONT
        return Point.CCW_ON_SEGMENT

    def dot(self, p):
        """
        内積
        :param Point p:
        :rtype: float
        """
        return self.x * p.x + self.y * p.y

    def det(self, p):
        """
        外積
        :param Point p:
        :rtype: float
        """
        return self.x * p.y - self.y * p.x


x1, y1, x2, y2 = list(map(int, sys.stdin.buffer.readline().split()))
Q = int(sys.stdin.buffer.readline())
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

p1 = Point(x1, y1)
p2 = Point(x2, y2)
for x3, y3 in XY:
    ccw = Point.ccw(p1, p2, Point(x3, y3))
    if ccw == Point.CCW_COUNTER_CLOCKWISE:
        print('COUNTER_CLOCKWISE')
    if ccw == Point.CCW_CLOCKWISE:
        print('CLOCKWISE')
    if ccw == Point.CCW_ONLINE_BACK:
        print('ONLINE_BACK')
    if ccw == Point.CCW_ONLINE_FRONT:
        print('ONLINE_FRONT')
    if ccw == Point.CCW_ON_SEGMENT:
        print('ON_SEGMENT')

Solution (Python):



COUNTER_CLOCKWISE = 1
CLOCKWISE = -1
ONLINE_BACK = 2
ONLINE_FRONT = -2
ON_SEGMENT = 0

EPS = 0.0000000001

class Point:
    
    global EPS
    
    def __init__(self, x = 0, y = 0):
        self.x = x
        self.y = y
        
        
    def __add__(a, b):
        s = a.x + b.x
        t = a.y + b.y
        return Point(s, t)
        
    def __sub__(a, b):
        s = a.x - b.x
        t = a.y - b.y
        return Point(s, t)
            
    def __mul__(self, a):
        s = a * self.x
        t = a * self.y
        return Point(s, t)
        
    def __truediv__(self, a):
        s = self.x / a
        t = self.y / a
        return Point(s, t)
            
            
            
            
    def norm(self):
        return self.x * self.x + self.y * self.y
        
    def abs(self):
        return self.norm() ** 0.5
            
    
            
            
    def __eq__(self, other):
        return abs(self.x - other.y) < self.EPS and abs(self.y - other.y) < self.EPS
            
            
            
    def dot(self, b):
        return self.x * b.x + self.y * b.y
        
    def cross(self, b):
        return self.x * b.y - self.y * b.x
    
    
class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def ccw(p0, p1, p2):
    a = p1-p0
    b = p2-p0
    
    if a.cross(b) > 0:
        return COUNTER_CLOCKWISE
    elif a.cross(b) <0:
        return CLOCKWISE
    elif a.dot(b) < 0:
        return ONLINE_BACK
    elif a.abs() < b.abs():
        return ONLINE_FRONT
    else:
        return ON_SEGMENT
        
        
nums=list(map(int,input().split()))
p1 = Point(nums[0], nums[1])
p2 = Point(nums[2], nums[3])
n = int(input())
for i in range(n):
    nums=list(map(int,input().split()))
    p = Point(nums[0], nums[1])
    result = ccw(p1, p2, p)
    if result == COUNTER_CLOCKWISE:
        print("COUNTER_CLOCKWISE")
    elif result == CLOCKWISE:
        print("CLOCKWISE")
    elif result == ONLINE_BACK:
        print("ONLINE_BACK")
    elif result == ONLINE_FRONT:
        print("ONLINE_FRONT")
    elif result == ON_SEGMENT:
        print("ON_SEGMENT")

Solution (Python):


from math import sqrt


class Vector:
    def __init__(self, ls):
        '''
        ls ... list
        '''
        self.vec = ls

    def __len__(self):
        return len(self.vec)

    def __getitem__(self, idx):
        return self.vec[idx]

    def __repr__(self):
        return f'Vector({self.vec})'

    def add(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a + b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def sub(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a - b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def mul(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a * b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def norm(self):
        tmp = sum([x * x for x in self.vec])
        return sqrt(tmp)


def norm(vec):
    '''
    vec ... Vector class
    '''
    return vec.norm()


def cross(a, b):
    '''
    Outer product for 2d
    a,b ... Vector class
    '''
    assert len(a) == 2 and len(b) == 2
    first = a[0] * b[1]
    second = a[1] * b[0]
    return first - second


def dot(a, b):
    return sum(a.mul(b))


EPS = 1e-10


def ccw(p0, p1, p2):
    '''
    問題を解くための関数
    引数はすべてVector
    '''
    a = p1.sub(p0)
    b = p2.sub(p0)
    if cross(a, b) > EPS:
        return 'COUNTER_CLOCKWISE'
    elif cross(a, b) < -EPS:
        return 'CLOCKWISE'
    elif dot(a, b) < 0:  
        return 'ONLINE_BACK'
    elif a.norm() < b.norm():  
        return 'ONLINE_FRONT'
    else:
        return 'ON_SEGMENT'



x0, y0, x1, y1 = list(map(int, input().split()))
N = int(input())
p0 = Vector([x0, y0])
p1 = Vector([x1, y1])
for _ in range(N):
    x2, y2 = list(map(int, input().split()))
    p2 = Vector([x2, y2])
    print(ccw(p0, p1, p2))

Solution (Python):


import array
from fractions import Fraction
import math
import os
import sys


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

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

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

    def __mul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __rmul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __truediv__(self, scalar):
        return Vec(self.x / scalar, self.y / scalar)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __imul__(self, scalar):
        self.x *= scalar
        self.y *= scalar
        return self

    def __idiv__(self, scalar):
        self.x /= scalar
        self.y /= scalar
        return self

    def __neg__(self):
        return Vec(-self.x, -self.y)

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    def cross(self, other):
        return self.x * other.y - self.y * other.x

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

    def __abs__(self):
        return math.sqrt(float(self.abs2()))

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)


def main():
    x1, y1, x2, y2 = read_ints()
    Q = read_int()
    for _ in range(Q):
        x, y = read_ints()
        print(solve(Vec(x1, y1), Vec(x2, y2), Vec(x, y)))


CCW = 'COUNTER_CLOCKWISE'
CW = 'CLOCKWISE'
OLB = 'ONLINE_BACK'
OLF = 'ONLINE_FRONT'
OL = 'ON_SEGMENT'


def solve(u, v, a):
    v -= u
    a -= u
    c = v.cross(a)
    if c > 0:
        return CCW
    if c < 0:
        return CW
    d = v.dot(a)
    if d < 0:
        return OLB
    if v.abs2() < a.abs2():
        return OLF
    return OL





DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Solution (Python):


import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

class Geometry:

    EPS = 10 ** -9

    def add(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1+x2, y1+y2)

    def sub(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1-x2, y1-y2)

    def mul(self, a, b):
        x1, y1 = a
        if not isinstance(b, tuple):
            return (x1*b, y1*b)
        x2, y2 = b 
        return (x1*x2, y1*y2)

    def norm(self, a):
        x, y = a
        return x**2 + y**2

    def dot(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*x2 + y1*y2

    def cross(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*y2 - y1*x2

    def project(self, seg, p):
        """ 線分segに対する点pの射影 """
        p1, p2 = seg
        base = self.sub(p2, p1)
        r = self.dot(self.sub(p, p1), base) / self.norm(base)
        return self.add(p1, self.mul(base, r))

    def reflect(self, seg, p):
        """ 線分segを対称軸とした点pの線対称の点 """
        return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2))

    def ccw(self, p0, p1, p2):
        """ 線分p0,p1から線分p0,p2への回転方向 """
        a = self.sub(p1, p0)
        b = self.sub(p2, p0)
        
        if self.cross(a, b) > self.EPS: return 1
        
        if self.cross(a, b) < -self.EPS: return -1
        
        if self.dot(a, b) < -self.EPS: return 2
        
        if self.norm(a) < self.norm(b): return -2
        
        return 0

gm = Geometry()
x1, y1, x2, y2 = MAP()
a, b = (x1, y1), (x2, y2)
Q = INT()
for i in range(Q):
    x3, y3  = MAP()
    res = gm.ccw(a, b, (x3, y3))
    if res == 1:
        print('COUNTER_CLOCKWISE')
    elif res == -1:
        print('CLOCKWISE')
    elif res == 2:
        print('ONLINE_BACK')
    elif res == -2:
        print('ONLINE_FRONT')
    elif res == 0:
        print('ON_SEGMENT')

Solution (Python):
if __name__ == "__main__":
    x_p0, y_p0, x_p1, y_p1 = map(lambda x: int(x), input().split())
    q = int(input())

    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    p0p1 = p1 - p0

    for _ in range(q):
        x_p2, y_p2 = map(lambda x: int(x), input().split())
        p2 = complex(x_p2, y_p2)
        p0p2 = p2 - p0
        
        sin_theta_val = p0p1.real * p0p2.imag - p0p1.imag * p0p2.real

        if abs(sin_theta_val) < 1e-9:
            if 0 <= p0p1.real * p0p2.real and 0 <= p0p1.imag * p0p2.imag:
                if abs(p0p1) < abs(p0p2):
                    print("ONLINE_FRONT")
                else:
                    print("ON_SEGMENT")
            else:
                print("ONLINE_BACK")
        else:
            if 0 < sin_theta_val:
                print("COUNTER_CLOCKWISE")
            else:
                print("CLOCKWISE")

Solution (Python):
x0,y0,x1,y1 = map(int, input().split( ))
p0 = [x0,y0]
p1= [x1,y1]
v1 =[p1[0]-p0[0],p1[1]-p0[1]]
q = int(input())
def cross(a,b):
    crs = a[0]*b[1] - a[1]*b[0]
    return crs
def dot(a,b):
    dt = a[0]*b[0] + a[1]*b[1]
    return dt
eps = 0.000001
for i in range(q):
    p2 = list(map(int, input().split( )))
    v2=[p2[0]-p0[0],p2[1]-p0[1]]
    if cross(v1,v2) >eps:
        print("COUNTER_CLOCKWISE")
    elif cross(v1,v2) <-eps:
        print("CLOCKWISE")
    elif dot(v1,v2)<-eps:
        print("ONLINE_BACK")
    elif v1[0]**2+v1[1]**2 < v2[0]**2+v2[1]**2:
        print("ONLINE_FRONT")
    else:
        print("ON_SEGMENT")

Solution (Python):
import math,sys
try: sys.stdin = open('in.in','r')
except: pass

class Point:
	def __init__(self,x,y):
		self.x = x
		self.y = y
	def __add__(self,p):
		return Point(self.x+p.x,self.y+p.y)
	def __sub__(self,p):
		return Point(self.x-p.x,self.y-p.y)
	def __mul__(self,p):
		return Point(self.x*p,self.y*p)

def Dot(a,b):
	return a.x*b.x + a.y*b.y
def Cross(a,b):
	return a.x*b.y - a.y*b.x
def Dis(a,b):
	return math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) )
def Dis2(a,b):
	return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)

x0,y0,x1,y1 = map(int,input().split())
p0 = Point(x0,y0)
p1 = Point(x1,y1)
q = int(input())
for i in range(q):
	x2,y2 = map(int,input().split())
	p2 = Point(x2,y2)

	cross = Cross(p1-p0,p2-p0)
	if cross > 0:
		print('COUNTER_CLOCKWISE')
	elif cross < 0:
		print('CLOCKWISE')
	else:
		dot = Dot(p1-p0,p2-p0)
		if dot < 0:
			print('ONLINE_BACK')
		else:
			len1 = Dis2(p1,p0)
			len2 = Dis2(p2,p0)
			print( 'ONLINE_FRONT' if len1 < len2 else 'ON_SEGMENT' )

Solution (Python):
import cmath
EPS = 1e-4


def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag


def InnerProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.real


def IsOnSegment(point, begin, end):
	if abs(OuterProduct(begin-point, end-point)) <= EPS and InnerProduct(begin-point, end-point) <= EPS:
		return True
	else:
		return False



def CCW(p, q, r):
	one, two = q-p, r-q
	if OuterProduct(one, two) > -EPS:
		return True
	else:
		return False

def solve(p, q, r):
	if abs(OuterProduct(q-r, p-r)) <= EPS:
		if InnerProduct(q-r, p-r) <= EPS:
			return "ON_SEGMENT"
		elif abs(p-r) < abs(q-r):
			return "ONLINE_BACK"
		else:
			return "ONLINE_FRONT"
	elif CCW(p, q, r):
		return "COUNTER_CLOCKWISE"
	else:
		return "CLOCKWISE"

a, b, c, d = map(int, input().split())
p, q = complex(a, b), complex(c, d)
n = int(input())
for _ in range(n):
	x, y = map(int, input().split())
	r = complex(x, y)
	print(solve(p, q, r))

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())




def sgn(a):
    if a < -eps: return -1
    if a >  eps: return  1
    return 0

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

    def tolist(self):
        return [self.x,self.y]

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

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

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

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

    def __lt__(self,other):
        tmp = sgn(self.x - other.x)
        if tmp != 0:
            return tmp < 0
        else:
            return sgn(self.y - other.y) < 0

    def __eq__(self,other):
        return sgn(self.x - other.x) == 0 and sgn(self.y - other.y) == 0

    def abs(self):
        return math.sqrt(self.x**2+self.y**2)

    def dot(self,p):
        return self.x * p.x + self.y*p.y

    def det(self,p):
        return self.x * p.y - self.y*p.x

    def arg(self,p):
        return math.atan2(y,x)


def iSP(a,b,c):
    tmp = sgn((b-a).det(c-a))
    if tmp > 0:   return 1   
    elif tmp < 0: return -1  
    else: 
        if sgn((b-a).dot(c-a)) < 0: return -2 
        if sgn((a-b).dot(c-b)) < 0: return  2 
        return 0 


def isToleranceLine(a,b,c,d):
    if sgn((b-a).det(c-d)) != 0: return 1 
    else:
        if sgn((b-a).det(c-a)) != 0: return 0 
        else: return -1 


def isToleranceSegline(a,b,c,d):
    return sgn(iSP(a,b,c)*iSP(a,b,d))<=0 and sgn(iSP(c,d,a)*iSP(c,d,b)) <= 0


def Intersection(a,b,c,d):
    tmp1 = (b-a)*((c-a).det(d-c))
    tmp2 = (b-a).det(d-c)
    return a+(tmp1/tmp2)


def DistanceLineToPoint(a,b,c):
    return abs(((c-a).det(b-a))/((b-a).abs()))


def DistanceSeglineToPoint(a,b,c):
    if sgn((b-a).dot(c-a)) < 0: 
        return (c-a).abs()
    if sgn((a-b).dot(c-b)) < 0: 
        return (c-b).abs()
    return DistanceLineToPoint(a,b,c)


def Vfoot(a,b,c):
    d = c + Point((b-a).y,-(b-a).x)
    return Intersection(a,b,c,d)


def PolygonArea(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
    return S


def PolygonG(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    G = Point(0,0)
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
        G += (Plist[i-1]+Plist[i])/3*tmpS
    return G/S


def ConvexHull(Plist):
    Plist.sort()
    L = len(Plist)
    qu = deque([])
    quL = 0
    for p in Plist:
        while quL >= 2 and iSP(qu[quL-2],qu[quL-1],p) == 1:
            qu.pop()
            quL -= 1
        qu.append(p)
        quL += 1

    qd = deque([])
    qdL = 0
    for p in Plist:
        while qdL >= 2 and iSP(qd[qdL-2],qd[qdL-1],p) == -1:
            qd.pop()
            qdL -= 1
        qd.append(p)
        qdL += 1

    qd.pop()
    qu.popleft()
    hidari = list(qd) + list(reversed(qu)) 
    return hidari

x1,y1,x2,y2 = inpl()
p0,p1 = Point(x1,y1), Point(x2,y2)
q = inp()
for _ in range(q):
    p2 = Point(*inpl())
    tmp = iSP(p1,p0,p2)
    if tmp == -1:
        print('COUNTER_CLOCKWISE')
    elif tmp == 1:
        print('CLOCKWISE')
    elif tmp == 2:
        print('ONLINE_BACK')
    elif tmp == -2:
        print('ONLINE_FRONT')
    else:
        print('ON_SEGMENT')

Solution (Python):
import math

eps = 10 ** -8

line = input()
x1, y1, x2, y2 = list(map(int, line.split()))
line = input()
q = int(line)
pts = []
for _ in range(0, q):
    line = input()
    x, y = list(map(int, line.split()))
    pts += [[x, y]]

def solve():
    l1 = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    for x, y in pts:
        l2 = math.sqrt((x - x1)**2 + (y - y1)**2)
        dx = (x2 - x1) / l1
        dy = (y2 - y1) / l1
        ip = (x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)
        sine = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1)
        if sine < 0.0:
            print("COUNTER_CLOCKWISE")
        elif sine > 0.0:
            print("CLOCKWISE")
        elif abs(ip - l1 * l2) < eps:
            if l1 < l2:
                print("ONLINE_FRONT")
            else:
                print("ON_SEGMENT")
        elif ip + l1 * l2 < eps:
            print("ONLINE_BACK")
solve()

Solution (Python):
pp = list(map(int, input().split()))
n = int(input())

def cross(a, b):
    return a[0]*b[1]-a[1]*b[0]
        
def dot(a, b):
    n = len(a)
    if n != len(b):
        return None
    ans = 0
    for i, j in zip(a, b):
        ans += i*j
    return ans
    
for i in range(n):
    bb = list(map(int, input().split()))
    a = (pp[2]-pp[0], pp[3]-pp[1])
    b = (bb[0]-pp[0], bb[1]-pp[1])
    if cross(a, b) > 0:
        print("COUNTER_CLOCKWISE")
    elif cross(a, b) < 0:
        print("CLOCKWISE")
    else:
        if dot(a,b)<0:
            print("ONLINE_BACK")
        elif dot(a, (b[0]-a[0],b[1]-a[1]))>0: 
            print("ONLINE_FRONT")
        else:
            print("ON_SEGMENT")

Solution (Python):
import math


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

    def __add__(self, v):
        return Vector2(self.x+v.x, self.y+v.y)

    def __sub__(self, v):
        return Vector2(self.x-v.x, self.y-v.y)

    def __mul__(self, v):
        return Vector2(self.x*v, self.y*v)

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

    def dot(self, v):
        return self.x*v.x+self.y*v.y

    def cross(self, v):
        return self.x*v.y-self.y*v.x

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


def distanceLP(v1, v2, p):
    '''
    v1 -> v2の直線とpとの距離
    '''
    return abs((v2-v1).cross(p-v1))/abs(v2-v1)


def distanceSP(v1, v2, p):
    '''
    v1 -> v2の線分とpとの距離
    '''
    if (v2-v1).dot(p-v1) < 0.0:
        return abs(p-v1)
    if (v1-v2).dot(p-v2) < 0.0:
        return abs(p-v2)
    return distanceLP(v1, v2, p)


def intersect(p1, p2, p3, p4):
    '''
    p1p2とp3p4の交差判定
    '''
    t1 = (p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x)
    t2 = (p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x)
    t3 = (p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x)
    t4 = (p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x)
    return (t1*t2) < 0.0 and (t3*t4) < 0.0


def distance(a1, a2, b1, b2):
    '''
    線分a1a2とb1b2の距離
    '''
    if intersect(a1, a2, b1, b2):
        return 0.0
    return min([
        min([distanceSP(a1, a2, b1), distanceSP(a1, a2, b2)]),
        min([distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)])
    ])


p0x, p0y, p1x, p1y = map(int, input().split())
p0 = Vector2(p0x, p0y)
p1 = Vector2(p1x, p1y)
q = int(input())
for i in range(q):
    x, y = map(int, input().split())
    p2 = Vector2(x, y)
    c = (p1-p0).cross(p2-p0)
    if math.isclose(c, 0.0):
        d = (p1-p0).dot(p2-p0)
        if d < 0.0:
            print("ONLINE_BACK")
        else:
            d1 = abs(p1-p0)
            d2 = abs(p2-p0)
            if d1 < d2:
                print("ONLINE_FRONT")
            else:
                print("ON_SEGMENT")
    elif c < 0.0:
        print("CLOCKWISE")
    else:
        print("COUNTER_CLOCKWISE")

Solution (Python):
from sys import stdin

EPS = 1e-10

class Vector:
    def __init__(self, x=None, y=None):
        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, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.yb

    def __lt__(self, other):
        return self.x < other.x and self.y < other.yb

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    
    def cross(self, other):
        return self.x * other.y - self.y * other.x

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

    def abs(self):
        return math.sqrt(self.norm())

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        self.p1 = p1
        self.p2 = p2

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

def read_and_print_results(p0, p1, n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p2 = Vector(int(line[0]), int(line[1]))
        result = ccw(p0, p1, p2)
        if result == 1:
            print('COUNTER_CLOCKWISE')
        elif result == -1:
            print('CLOCKWISE')
        elif result == 2:
            print('ONLINE_BACK')
        elif result == -2:
            print('ONLINE_FRONT')
        elif result == 0:
            print('ON_SEGMENT')

x0, y0, x1, y1 = [int(i) for i in input().split()]
p0 = Point(x0, y0)
p1 = Point(x1, y1)
n = int(input())
read_and_print_results(p0, p1, n)