def orientation(p, q, r):
    """
    To find orientation of ordered triplet(p, q, r).

    p: coordinate
    q: coordinate
    r: coordinate

    The function returns following values:
    0 --> p, q and r are colinear
    1 --> clockwise
    2 --> counterclockwise

    See 10th slides from following link for derivation of the formula
    http://www.dcs.gla.ac.uk/~pat/52233/slides/Geometry1x1.pdf
    """
    value = ((q.y - p.y) * (r.x - q.x) -
             (q.x - p.x) * (r.y - q.y))

    if value == 0:
        return 0
    elif value > 0:
        return 1
    else:
        return 2