Problem:
Is-Convex For a given polygon g , print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.  g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 ≤ i ≤ n-1 ) are sides of the polygon. The line segment connecting p n and p 1 is also a side of the polygon. Input  g is given by coordinates of the points p 1 ,..., p n in the following format:  n  x 1  y 1  x 2  y 2 : x n  y n  The first integer n is the number of points. The coordinate of a point p i is given by two integers x i and y i . The coordinates of points are given in the order of counter-clockwise visit of them. Output Print "1" or "0" in a line. Constraints  3 ≤ n ≤ 100  -10000 ≤ x i , y i ≤ 10000  No point of the polygon will occur more than once.  Two sides of the polygon can intersect only at a common endpoint.  Sample Input 1 4
0 0
3 1
2 3
0 3 Sample Output 1 1 Sample Input 2 5
0 0
2 0 
1 1
2 2
0 2 Sample Output 2 0

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


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



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


def ConvexHull(dots):
	dots.sort(key=lambda x: (x.real, x.imag))
	res1 = [dots[0]]
	for d in dots[1:]:
		if len(res1) == 1:
			res1.append(d)
		else:
			while len(res1) > 1 and not CCW(res1[-2], res1[-1], d):
				res1.pop()
			res1.append(d)
	dots.reverse()
	res2 = [dots[0]]
	for d in dots[1:]:
		if len(res2) == 1:
			res2.append(d)
		else:
			while len(res2) > 1 and not CCW(res2[-2], res2[-1], d):
				res2.pop()
			res2.append(d)
	return res1[:-1] + res2[:-1]

n = int(input())
dots = []
for _ in range(n):
	x, y = map(int, input().split())
	dots.append(complex(x, y))

if len(dots) == 3:
	print(1)
elif len(ConvexHull(dots)) == n:
	print(1)
else:
	print(0)

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

N = int(input())
Plyst = [Point(*inpl()) for _ in range(N)]
Plyst2 = ConvexHull(Plyst)

L1 = [tuple(p.tolist()) for p in Plyst]
L2 = [tuple(p.tolist()) for p in Plyst2]

if len(list(set(L1))) != len(list(set(L2))):
    print(0)
else:
    print(1)

Solution (Python):
n = int(input())
vec = []
for i in range(n):
    vec += [list(map(int, input().split()))]
vec += [vec[0]]
vec += [vec[1]]
Sum = 0
def cross(a, b):
    return a[0]*b[1]-a[1]*b[0]
def ab(a, b):
    c = (b[0]-a[0],b[1]-a[1])
    return c
def check(a, b, c):
    if cross(ab(a, b),ab(a, c)) >= 0:
        return 1
    else:
        return 0
    
for a, b, c in zip(vec[0:-2],vec[1:-1],vec[2:]):
    cnt = check(a,b,c)
    if cnt == 0:
        break
print(cnt)

Solution (Python):
def cross(ux, uy, vx, vy):
    return ux*vy - uy*vx


n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
points.append(points[0])
points.append(points[1])

is_convex = True
for i in range(n):
    x1, y1 = points[i]
    x2, y2 = points[i + 1]
    x3, y3 = points[i + 2]
    if cross(x2 - x1, y2 - y1, x3 - x1, y3 - y1) < 0:
        is_convex = False
        break

print(1 if is_convex else 0)

Solution (Python):




def run():
    n = int(input())
    ps = []

    for _ in range(n):
        x, y = [int(i) for i in input().split()]
        ps.append((x, y))

    if convex(ps):
        print(1)
    else:
        print(0)


def dot(v1, v2):
    x1, y1 = v1
    x2, y2 = v2
    return x1 * x2 + y1 * y2


def orthogonal(v):
    x, y = v
    return -y, x


def convex(ps0):
    p0, *ps1 = ps0
    ps1.append(p0)
    p1, *ps2 = ps1
    ps2.append(p1)
    ret = []
    for pa, pb, pc in zip(ps0, ps1, ps2):
        xa, ya = pa
        xb, yb = pb
        xc, yc = pc
        v1 = (xb - xa, yb - ya)
        v2 = (xc - xb, yc - yb)
        ret.append(dot(orthogonal(v1), v2))

    return all([d >= 0 for d in ret]) or all([d <= 0 for d in ret])


if __name__ == '__main__':
    run()

Solution (Python):


import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

n = input()
lst = []
for loop in range(n):
    x, y = map(int, raw_input().split())
    lst.append((x, y))
lst += lst[:2]

ans = 1
for i in range(1, n + 1):
    x0, y0 = lst[i]
    x1, y1 = lst[i - 1]
    x2, y2 = lst[i + 1]
    if (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0) > 0:
        ans = 0

print ans