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):
x0,y0,x1,y1 = map(int, input().split())
p0=complex(x0,y0)
p1=complex(x1,y1)
q = int(input())

CCW = {1: 'COUNTER_CLOCKWISE',
       -1: 'CLOCKWISE',
       2: 'ONLINE_BACK',
       -2: 'ONLINE_FRONT',
       0: 'ON_SEGMENT',}

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

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

for i in range(q):
  p2=complex(*map(int,input().split()))
  print(CCW[ccw(p0,p1,p2)])

Solution (Python):


from typing import List, Tuple
from math import sqrt
from enum import Enum

EPS = 1e-10


def float_equal(x: float, y: float) -> bool:
    return abs(x - y) < EPS


class PointLocation(Enum):
    COUNTER_CLOCKWISE = 1
    CLOCKWISE = 2
    ONLINE_BACK = 3
    ONLINE_FRONT = 4
    ON_SEGMENT = 5


class Point:

    def __init__(self, x: float=0.0, y: float=0.0) -> None:
        self.x = x
        self.y = y

    def __repr__(self) -> str:
        return "Point({}, {})".format(self.x, self.y)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Point):
            
            return NotImplemented
        return float_equal(self.x, other.x) and \
            float_equal(self.y, other.y)

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

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

    def __mul__(self, k: float) -> 'Point':
        return Point(self.x * k, self.y * k)

    def __rmul__(self, k: float) -> 'Point':
        return self * k

    def __truediv__(self, k: float) -> 'Point':
        return Point(self.x / k, self.y / k)

    def __lt__(self, other: 'Point') -> bool:
        return self.y < other.y \
            if abs(self.x - other.x) < EPS \
            else self.x < other.x

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

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

    def dot(self, other: 'Point') -> float:
        return self.x * other.x + self.y * other.y

    def cross(self, other: 'Point') -> float:
        return self.x * other.y - self.y * other.x

    def is_orthogonal(self, other: 'Point') -> bool:
        return float_equal(self.dot(other), 0.0)

    def is_parallel(self, other: 'Point') -> bool:
        return float_equal(self.cross(other), 0.0)

    def distance(self, other: 'Point') -> float:
        return (self - other).abs()

    def in_side_of(self, seg: 'Segment') -> bool:
        return seg.vector().dot(
            Segment(seg.p1, self).vector()) >= 0

    def in_width_of(self, seg: 'Segment') -> bool:
        return \
            self.in_side_of(seg) and \
            self.in_side_of(seg.reverse())

    def distance_to_line(self, seg: 'Segment') -> float:
        return \
            abs((self - seg.p1).cross(seg.vector())) / \
            seg.length()

    def distance_to_segment(self, seg: 'Segment') -> float:
        if not self.in_side_of(seg):
            return self.distance(seg.p1)
        if not self.in_side_of(seg.reverse()):
            return self.distance(seg.p2)
        else:
            return self.distance_to_line(seg)

    def location(self, seg: 'Segment') -> PointLocation:
        p = self - seg.p1
        d = seg.vector().cross(p)
        if d < 0:
            return PointLocation.CLOCKWISE
        elif d > 0:
            return PointLocation.COUNTER_CLOCKWISE
        else:
            if seg.p2.x != seg.p1.x:
                r = (self.x - seg.p1.x) / (seg.p2.x - seg.p1.x)
            else:
                r = (self.y - seg.p1.y) / (seg.p2.y - seg.p1.y)
            if r < 0:
                return PointLocation.ONLINE_BACK
            elif r > 1:
                return PointLocation.ONLINE_FRONT
            else:
                return PointLocation.ON_SEGMENT


Vector = Point


class Segment:

    def __init__(self, p1: Point = None, p2: Point = None) -> None:
        self.p1: Point = Point() if p1 is None else p1
        self.p2: Point = Point() if p2 is None else p2

    def __repr__(self) -> str:
        return "Segment({}, {})".format(self.p1, self.p2)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Segment):
            
            return NotImplemented
        return self.p1 == other.p1 and self.p2 == other.p2

    def vector(self) -> Vector:
        return self.p2 - self.p1

    def reverse(self) -> 'Segment':
        return Segment(self.p2, self.p1)

    def length(self) -> float:
        return self.p1.distance(self.p2)

    def is_orthogonal(self, other: 'Segment') -> bool:
        return self.vector().is_orthogonal(other.vector())

    def is_parallel(self, other: 'Segment') -> bool:
        return self.vector().is_parallel(other.vector())

    def projection(self, p: Point) -> Point:
        v = self.vector()
        vp = p - self.p1
        return v.dot(vp) / v.norm() * v + self.p1

    def reflection(self, p: Point) -> Point:
        x = self.projection(p)
        return p + 2 * (x - p)

    def intersect_ratio(self, other: 'Segment') -> Tuple[float, float]:
        a = self.vector()
        b = other.vector()
        c = self.p1 - other.p1
        s = b.cross(c) / a.cross(b)
        t = a.cross(c) / a.cross(b)
        return s, t

    def intersects(self, other: 'Segment') -> bool:
        s, t = self.intersect_ratio(other)
        return (0 <= s <= 1) and (0 <= t <= 1)

    def intersection(self, other: 'Segment') -> Point:
        s, _ = self.intersect_ratio(other)
        return self.p1 + s * self.vector()

    def distance_with_segment(self, other: 'Segment') -> float:
        if not self.is_parallel(other) and \
                self.intersects(other):
            return 0
        else:
            return min(
                self.p1.distance_to_segment(other),
                self.p2.distance_to_segment(other),
                other.p1.distance_to_segment(self),
                other.p2.distance_to_segment(self))


Line = Segment


class Circle:

    def __init__(self, c: Point=None, r: float=0.0) -> None:
        self.c: Point = Point() if c is None else c
        self.r: float = r

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Circle):
            return NotImplemented
        return self.c == other.c and self.r == other.r

    def __repr__(self) -> str:
        return "Circle({}, {})".format(self.c, self.r)


def main() -> None:
    x0, y0, x1, y1 = [int(x) for x in input().split()]
    s = Segment(Point(x0, y0), Point(x1, y1))
    q = int(input())

    for _ in range(q):
        x2, y2 = [int(x) for x in input().split()]
        print(Point(x2, y2).location(s).name)


if __name__ == "__main__":
    main()

Solution (Python):


from typing import List, Tuple
from math import sqrt
from enum import Enum

EPS = 1e-10


def float_equal(x: float, y: float) -> bool:
    return abs(x - y) < EPS


class PointLocation(Enum):
    COUNTER_CLOCKWISE = 1
    CLOCKWISE = 2
    ONLINE_BACK = 3
    ONLINE_FRONT = 4
    ON_SEGMENT = 5


class Point:

    def __init__(self, x: float=0.0, y: float=0.0) -> None:
        self.x = x
        self.y = y

    def __repr__(self) -> str:
        return "Point({}, {})".format(self.x, self.y)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Point):
            
            return NotImplemented
        return float_equal(self.x, other.x) and \
            float_equal(self.y, other.y)

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

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

    def __mul__(self, k: float) -> 'Point':
        return Point(self.x * k, self.y * k)

    def __rmul__(self, k: float) -> 'Point':
        return self * k

    def __truediv__(self, k: float) -> 'Point':
        return Point(self.x / k, self.y / k)

    def __lt__(self, other: 'Point') -> bool:
        return self.y < other.y \
            if abs(self.x - other.x) < EPS \
            else self.x < other.x

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

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

    def dot(self, other: 'Point') -> float:
        return self.x * other.x + self.y * other.y

    def cross(self, other: 'Point') -> float:
        return self.x * other.y - self.y * other.x

    def is_orthogonal(self, other: 'Point') -> bool:
        return float_equal(self.dot(other), 0.0)

    def is_parallel(self, other: 'Point') -> bool:
        return float_equal(self.cross(other), 0.0)

    def distance(self, other: 'Point') -> float:
        return (self - other).abs()

    def in_side_of(self, seg: 'Segment') -> bool:
        return seg.vector().dot(
            Segment(seg.p1, self).vector()) >= 0

    def in_width_of(self, seg: 'Segment') -> bool:
        return \
            self.in_side_of(seg) and \
            self.in_side_of(seg.reverse())

    def distance_to_line(self, seg: 'Segment') -> float:
        return \
            abs((self - seg.p1).cross(seg.vector())) / \
            seg.length()

    def distance_to_segment(self, seg: 'Segment') -> float:
        if not self.in_side_of(seg):
            return self.distance(seg.p1)
        if not self.in_side_of(seg.reverse()):
            return self.distance(seg.p2)
        else:
            return self.distance_to_line(seg)

    def location(self, seg: 'Segment') -> PointLocation:
        p = self - seg.p1
        d = seg.vector().cross(p)
        if float_equal(d, 0.0):
            if seg.p2.x != seg.p1.x:
                r = (self.x - seg.p1.x) / (seg.p2.x - seg.p1.x)
            else:
                r = (self.y - seg.p1.y) / (seg.p2.y - seg.p1.y)
            if r < 0:
                return PointLocation.ONLINE_BACK
            elif r > 1:
                return PointLocation.ONLINE_FRONT
            else:
                return PointLocation.ON_SEGMENT
        elif d > 0:
            return PointLocation.COUNTER_CLOCKWISE
        else:
            return PointLocation.CLOCKWISE


Vector = Point


class Segment:

    def __init__(self, p1: Point = None, p2: Point = None) -> None:
        self.p1: Point = Point() if p1 is None else p1
        self.p2: Point = Point() if p2 is None else p2

    def __repr__(self) -> str:
        return "Segment({}, {})".format(self.p1, self.p2)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Segment):
            
            return NotImplemented
        return self.p1 == other.p1 and self.p2 == other.p2

    def vector(self) -> Vector:
        return self.p2 - self.p1

    def reverse(self) -> 'Segment':
        return Segment(self.p2, self.p1)

    def length(self) -> float:
        return self.p1.distance(self.p2)

    def is_orthogonal(self, other: 'Segment') -> bool:
        return self.vector().is_orthogonal(other.vector())

    def is_parallel(self, other: 'Segment') -> bool:
        return self.vector().is_parallel(other.vector())

    def projection(self, p: Point) -> Point:
        v = self.vector()
        vp = p - self.p1
        return v.dot(vp) / v.norm() * v + self.p1

    def reflection(self, p: Point) -> Point:
        x = self.projection(p)
        return p + 2 * (x - p)

    def intersect_ratio(self, other: 'Segment') -> Tuple[float, float]:
        a = self.vector()
        b = other.vector()
        c = self.p1 - other.p1
        s = b.cross(c) / a.cross(b)
        t = a.cross(c) / a.cross(b)
        return s, t

    def intersects(self, other: 'Segment') -> bool:
        s, t = self.intersect_ratio(other)
        return (0 <= s <= 1) and (0 <= t <= 1)

    def intersection(self, other: 'Segment') -> Point:
        s, _ = self.intersect_ratio(other)
        return self.p1 + s * self.vector()

    def distance_with_segment(self, other: 'Segment') -> float:
        if not self.is_parallel(other) and \
                self.intersects(other):
            return 0
        else:
            return min(
                self.p1.distance_to_segment(other),
                self.p2.distance_to_segment(other),
                other.p1.distance_to_segment(self),
                other.p2.distance_to_segment(self))


Line = Segment


class Circle:

    def __init__(self, c: Point=None, r: float=0.0) -> None:
        self.c: Point = Point() if c is None else c
        self.r: float = r

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Circle):
            return NotImplemented
        return self.c == other.c and self.r == other.r

    def __repr__(self) -> str:
        return "Circle({}, {})".format(self.c, self.r)


def main() -> None:
    x0, y0, x1, y1 = [int(x) for x in input().split()]
    s = Segment(Point(x0, y0), Point(x1, y1))
    q = int(input())

    for _ in range(q):
        x2, y2 = [int(x) for x in input().split()]
        print(Point(x2, y2).location(s).name)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
readline = stdin.readline



def lt(a, b):
    if a.real != b.real:
        return a.real < b.real
    return a.imag < b.imag


def main():
    x1, y1, x2, y2 = map(int, readline().split())
    p1, p2 = x1 + y1 * 1j, x2 + y2 * 1j
    q = int(readline())
    for i in range(q):
        xi, yi = map(int, readline().split())
        pi = xi + yi * 1j

        s = cross(p2 - p1, pi - p1)
        if abs(s) < 1e-10:
            if (lt(p1, p2) and lt(p2, pi)) or (lt(pi, p2) and lt(p2, p1)):
                print('ONLINE_FRONT')
            elif (lt(pi, p1) and lt(p1, p2)) or (lt(p2, p1) and lt(p1, pi)):
                print('ONLINE_BACK')
            else:
                print('ON_SEGMENT')
        elif s < 0:
            print('CLOCKWISE')
        else:
            print('COUNTER_CLOCKWISE')


def projecter(a, b):
    return dot(a, b) / dot(a, a)


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
main()

Solution (Python):

import math
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
        self.length = math.sqrt(x**2 + y**2)

init_point = map(float,raw_input().split())
p0 = Point(init_point[0], init_point[1])
p1 = Point(init_point[2], init_point[3])

q = int(raw_input())
for i in range(q):
    xp2,yp2 = map(float,raw_input().split())
    p2 = Point(xp2,yp2)
    p0p2 = Point(p2.x - p0.x, p2.y - p0.y)
    p0p1 = Point(p1.x - p0.x, p1.y - p0.y)
    p1p2 = Point(p2.x - p1.x, p2.y - p1.y)
    
    if p0p1.x * p0p2.y - p0p1.y * p0p2.x == 0:
        if max(p0p1.length, p0p2.length) < p1p2.length: 
            print "ONLINE_BACK"
        elif p0p1.length < p0p2.length:
            print "ONLINE_FRONT"
        elif p0p1.length >= p0p2.length:
            print "ON_SEGMENT"
    else:
        
        z = p0p1.x * p0p2.y - p0p1.y * p0p2.x
        if z > 0:
            print "COUNTER_CLOCKWISE"
        else:
            print "CLOCKWISE"

Solution (Python):
x0, y0, x1, y1 = map(int, input().split())
q = int(input())

p0, p1 = complex(x0, y0), complex(x1, y1)
p0p1 = p1 - p0

while q:
    q -= 1
    p2 = complex(*map(int, input().split()))
    p0p2 = p2 - p0
    prod_cross = p0p1.real * p0p2.imag - p0p1.imag * p0p2.real
    if abs(prod_cross) < 1e-6:
        if p0p1.real * p0p2.real >= 0 and p0p1.imag * p0p2.imag >= 0:
            print('ONLINE_FRONT' if abs(p0p1) < abs(p0p2) else 'ON_SEGMENT')
        else:
            print('ONLINE_BACK')
    else:
        print('COUNTER_CLOCKWISE' if prod_cross > 0 else 'CLOCKWISE')

Solution (Python):
x0, y0, x1, y1 = map(int, raw_input().split())
dx = x1 - x0
dy = y1 - y0
r = dx**2 + dy**2
for t in xrange(input()):
    x, y = map(int, raw_input().split())
    ex = x - x0
    ey = y - y0
    ov = dx*ey - dy*ex
    if ov > 0:
        print "COUNTER_CLOCKWISE"
    elif ov < 0:
        print "CLOCKWISE"
    else:
        iv = dx*ex + dy*ey
        if iv < 0:
            print "ONLINE_BACK"
        elif 0 <= iv <= r:
            print "ON_SEGMENT"
        else:
            print "ONLINE_FRONT"

Solution (Python):


import enum


EPS = 1e-10


class PointsRelation(enum.Enum):
    counter_clockwise = 1
    clockwise = 2
    online_back = 3
    on_segment = 4
    online_front = 5


def inner_product(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag


def outer_product(v1, v2):
    return v1.real * v2.imag - v1.imag * v2.real


def judge_relation(p0, p1, p2):
    v1 = p1 - p0
    v2 = p2 - p0
    op = outer_product(v1, v2)
    if op > EPS:
        return PointsRelation.counter_clockwise
    elif op < -EPS:
        return PointsRelation.clockwise
    elif inner_product(v1, v2) < -EPS:
        return PointsRelation.online_back
    elif abs(v1) < abs(v2):
        return PointsRelation.online_front
    else:
        return PointsRelation.on_segment


def main():
    x_p0, y_p0, x_p1, y_p1 = map(float, input().split())
    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        p2 = complex(*map(float, input().split()))
        ans = judge_relation(p0, p1, p2)
        if ans == PointsRelation.counter_clockwise:
            print("COUNTER_CLOCKWISE")
        elif ans == PointsRelation.clockwise:
            print("CLOCKWISE")
        elif ans == PointsRelation.online_back:
            print("ONLINE_BACK")
        elif ans == PointsRelation.online_front:
            print("ONLINE_FRONT")
        else:
            print("ON_SEGMENT")


if __name__ == '__main__':
    main()

Solution (Python):
import math

x0,y0,x1,y1 = map(float, raw_input().split())
q = int(raw_input())
for _ in xrange(q):
  x2,y2 = map(float, raw_input().split())
  ax = x1-x0
  ay = y1-y0
  bx = x2-x0
  by = y2-y0
  
  sin = ax*by-ay*bx
  if sin == 0:
    if(ax*bx < 0 or ay*by < 0):
      print "ONLINE_BACK"
    else:
      if math.fabs(bx) > math.fabs(ax) or math.fabs(by) > math.fabs(ay):
        print "ONLINE_FRONT"
      else:
        print "ON_SEGMENT"
  elif sin > 0:
    print "COUNTER_CLOCKWISE"
  else:
    print "CLOCKWISE"

Solution (Python):



"""
input:
0 0 2 0
3
-1 0
0 0
3 0

output:
ONLINE_BACK
ON_SEGMENT
ONLINE_FRONT
"""

import sys

EPS = 1e-9


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


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


def calc_distance(p_info):
    for point in p_info:
        p2_real, p2_imag = map(int, point)
        p2 = p2_real + p2_imag * 1j
        a, b = p1 - p0, p2 - p0
        if cross(a, b) > EPS:
            print('COUNTER_CLOCKWISE')
        elif cross(a, b) < -1 * EPS:
            print('CLOCKWISE')
        elif dot(a, b) < -1 * EPS:
            print('ONLINE_BACK')
        elif abs(a) < abs(b):
            print('ONLINE_FRONT')
        else:
            print('ON_SEGMENT')
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    base_line = tuple(map(int, _input[0].split()))
    p0, p1 = (x + y * 1j for x, y in zip(base_line[::2], base_line[1::2]))

    q_num = int(_input[1])
    q_list = map(lambda x: x.split(), _input[2:])
    calc_distance(q_list)

Solution (Python):
class Point:
    def __init__(self, x , y):
        self.x = x
        self.y = y
    def __sub__(self, p):
        x_sub = self.x - p.x
        y_sub = self.y - p.y
        return Point(x_sub, y_sub)

class Vector:
    def __init__(self, p):
        self.x = p.x
        self.y = p.y
    def norm(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5

def cross(v1, v2):
    return v1.x * v2.y - v1.y * v2.x

def dot(v1, v2):
    return v1.x * v2.x + v1.y * v2.y

def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    cross_ab = cross(a, b)
    if cross_ab > 0:
        print("COUNTER_CLOCKWISE")
    elif cross_ab < 0:
        print("CLOCKWISE")
    elif dot(a, b) < 0:
        print("ONLINE_BACK")
    elif a.norm() < b.norm():
        print("ONLINE_FRONT")
    else:
        print("ON_SEGMENT")

import sys

file_input = sys.stdin

x_p0, y_p0, x_p1, y_p1 = map(int, file_input.readline().split())
p0 = Point(x_p0, y_p0)
p1 = Point(x_p1, y_p1)

q = map(int, file_input.readline())

for line in file_input:
    x_p2, y_p2 = map(int, line.split())
    p2 = Point(x_p2, y_p2)
    ccw(p0, p1, p2)

Solution (Python):
import sys
from itertools import starmap
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
p0, p1 = starmap(complex, zip(*[map(int, input().split())] * 2))
n = int(readline())
for _ in [0] * n:
    res = ccw(p0, p1, complex(*map(float, readline().split())))
    if res == COUNTER_CLOCKWISE: print("COUNTER_CLOCKWISE")
    elif res == CLOCKWISE: print("CLOCKWISE")
    elif res == ONLINE_BACK: print("ONLINE_BACK")
    elif res == ONLINE_FRONT: print("ONLINE_FRONT")
    else: print("ON_SEGMENT")

Solution (Python):
def dot(a,b):
    return a[0]*b[0] + a[1]*b[1]

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

x0,y0,x1,y1 = [int(i) for i in input().split()] 
a = [x1-x0,y1-y0]

q = int(input())
for i in range(q):
    x2,y2 = [int(i) for i in input().split()]
    b = [x2-x0,y2-y0]
    crs = cross(a,b)
    if crs > 0 :
        print("COUNTER_CLOCKWISE")
    elif crs < 0 :
        print("CLOCKWISE")
    else :
        if dot(a,b) < 0 :
            print("ONLINE_BACK")
        elif dot(a,a) < dot(b,b) :
            print("ONLINE_FRONT")
        else :
            print("ON_SEGMENT")

Solution (Python):
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def Order(a,b):
    crs = cross(a,b)
    if crs > 0 : return "COUNTER_CLOCKWISE"
    elif crs < 0 : return "CLOCKWISE"
    else:
        if dot(a,b) < 0 : return "ONLINE_BACK"
        elif dot(a,a) < dot(b,b) : return "ONLINE_FRONT"
        else : return "ON_SEGMENT"

x0,y0,x1,y1 = [int(i) for i in input().split()] 
a = [x1-x0,y1-y0]

q = int(input())
for i in range(q):
    x2,y2 = [int(i) for i in input().split()]
    b = [x2-x0,y2-y0]
    print(Order(a,b))

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&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(other / self.x, other / self.y)

    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):
        from math import sqrt
        return sqrt(self.norm())


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(other / self.x, other / self.y)

    @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])

    @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, c=Point(), r=0.0):
        self.c = c
        self.r = r


def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    epsilon = 1e-10
    if Vector.cross(a, b) > epsilon:
        return 'COUNTER_CLOCKWISE'
    elif Vector.cross(a, b) < -epsilon:
        return 'CLOCKWISE'
    elif Vector.dot(a, b) < -epsilon:
        return 'ONLINE_BACK'
    elif a.norm() < b.norm():
        return 'ONLINE_FRONT'
    else:
        return 'ON_SEGMENT'


def main(args):
    x_p0, y_p0, x_p1, y_p1 = map(int, input().split())
    p0 = Point(x_p0, y_p0)
    p1 = Point(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        x_p2, y_p2 = map(int, input().split())
        p2 = Point(x_p2, y_p2)
        result = ccw(p0, p1, p2)
        print(result)


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

Solution (Python):
from math import sqrt
xp0, yp0, xp1, yp1 = map(int, input().split())
a = [xp0, yp0]
b = [xp1, yp1]
q = int(input())

CCW = {1: 'COUNTER_CLOCKWISE',
       2: 'CLOCKWISE',
       3: 'ONLINE_BACK',
       4: 'ONLINE_FRONT',
       5: 'ON_SEGMENT',}

def dot(a, b):
    return sum([i * j for i,j in zip(a, b)])

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

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

def _abs(a):
    return sqrt(a[0] ** 2 + a[1] ** 2)

def ccw(a, b, c):
    x = sub(b, a)
    y = sub(c, a)
    if cross(x, y) > 0: return 1
    if cross(x, y) < 0: return 2
    if dot(x, y) < 0: return 3
    if _abs(x) < _abs(y): return 4
    return 5

for i in range(q):
    c = list(map(int, input().split()))
    print(CCW[ccw(a, b, c)])

Solution (Python):


import collections
import math


class Vector2(collections.namedtuple("Vector2", ["x",  "y"])):

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

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

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

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

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

    def __abs__(self):  
        return math.sqrt(float(self.x * self.x + self.y * 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 getDistanceSP(segment, point):
    p = point
    p1, p2 = segment
    if (p2 - p1).dot(p - p1) < 0:
        return abs(p - p1)
    if (p1 - p2).dot(p - p2) < 0:
        return abs(p - p2)
    return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)


def getDistance(s1, s2):
    if 0:  
        return 0
    a, b = s1
    c, d = s2
    return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b))


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


if __name__ == '__main__':

    a, b, c, d = map(int, input().split())
    p0 = Vector2(a, b)
    p1 = Vector2(c, d)
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        p2 = Vector2(e, f)
        ans.append(ccw(p0, p1, p2))
    dic = {1: "COUNTER_CLOCKWISE", -1: "CLOCKWISE",
           2: "ONLINE_BACK", -2: "ONLINE_FRONT", 0: "ON_SEGMENT"}
    for a in ans:
        print(dic[a])