Problem:
Parallel/Orthogonal For given two lines s1 and s2 , print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.  s1 crosses points p0 and p1 , and s2 crosses points p2 and p3 . Input The entire input looks like:  q (the number of queries)
1st query
2nd query
... q th query Each query consists of integer coordinates of the points p0 , p1 , p2 , p3 in the following format:  x p0  y p0  x p1  y p1  x p2  y p2  x p3  y p3  Output For each query, print "2", "1" or "0". Constraints  1 ≤ q ≤ 1000  -10000 ≤ x p i , y p i ≤ 10000   p0 ≠ p1 and p2 ≠ p3 .  Sample Input 1 3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2 Sample Output 1 2
1
0

Solution (Python):


def main():
  q = int(input())
  for i in range(q):
    print(parallel_orthogonal())

def parallel_orthogonal():
  xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
  l1_start = complex(xp0, yp0)
  l1_end = complex(xp1, yp1)
  l2_start = complex(xp2, yp2)
  l2_end = complex(xp3, yp3)

  if 0 == dot(l1_end - l1_start, l2_end - l2_start):
    return 1
  if 0 == cross(l1_end - l1_start, l2_end - l2_start):
    return 2
  return 0




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):
from sys import stdin
readline = stdin.readline


def main():
    q = int(readline())
    for i in range(q):
        print(parallel_orthogonal())


def parallel_orthogonal():
    xy = map(int, readline().split())
    p0, p1, p2, p3 = [x + y * 1j for x, y in zip(*[xy] * 2)]
    if 0 == dot(p1 - p0, p3 - p2):
        return 1
    if 0 == cross(p1 - p0, p3 - p2):
        return 2
    return 0


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


q = int(raw_input())
for i in range(q):
    l = map(float,raw_input().split())
    if l[2] - l[0] == 0:
        if l[6] - l[4] == 0:
            print 2
        elif l[7]-l[5] == 0:
            print 1
        else:
            print 0
    elif l[6] - l[4] == 0:
        if l[2] - l[0] == 0:
            print 2
        elif l[3] - l[1] == 0:
            print 1
        else:
            print 0
    else:
        s1 = (l[3] - l[1], l[2] - l[0])
        s2 = (l[7] - l[5], l[6] - l[4])
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Solution (Python):



q = int(raw_input())
for i in range(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(float,raw_input().split())
    if xp1 - xp0 == 0:
        if xp3 - xp2 == 0:
            print 2
        elif yp3 - yp2 == 0:
            print 1
        else:
            print 0
    elif xp3 - xp2 == 0:
        if xp1 - xp0 == 0:
            print 2
        elif yp1 - yp0 == 0:
            print 1
        else:
            print 0
    
    else:
        s1 = (yp1 - yp0, xp1 - xp0)
        s2 = (yp3 - yp2, xp3 - xp2)
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Solution (Python):



q = int(raw_input())
for i in xrange(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(float,raw_input().split())
    if xp1 - xp0 == 0:
        if xp3 - xp2 == 0:
            print 2
        elif yp3 - yp2 == 0:
            print 1
        else:
            print 0
    elif xp3 - xp2 == 0:
        if xp1 - xp0 == 0:
            print 2
        elif yp1 - yp0 == 0:
            print 1
        else:
            print 0
    
    else:
        s1 = (yp1 - yp0, xp1 - xp0)
        s2 = (yp3 - yp2, xp3 - xp2)
        if s1[0]/s1[1] == s2[0]/s2[1]:
            print 2
        elif s1[0]*s2[0] + s1[1]*s2[1] == 0:
            print 1
        else:
            print 0

Solution (Python):
from itertools import starmap

q = int(input())
while q:
    q -= 1
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, input().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Solution (Python):
for t in xrange(input()):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    dx0 = x1 - x0
    dy0 = y1 - y0
    dx1 = x3 - x2
    dy1 = y3 - y2
    ov = dx0*dy1 - dy0*dx1
    iv = dx0*dx1 + dy0*dy1
    if iv == 0:
        print 1
    elif ov == 0:
        print 2
    else:
        print 0

Solution (Python):


import enum


EPS = 1e-10


class LinesRelation(enum.Enum):
    other = 0
    orthogonal = 1
    parallel = 2


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_lines_relation(l1_start, l1_end, l2_start, l2_end):
    v1 = l1_end - l1_start
    v2 = l2_end - l2_start
    if abs(outer_product(v1, v2)) < EPS:
        return LinesRelation.parallel
    elif abs(inner_product(v1, v2)) < EPS:
        return LinesRelation.orthogonal
    else:
        return LinesRelation.other


def main():
    q = int(input())
    for _ in range(q):
        xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
        l1_start = complex(xp0, yp0)
        l1_end = complex(xp1, yp1)
        l2_start = complex(xp2, yp2)
        l2_end = complex(xp3, yp3)
        print(judge_lines_relation(l1_start, l1_end, l2_start, l2_end).value)


if __name__ == '__main__':
    main()

Solution (Python):
q = int(raw_input())
for _ in xrange(q):
  x0,y0,x1,y1,x2,y2,x3,y3 = map(float, raw_input().split())
  ax = x1-x0
  ay = y1-y0
  bx = x3-x2
  by = y3-y2
  inner = ax*bx+ay*by
  outer = ax*by-ay*bx
  if inner == 0:
    print 1
  elif outer == 0:
    print 2
  else:
    print 0

Solution (Python):



"""
input:
3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2

output:
2
1
0
"""

import sys


def get_line(line_info):
    for line_pair in line_info:
        line_axis = tuple(map(int, line_pair))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        
        if dot(p1 - p0, p3 - p2) == 0:
            print('1')
        elif cross(p1 - p0, p3 - p2) == 0:
            print('2')
        else:
            print('0')
    return line_info


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


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    lines = map(lambda x: x.split(), _input[1:])
    ans = get_line(lines)

Solution (Python):
import sys
 
 
def get_line(line_info):
    for line_pair in line_info:
        line_axis = tuple(map(int, line_pair))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        
        if dot(p1 - p0, p3 - p2) == 0:
            print('1')
        elif cross(p1 - p0, p3 - p2) == 0:
            print('2')
        else:
            print('0')
    return line_info
 
 
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
 
 
if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    lines = map(lambda x: x.split(), _input[1:])
    ans = get_line(lines)

Solution (Python):
for _ in [0]*int(input()):
    a,b,c,d,e,f,g,h=map(int,input().split())
    print(1 if (c-a)*(g-e)==-(d-b)*(h-f) else(2 if (c-a)*(h-f)==(d-b)*(g-e) else 0))

Solution (Python):

class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def is_orthogonal(self, v):
        if self.x * v.x + self.y * v.y == 0:
            return True
        else:
            return False
    def is_parallel(self, v):
        if self.x * v.y - self.y * v.x == 0:
            return True
        else:
            return False



import sys

file_input = sys.stdin

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

for line in file_input:
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())
    s1 = Vector(x_p1 - x_p0, y_p1 - y_p0)
    s2 = Vector(x_p3 - x_p2, y_p3 - y_p2)
    if s1.is_parallel(s2):
        print(2)
    elif s1.is_orthogonal(s2):
        print(1)
    else:
        print(0)

Solution (Python):


import sys
import os
import pprint




def judge(lst):
    x0, y0, x1, y1, x2, y2, x3, y3 = lst
    v0 = (x1 - x0, y1 - y0)
    v1 = (x3 - x2, y3 - y2)

    dot = v0[0] * v1[0] + v0[1] * v1[1]
    cross = v0[0] * v1[1] - v0[1] * v1[0]

    if dot == 0:
        print(1)
    elif cross == 0:
        print(2)
    else:
        print(0)


N = int(input())
for i in range(N):
    lst = list(map(int, input().split()))
    judge(lst)

Solution (Python):
import sys
readline = sys.stdin.readline
n = int(readline())
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
for _ in [0] * n:
    line_axis = tuple(map(int, readline().split()))
    p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
    if dot(p1 - p0, p3 - p2) == 0:
        print('1')
    elif cross(p1 - p0, p3 - p2) == 0:
        print('2')
    else:
        print('0')

Solution (Python):
import sys
readline = sys.stdin.readline
n = int(readline())
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
for _ in [0] * n:
    line_axis = tuple(map(int, readline().split()))
    p0, p1, p2, p3 = (complex(x, y) for x, y in zip(line_axis[::2], line_axis[1::2]))
    if dot(p1 - p0, p3 - p2) == 0:
        print('1')
    elif cross(p1 - p0, p3 - p2) == 0:
        print('2')
    else:
        print('0')

Solution (Python):
from itertools import starmap
import sys
readline = sys.stdin.readline
q = int(readline())
while q:
    q -= 1
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Solution (Python):
from itertools import starmap
import sys
readline = sys.stdin.readline
q = int(readline())
for _ in [0] * q:
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

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]

q = int(input())
for i in range(q):
    x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
    a = [x1-x0,y1-y0]
    b = [x3-x2,y3-y2]
    if dot(a,b) == 0 : print(1)
    elif cross(a,b) == 0 : print(2)
    else : print(0)

Solution (Python):

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

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

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

    def __truediv__(self, other):
        return (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):
    @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 solve(data):
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = data
    a = Segment((x_p0, y_p0), (x_p1, y_p1))
    b = Segment((x_p2, y_p2), (x_p3, y_p3))
    if Segment.is_orthogonal(a, b):
        return 1
    elif Segment.is_parallel(a, b):
        return 2
    else:
        return 0


def main(args):
    q = int(input())
    for _ in range(q):
        result = solve([int(x) for x in input().split()])
        print(result)

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

Solution (Python):
n = int(input())

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

from math import sqrt
def s(a):
    return a[0]**2 + a[1]**2
for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    p2 = points[4:6]
    p3 = points[6:8]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0:
        print(1)
    elif c == 1:
        print(2)
    else:
        print(0)

Solution (Python):
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]
def s(a):
    return a[0]**2 + a[1]**2

for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    p2 = points[4:6]
    p3 = points[6:8]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0: print(1)
    elif c == 1: print(2)
    else: print(0)

Solution (Python):
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]
def s(a):
    return a[0]**2 + a[1]**2

for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    p2 = points[4:6]
    p3 = points[6:8]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0: print(1)
    elif c == 1: print(2)
    else: print(0)

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 __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


if __name__ == '__main__':

    n = int(input())
    
    for _ in range(n):
        l = list(map(int, input().split()))
        s1 = Vector2(l[2], l[3]) - Vector2(l[0], l[1])
        s2 = Vector2(l[6], l[7]) - Vector2(l[4], l[5])

        if abs(s1.dot(s2)) == 0:
            print(1)
        elif abs(s1.cross(s2)) == 0:
            print(2)
        else:
            print(0)

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

class Line():
    def __init__(self, x1, y1, x2, y2):
        self.p1 = Point(x1, y1)
        self.p2 = Point(x2, y2)

    def get_slope(self):
        if self.p1.x == self.p2.x:
            return float('inf')
        return (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x)

q = int(input())
for i in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
    line1, line2 = Line(x0, y0, x1, y1), Line(x2, y2, x3, y3)
    a1, a2 = line1.get_slope(), line2.get_slope()
    if a1 == a2: 
        print('2')
    elif round(a1*a2, 8) == -1.0:
        print('1')
    elif (a1 == float('inf') and a2 == 0) or (a1 == 0 and a2 == float('inf')):
        print('1')
    else:
        print('0')

Solution (Python):



def vector_product(vect1, vect2):
    return [el1 * el2 for el1, el2 in zip(vect1, vect2)]


def inner_product(vect1, vect2):
    return sum(vector_product(vect1, vect2))


def cross_product(vect1, vect2):
    return vect1[0]*vect2[1] - vect1[1]*vect2[0]


def vector_minus(vect1, vect2):
    return [el1 - el2 for el1, el2 in zip(vect1, vect2)]


def line_slope(line_from, line_to):
    try:
        slope = (line_to[1] - line_from[1])/(line_to[0] - line_from[0])
    except ZeroDivisionError:
        slope = "未定義"
    return slope


"""
def is_parallel(l_from1, l_to1, l_from2, l_to2):
    slope1 = line_slope(l_from1, l_to1)
    slope2 = line_slope(l_from2, l_to2)
    if slope1 == slope2:
        return 1
    return 0
"""


def is_parallel(l_from1, l_to1, l_from2, l_to2):
    line1 = vector_minus(l_to1, l_from1)
    line2 = vector_minus(l_to2, l_from2)
    if cross_product(line1, line2) == 0:
        return 1
    return 0


def is_orthogonal(l_from1, l_to1, l_from2, l_to2):
    line1 = vector_minus(l_to1, l_from1)
    line2 = vector_minus(l_to2, l_from2)
    if inner_product(line1, line2) == 0:
        return 1
    return 0


if __name__ == '__main__':
    Q = int(input())

    for i in range(Q):
        all_list = list(map(int, input().split()))
        p0_list = all_list[:2]
        p1_list = all_list[2:4]
        p2_list = all_list[4:6]
        p3_list = all_list[6:]

        if is_parallel(p0_list, p1_list, p2_list, p3_list):
            print("2")
        elif is_orthogonal(p0_list, p1_list, p2_list, p3_list):
            print("1")
        else:
            print("0")

Solution (Python):
from math import sin, cos, atan2

def sgn(x, eps=1e-10):
    if x < -eps: return -1
    if -eps <= x <= eps: return 0
    if eps < x: return 1

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

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

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

    def rotate(self, t):
        nx = self.x * cos(t) - self.y * sin(t)
        ny = self.x * sin(t) + self.y * cos(t)
        return Vector(nx, ny)

    def counter(self):
        nx = -self.x
        ny = -self.y
        return Vector(nx, ny)

    def times(self, k):
        nx = self.x * k
        ny = self.y * k
        return Vector(nx, ny)

    def unit(self):
        norm = self.norm()
        nx = self.x / norm
        ny = self.y / norm
        return Vector(nx, ny)

    def normal(self):
        norm = self.norm()
        nx = -self.y / norm
        ny = self.x / norm
        return Vector(nx, ny)

    def add(self, other): 
        nx = self.x + other.x
        ny = self.y + other.y
        return Vector(nx, ny)

    def sub(self, other):
        nx = self.x - other.x
        ny = self.y - other.y
        return Vector(nx, ny)

    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 __str__(self):
        return '{:.9f}'.format(self.x) + ' ' + '{:.9f}'.format(self.y)

class Line():
    def __init__(self, bgn=Vector(), end=Vector()):
        self.bgn = bgn
        self.end = end

    def build(self, a, b, c): 
        assert sgn(a) != 0 or sgn(b) != 0
        if sgn(b) == 0:
            self.bgn = Vector(-c / a, 0.0)
            self.end = Vector(-c / a, 1.0)
        else:
            self.v = Vector(0, -c / b)
            self.u = Vector(1.0, -(a + b) / b)

    def vec(self):
        return self.end.sub(self.bgn)

    def projection(self, point):
        v = self.vec()
        u = point.sub(self.bgn)
        k = v.dot(u) / v.norm()
        h = v.unit().times(k)
        return self.bgn.add(h)

    def refrection(self, point):
        proj = self.projection(point)
        return proj.sub(point).times(2).add(point)

    def is_orthogonal(self, other):
        v = self.vec()
        u = other.vec()
        if sgn(v.dot(u)) == 0:
            return True
        else:
            return False

    def is_parallel(self, other):
        v = self.vec()
        u = other.vec()
        if sgn(v.cross(u)) == 0:
            return True
        else:
            return False

q = int(input())
for _ in range(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
    p0 = Vector(xp0, yp0)
    p1 = Vector(xp1, yp1)
    p2 = Vector(xp2, yp2)
    p3 = Vector(xp3, yp3)
    s1 = Line(p0, p1)
    s2 = Line(p2, p3)
    if s1.is_parallel(s2):
        print(2)
    elif s1.is_orthogonal(s2):
        print(1)
    else:
        print(0)

Solution (Python):
n = int(input())

for i in range(n):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
    v0 = (x1 - x0, y1 - y0)
    v1 = (x3 - x2, y3 - y2)

    dot = v0[0] * v1[0] + v0[1] * v1[1]
    cross = v0[0] * v1[1] - v0[1] * v1[0]

    if dot == 0:
        print(1)
    elif cross == 0:
        print(2)
    else:
        print(0)

Solution (Python):
def dot(vector1,vector2):
    return vector1[0]*vector2[0]+vector1[1]*vector2[1]

q = int(input())
for _ in range(q):
    x1,y1,x2,y2,x3,y3,x4,y4 = map(int,input().split())
    vector1 = [x1-x2,y1-y2]
    vector2 = [x3-x4,y3-y4]
    
    if dot(vector1,vector2)==0:
        print(1)
    elif dot(vector1,vector2)**2==dot(vector1,vector1)*dot(vector2,vector2):
        print(2)
    else:
        print(0)

Solution (Python):
import sys
import math
input = sys.stdin.readline


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

    def __add__(self, vec):
        return Vector(self.x+vec.x, self.y+vec.y)

    def __sub__(self, vec):
        return Vector(self.x-vec.x, self.y-vec.y)

    def __mul__(self, sc):
        return Vector(self.x*sc, self.y*sc)

    def __truediv__(self, sc):
        return Vector(self.x/sc, self.y/sc)

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

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

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

    def __itruediv__(self, sc):
        self.x /= sc
        self.y /= sc
        return self

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

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

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

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

    def abs(self):
        return (self.x*self.x + self.y*self.y)**0.5

    def ortho(self):
        return Vector(-self.y, self.x)


for _ in [0]*int(input()):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
    v = Vector(x1-x0, y1-y0)
    u = Vector(x3-x2, y3-y2)

    if v.cross(u) == 0:
        print(2)
    elif v.dot(u) == 0:
        print(1)
    else:
        print(0)

Solution (Python):
EPS = 10**(-9)
def is_equal(a,b):
    return abs(a-b) < EPS

def norm(v,i):
    import math
    ret = 0
    n = len(v)
    for j in range(n):
        ret += abs(v[j])**i
    return math.pow(ret,1/i)

class Vector(list):
    """
    ベクトルクラス
    対応演算子
    +  : ベクトル和 
    -  : ベクトル差
    *  : スカラー倍、または内積
    /  : スカラー除法
    ** : 外積
    += : ベクトル和
    -= : ベクトル差
    *= : スカラー倍
    /= : スカラー除法

    メソッド
    self.norm(i) : L{i}ノルムを計算
    """
    def __add__(self,other):
        n = len(self)
        ret = [0]*n
        for i in range(n):
            ret[i] = super().__getitem__(i) + other.__getitem__(i)
        return self.__class__(ret)
    
    def __radd__(self,other):
        n = len(self)
        ret = [0]*n
        for i in range(n):
            ret[i] = other.__getitem__(i) + super().__getitem__(i)
        return self.__class__(ret)
    
    def __iadd__(self, other):
        n = len(self)
        for i in range(n):
            self[i] += other.__getitem__(i)
        return self

    def __sub__(self,others):
        n = len(self) 
        ret = [0]*n
        for i in range(n):
            ret[i] = super().__getitem__(i) - others.__getitem__(i)
        return self.__class__(ret)

    def __iadd__(self, other):
        n = len(self)
        for i in range(n):
            self[i] -= other.__getitem__(i)
        return self

    def __rsub__(self,others):
        n = len(self) 
        ret = [0]*n
        for i in range(n):
            ret[i] = others.__getitem__(i) - super().__getitem__(i)
        return self.__class__(ret)
    
    def __mul__(self,other):
        n = len(self)
        if isinstance(other,list):
            ret = 0
            for i in range(n):
                ret += super().__getitem__(i)*other.__getitem__(i)
            return ret
        else:
            ret = [0]*n
            for i in range(n):
                ret[i] = super().__getitem__(i)*other
            return self.__class__(ret)

    def __rmul__(self,other):
        n = len(self)
        if isinstance(other,list):
            ret = 0
            for i in range(n):
                ret += super().__getitem__(i)*other.__getitem__(i)
            return ret
        else:
            ret = [0]*n
            for i in range(n):
                ret[i] = super().__getitem__(i)*other
            return self.__class__(ret)
    
    
    def __truediv__(self,other):
        """
        ベクトルのスカラー除法
        Vector/scalar
        """
        n = len(self)
        ret = [0]*n
        for i in range(n):
            ret[i] = super().__getitem__(i)/other
        return self.__class__(ret)
    
    def norm(self,i):
        """
        L{i}ノルム
        self.norm(i)
        """
        return norm(self,i)
    
    def __pow__(self,other):
        """
        外積
        self**other
        """
        n = len(self)
        ret = [0]*3
        x = self[:]
        y = other[:]
        if n == 2:
            x.append(0)
            y.append(0)
        if n == 2 or n == 3:
            for i in range(3):
                ret[0],ret[1],ret[2] = x[1]*y[2]-x[2]*y[1],x[2]*y[0]-x[0]*y[2],x[0]*y[1]-x[1]*y[0]
            ret = Vector(ret)
            if n == 2:
                return ret.norm(2)
            else:
                return ret

class Segment:
    """
    線分クラス
    """
    def __init__(self,v1,v2):
        self.v1 = v1
        self.v2 = v2

    def get_unit_vec(self):
        return (self.v2-self.v1)/norm(self.v2-self.v1,2)
    
    def projection(self,vector):
        unit_vec = self.get_unit_vec()
        t = unit_vec*(vector-self.v1)
        return self.v1 + t*unit_vec
    
    def is_vertical(self,other):
        return is_equal(0,self.get_unit_vec()*other.get_unit_vec())
    
    def is_horizontal(self,other):
        return is_equal(0,self.get_unit_vec()**other.get_unit_vec())
    
    def reflection(self,vector):
        projection = self.projection(vector)
        v = projection - vector
        return projection + vector

class Line(Segment):
    """
    直線クラス
    """
    pass


q = int(input())
for _ in range(q):
    tmp = list(map(int,input().split()))
    vectors = [0]*4
    for j in range(4):
        vectors[j] = Vector(tmp[j*2:(j+1)*2])
    l1 = Line(vectors[0],vectors[1])
    l2 = Line(vectors[2],vectors[3])

    if l1.is_horizontal(l2):
        print(2)
    elif l1.is_vertical(l2):
        print(1)
    else:
        print(0)

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

def resolve():
    Q = int(input())

    for i in range(Q):
        s, t, a, b, x, y, c, d = map(int, input().split())
        P0 = Vector([s, t])
        P1 = Vector([a, b])
        P2 = Vector([x, y])
        P3 = Vector([c, d])

        line_a = P1.sub(P0)
        line_b = P3.sub(P2)

        if cross(line_a, line_b) == 0:
            print(2)
        elif dot(line_a, line_b) == 0:
            print(1)
        else:
            print(0)

if __name__ == '__main__':
    resolve()

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

class Vector(Point):
    pass

def point_to_vector(p1, p2):
    x = p1.x - p2.x
    y = p1.y - p2.y
    return Vector(x, y)

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

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

def is_orth(v1, v2):
    if dot(v1, v2) == 0:
        return True
    else:
        return False

def is_pal(v1, v2):
    if cross(v1, v2) == 0:
        return True
    else:
        return False

q = int(input())
for i in range(q):
    temp = list(map(int, input().split()))
    points = []
    for j in range(0, 8, 2):
        points.append(Point(temp[j], temp[j+1]))
    v1 = point_to_vector(points[0], points[1])
    v2 = point_to_vector(points[2], points[3])
    if is_pal(v1, v2):
        ans = 2
    elif is_orth(v1, v2):
        ans = 1
    else:
        ans = 0
    print(ans)