Problem:
Reflection For given three points p1, p2, p , find the reflection point x of p onto p1p2 .   Input  x p1  y p1  x p2  y p2  q  x p 0  y p 0  x p 1  y p 1 ... x p q−1  y p q−1  In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p . Output For each query, print the coordinate of the reflection point x . The output values should be in a decimal fraction with an error less than 0.00000001. Constraints   1 ≤ q ≤ 1000    -10000 ≤ x i , y i ≤ 10000    p1 and p2 are not identical.  Sample Input 1 0 0 2 0
3
-1 1
0 1
1 1 Sample Output 1 -1.0000000000 -1.0000000000
0.0000000000 -1.0000000000
1.0000000000 -1.0000000000 Sample Input 2 0 0 3 4
3
2 5
1 4
0 3 Sample Output 2 4.2400000000 3.3200000000
3.5600000000 2.0800000000
2.8800000000 0.8400000000

Solution (Python):
x1,y1,x2,y2=map(float,raw_input().split(" "))
for i in xrange(int(raw_input())):
    px,py=map(float,raw_input().split(" "))
    dxa=(x2-x1)
    dya=(y2-y1)
    da=dxa**2+dya**2
    dxb=(px-x1)
    dyb=(py-y1)
    ip=dxb*dxa+dya*dyb
    r=ip/da
    kouten_x=x1+r*dxa
    kouten_y=y1+r*dya
    ref_x=px+2.0*(kouten_x-px)
    ref_y=py+2.0*(kouten_y-py)
    print "{0:.10f} {1:.10f}".format(ref_x,ref_y)

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

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
        cross = p1 + (p2 - p1) * projecter(p2 - p1, pi - p1)
        cross = cross * 2 - pi
        print('{:.10f} {:.10f}'.format(cross.real, cross.imag))


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


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

Solution (Python):

xp0,yp0,xp1,yp1 = map(float,raw_input().split())
q = int(raw_input())
for i in range(q):
    xp2,yp2 = map(float,raw_input().split())
    p0p2 = (xp2-xp0,yp2-yp0)
    p0p1 = (xp1-xp0,yp1-yp0)
    k = ((p0p2[0]*p0p1[0]+p0p2[1]*p0p1[1])/(p0p1[0]**2 + p0p1[1]**2))
    
    p0T = (k*p0p1[0],k*p0p1[1])
    OT = (xp0+p0T[0],yp0+p0T[1])
    p2t = (2*(OT[0]-xp2),2*(OT[1]-yp2))
    Ot =  (p2t[0] + xp2,p2t[1] + yp2)
    print "%.10f %.10f" % (Ot[0],Ot[1])

Solution (Python):

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

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)
    k = ((p0p2.x * p0p1.x + p0p2.y * p0p1.y)/(p0p1.x ** 2 + p0p1.y ** 2))
    
    p0T = Point(k * p0p1.x, k * p0p1.y)
    OT = Point(p0.x + p0T.x, p0.y + p0T.y)
    p2t = Point(2*(OT.x - p2.x), 2*(OT.y - p2.y))
    Ot =  Point(p2t.x + xp2, p2t.y + p2.y)
    print "%.10f %.10f" % (Ot.x, Ot.y)

Solution (Python):
x1, y1, x2, y2 = map(int, input().split())
q = int(input())

p1, p2 = complex(x1, y1), complex(x2, y2)
p1p2 = p2 - p1
d2_p1p2 = p1p2.real ** 2 + p1p2.imag ** 2

while q:
    q -= 1
    p0 = complex(*map(int, input().split()))
    p1p0 = p0 - p1
    t = (p1p2.real * p1p0.real + p1p2.imag * p1p0.imag) / d2_p1p2
    ref = p0 + 2 * (p1p2 * t - p1p0)
    print(ref.real, ref.imag)

Solution (Python):
x0,y0,x1,y1 = map(float,input().split())
n = int(input())
vx1,vy1 = x1-x0,y1-y0

for i in range(n):
    x2,y2 = map(float,input().split())
    vx2,vy2 = x2-x0,y2-y0
    sqr = vx1**2 + vy1**2
    in_p = vx1*vx2 + vy1*vy2
    xt,yt = 2*in_p*vx1/sqr + 2*x0-x2,2*in_p*vy1/sqr + 2*y0-y2
    print("{0:.10f} {1:.10f}".format(xt,yt))

Solution (Python):
from math import sqrt
x1, y1, x2, y2 = map(int, raw_input().split())
dx = x2 - x1
dy = y2 - y1
for i in xrange(input()):
    x, y = map(int, raw_input().split())
    a = float(dx*(x - x1) + dy*(y - y1)) / (dx**2 + dy**2)
    print "%.09f %0.09f" % (2*x1 - x + 2*a*dx, 2*y1 - y + 2*a*dy)

Solution (Python):


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



def project(a, b):
    return a * inner_product(a, b) / (abs(a) ** 2)



def reflect(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    v = project(a, b)
    u = v - b
    p3 = p2 + 2 * u
    return p3


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()))
        t = reflect(p0, p1, p2)
        print("{:.10f} {:.10f}".format(t.real, t.imag))


if __name__ == '__main__':
    main()

Solution (Python):
x1,y1,x2,y2 = map(float, raw_input().split())

q = int(raw_input())
for _ in xrange(q):
  x,y = map(float, raw_input().split())
  if x1 == x2:
    print "%f %f" % (x1*2-x, y)
  elif y1 == y2:
    print "%f %f" % (x, y1*2-y)
  else:
    a0 = (y2 - y1) / (x2 - x1)
    b0 = y1 - a0 * x1
    ap = -1 / a0
    bp = y - ap * x
    xe = (bp - b0) / (a0 - ap)
    ye = a0 * xe + b0
    xe = xe + (xe - x)
    ye = ye + (ye - y)
    print "%.12f %.12f" % (xe, ye)

Solution (Python):



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

output:
4.2400000000 3.3200000000
3.5600000000 2.0800000000
2.8800000000 0.8400000000
"""

import sys


def solve(_prj_info):
    for point in _prj_info:
        xp, yp = map(int, point)
        p = xp + yp * 1j
        hypo = p - p1
        prj = p1 + base * project(base, hypo)
        ref = p + (prj - p) * 2.0
        print('{0:.10f} {1:.10f}'.format(ref.real, ref.imag))

    return _prj_info


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



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


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    base_info = _input[0].split()
    q_num = int(_input[1])
    prj_points = map(lambda x: x.split(), _input[2:])

    x1, y1, x2, y2 = map(int, base_info)
    p1, p2 = x1 + y1 * 1j, x2 + y2 * 1j
    base = p2 - p1
    res = solve(prj_points)

Solution (Python):
x1,y1,x2,y2 = map(float,input().split())
det = x1 - x2
if det != 0:
    a = (y1 - y2) / det
    b = (-(y1 * x2) + y2 * x1) / det

q = int(input())
x,y = [],[]
for i in range(q):
    x_t,y_t = map(float,input().split())
    x.append(x_t)
    y.append(y_t)

if det == 0:
    for i in range(q):
        print(-x[i],y[i])
elif y2 == y1:
    for i in range(q):
        print(x[i],-y[i])
else:
    for i in range(q):
        k = y[i] + 1/a * x[i]
        s = (k - b)/(a + 1/a)
        print(s+(s-x[i]),-1/a * (s+(s-x[i])) + k)

Solution (Python):
a,b,c,d=map(float,input().split())
a=complex(a,b)
b=complex(c,d)
for _ in [0]*int(input()):
    c=complex(*map(float,input().split()))
    q=b-a;c-=a
    p=a+q*(c/q).conjugate()
    print(p.real,p.imag)

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
    def dot_product(self, v):
        return self.x * v.x + self.y * v.y
    def quadrance(self):
        return self.x ** 2 + self. y ** 2
    def mul(self, k):
        return Vector(self.x * k, self.y *k)
    def __add__(self, v):
        return Vector(self.x + v.x, self.y + v.y)
    def __sub__(self, v):
        return Vector(self.x - v.x, self.y - v.y)
    def __str__(self):
        return "{0:.8f} {1:.8f}".format(self.x, self. y)
    def projection_on(self, v):
        return v.mul(self.dot_product(v) / v.quadrance())
    def rejection_from(self, v):
        return self - self.projection_on(v)


import sys

file_input = sys.stdin

x_p1, y_p1, x_p2, y_p2 = map(int, file_input.readline().split())
p1_p2 = Vector(x_p2 - x_p1, y_p2 - y_p1)

q = int(file_input.readline())

for line in file_input:
    x_p, y_p = map(int, line.split())
    p1_p = Vector(x_p - x_p1, y_p - y_p1)
    r_v = p1_p.rejection_from(p1_p2)
    o_p = Vector(x_p, y_p)
    print(o_p - r_v.mul(2))

Solution (Python):
import sys
from itertools import starmap
readline = sys.stdin.readline
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
s = Segment(*starmap(complex, zip(*[map(int, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p1 = reflect(s, complex(*map(float, readline().split())))
    print("{0:.10f} {1:.10f}".format(p1.real, p1.imag))

Solution (Python):
import sys
from itertools import starmap
readline = sys.stdin.readline
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
s = Segment(*starmap(complex, zip(*[map(float, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p1 = reflect(s, complex(*map(float, readline().split())))
    print("{0:.10f} {1:.10f}".format(p1.real, p1.imag))

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

x1,y1,x2,y2 = [int(i) for i in input().split()] 
q = int(input())
for i in range(q):
    x,y = [int(i) for i in input().split()]
    a = [x2-x1,y2-y1]
    b = [x-x1,y-y1]
    co = dot(a,b) / dot(a,a)
    isec = [co*a[0]+x1,co*a[1]+y1]
    c = [isec[0] - x, isec[1] - y]
    print(isec[0]+c[0],isec[1]+c[1])

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&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 project(s, p):
    base = Vector(s.p2 - s.p1)
    a = Vector(p - s.p1)
    r = Vector.dot(a, base)
    r /= base.norm()
    return s.p1 + base * r


def reflect(s, p):
    proj = project(s, p)
    return p + (proj - p)*2


def main(args):
    x_p1, y_p1, x_p2, y_p2 = map(int, input().split())
    q = int(input())
    s = Segment((x_p1, y_p1), (x_p2, y_p2))
    for _ in range(q):
        x, y = map(int, input().split())
        p = Point(x, y)
        result = reflect(s, p)
        print('{:.10f} {:.10f}'.format(result.x, result.y))


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

Solution (Python):
xp1, yp1, xp2, yp2 = map(int, input().split())
q = int(input())

r = [xp2 - xp1, yp2 - yp1]

def a(p1,p2):
    s = (p1-xp1,p2-yp1)
    d = r[0] * s[0] + r[1] * s[1]
    a = xp1 + r[0] * d / (r[0]**2 + r[1]**2)
    b = yp1 + r[1] * d / (r[0]**2 + r[1]**2)
    return a,b

for i in range(q):
    x, y = map(int, input().split())
    x2,y2 = a(x, y)
    print(x + 2 * (x2 - x), y + 2 * (y2 - y))

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


if __name__ == '__main__':

    a, b, c, d = map(int, input().split())
    p1 = Vector2(a, b)
    p2 = Vector2(c, d)
    base = p2 - p1
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        p = Vector2(e, f)
        hypo = Vector2(e - a, f - b)
        proj = p1 + base * (hypo.dot(base) / float(base.x**2 + base.y**2))
        x = p + (proj - p) * 2
        ans.append(x)

    for x in ans:
        print(x.x, x.y)

Solution (Python):
import math

class Point():
    def __init__(self, x=None, y=None):
        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 projection(self, p):
        a = (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x) if self.p2.x != self.p1.x else float('inf')
        if a == 0:
            return (p.x, 2*self.p1.y - p.y)
        elif a == float('inf'):
            return (2*self.p1.x - p.x, p.y)
        else:
            b = self.p2.y - a*self.p2.x
            d = abs(-1*a*p.x + p.y - b)/math.sqrt(1 + a*a)
            ans_y = [p.y + math.sqrt(4*d*d/(a*a+1)), p.y - math.sqrt(4*d*d/(a*a+1))]
            ans_x = [p.x - a*(_y - p.y) for _y in ans_y]

            rst_x, rst_y = None, None
            tmp = abs(-1*a*ans_x[0] + ans_y[0] - b)/math.sqrt(1 + a*a) - d
            if tmp < abs(-1*a*ans_x[1] + ans_y[1] - b)/math.sqrt(1 + a*a) - d:
                rst_x, rst_y = ans_x[0], ans_y[0]
            else:
                rst_x, rst_y = ans_x[1], ans_y[1]
            return round(rst_x, 9), round(rst_y, 9)

x1, y1, x2, y2 = list(map(int, input().split(' ')))
line = Line(x1, y1, x2, y2)
q = int(input())
for i in range(q):
    x, y = list(map(int, input().split(' ')))
    p = Point(x, y)
    rst_x, rst_y = line.projection(p)
    print(rst_x, rst_y)

Solution (Python):

import math
EPS=1e-10


class Point():

    def __init__(self,x,y):
        self.x=x
        self.y=y
    
    def __sub__(self,p):
        return Point(self.x - p.x, self.y - p.y);
    def __add__(self,p):
        return Point(self.x + p.x, self.y + p.y)
           
    def __mul__(self,a): 
        return Point(self.x * a, self.y * a)
    def __truediv__(self,a): 
        return Point(self.x / a, self.y / a)
   
    def __str__(self):
       return  str(self.x)+','+str(self.y)
    def __repr__(self):
        return  'Point('+str(self.x)+','+str(self.y)+')'
    
    def __lt__(self, other):    
        if self.y-other.y==0:
            return self.x<other.x
        else:
            return self.y<other.y
            
    def __eq__(self, other):    
        return abs(self.x-other.x)<EPS and  abs(self.y-other.y)<EPS



class Segment():
    def __init__(self,p1, p2):
        self.p1=p1
        self.p2=p2
    def __str__(self):
        return  'segment:('+str(self.p1)+';'+str(self.p2)+')'
    def __repr__(self):
        return  'segment:('+str(self.p1)+';'+str(self.p2)+')'


class Circle():
    def __init__(self,c, r):
        self.c=c
        self.r=r

    def __str__(self):
       return  'Circle:(center point: '+str(self.c)+'; radius: '+str(self.r)+')'
    def __repr__(self):
       return  'Circle:(center point: '+str(self.c)+'; radius: '+str(self.r)+')'
   
    

class Polygon():
    def __init__(self,ps=[]):
        self.ps=ps
        self.size=len(ps)
  
    def __getitem__(self, i):
        return self.ps[i]  
    def __setitem__(self,i,p): 
        self.ps[i]=p               
    def __iter__(self):     
        return self.ps  
    
    def addpoint(self,i,p):
        self.ps.insert(i,p)
        self.size+=1
    def delpoint(self,i):
        self.size-=1
        return self.ps.pop(i)
    def sortYX(self):
        self.ps.sort()
        
    def __str__(self):
       return  'Polygon:'+str(tuple(self.ps))
    def __repr__(self):
       return  'Polygon:'+str(tuple(self.ps))
        
    def __len__(self):
        return len(self.ps)
    def __eq__(self, other):  
         return self.ps==other.ps
    
    def draw(self):
      
       turtle.screensize(800,800,"black")
       
       turtle.title("Polygon convex hull")
       turtle.setworldcoordinates(-400,-400,400,400) 

       
       
       
       t=turtle.Turtle() 
       
       
       t.pencolor("red")
       for pt in self.ps:
           t.goto(pt.x,pt.y)
           t.dot(10,'white')
       
 




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



def length(p):
    return math.sqrt(p.x * p.x + p.y * p.y)









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 project(s, p):
    base = s.p2 - s.p1
    r = dot(p - s.p1, base) / norm(base)
    return s.p1 + base * r 



def getDistance(a, b) :
    return length(a - b)


def getDistanceLP(l, p) :
    return abs( cross(l.p2 - l.p1, p - l.p1) / length(l.p2 - l.p1) )


    

def getDistanceSP(s, p) :
    if (dot(s.p2 - s.p1, p - s.p1) < 0.0):
        return length(p - s.p1)
    if (dot(s.p1 - s.p2, p - s.p2) < 0.0):
        return length(p - s.p2)
    return getDistanceLP(s, p)







def isOrthogonalSG(s1, s2) :
    return abs(dot(s1.p2 - s1.p1, s2.p2 - s2.p1))<EPS



def isParallelLN(s1,s2) :
    return abs(cross(s1.p2 - s1.p1, s2.p2 - s2.p1))<0





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

def ccw(p0, p1, p2) :
    a = p1 - p0
    b = p2 - p0
    if (cross(a, b) > EPS):
        return COUNTER_CLOCKWISE
    if (cross(a, b) < -EPS):
        return CLOCKWISE
    if (dot(a, b) < -EPS):
        return ONLINE_BACK
    if (norm(a) < norm(b)):
        return ONLINE_FRONT
    
    return ON_SEGMENT;


def toleft(p0,p1,p2):
    a = p1 - p0
    b = p2 - p0  
    tmp=cross(a,b)
    if tmp > EPS:
        return 1
    elif abs(tmp)<EPS and norm(a)<=norm(b):
        return 2  
    elif abs(tmp)<EPS and norm(a)>norm(b):
        return -2  
    else:
        return -1



def reflect(s, p) :
    return p + (project(s, p) - p) * 2.0


s= [int(x) for x in input().split()]
p1=Point(s[0],s[1])
p2=Point(s[2],s[3])
sg=Segment(p1,p2)
q=int(input())
for i in range(0,q):
    s= [int(x) for x in input().split()]
    p3=Point(s[0],s[1])
    pt=reflect(sg,p3)
    print(pt.x,pt.y)

Solution (Python):
from math import hypot

x1, y1, x2, y2 = map(int, input().split())
dx, dy = x2-x1, y2-y1
vector_base = hypot(dx, dy)
q = int(input())

for i in range(q):
    x3, y3 = map(int, input().split()) 
    r = ((x3-x1)*dx + (y3-y1)*dy) / (vector_base**2)
    tx, ty = x1+dx*r, y1+dy*r
    print('{:.08f}'.format(x3+2*(tx-x3)), '{:.08f}'.format(y3+2*(ty-y3)))

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)

xp1, yp1, xp2, yp2 = map(int, input().split())
q = int(input())

p1 = Vector(xp1, yp1)
p2 = Vector(xp2, yp2)
l = Line(p1, p2)

for _ in range(q):
    x, y = map(int, input().split())
    p = Vector(x, y)
    ref = l.refrection(p)
    print(ref)

Solution (Python):
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y) 
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
def v_diff(v1,v2):
    return v_sum(v1,scalar_multi(-1,v2))
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y+vector1.y*vector2.x

x1,y1,x2,y2 = map(int,input().split())
p1 = Vector(x1,y1)
p2 = Vector(x2,y2)

d = v_diff(p2,p1)

q = int(input())
for i in range(q):
    x,y = map(int,input().split())
    v = v_diff(Vector(x,y),p1)
    h = scalar_multi(dot(v,d)/d.norm_2(),d)
    w = v_sum(scalar_multi(2,v_diff(h,v)),v)
    print('{} {}'.format(v_sum(w,p1).x,v_sum(w,p1).y))

Solution (Python):
import sys
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 abs(self):
        return (self.x*self.x + self.y*self.y)**0.5

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


x1, y1, x2, y2 = map(int, input().split())
v1 = Vector(x1, y1)
v2 = Vector(x2, y2)
n = v2-v1
n /= n.abs()
m = n.ortho()

for _ in [0]*int(input()):
    x, y = map(int, input().split())
    v = Vector(x, y) - v1
    u = v - m * v.dot(m) * 2
    print(v1 + u)

Solution (Python):
from math import sqrt
x1, y1, x2, y2 = map(int, raw_input().split())
dx = x2 - x1
dy = y2 - y1

for i in xrange(input()):
    x, y = map(int, raw_input().split())
    a = float(dx * (x - x1) + dy * (y - y1)) / (dx ** 2 + dy ** 2)
    print "%.09f %0.09f" % (2 * x1 - x + 2 * a * dx, 2 * y1 - y + 2 * a * dy)

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

class Line(Segment):
    """
    直線クラス
    """
    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 + v


xp1,yp1,xp2,yp2 = map(float,input().split())
q = int(input())
ps = [list(map(int,input().split())) for i in range(q)]

p1 = Vector([xp1,yp1])
p2 = Vector([xp2,yp2])
L = Line(p1,p2)

for p in ps:
    ans = L.reflection(p)
    ans = [float(round(a,11)) for a in ans]
    print(*ans)

Solution (Python):
x1,y1,x2,y2=map(int,input().split())
p1,p2=complex(x1,y1),complex(x2,y2)
a=p2-p1
dis=(x1-x2)**2+(y1-y2)**2
for i in range(int(input())):
    p=complex(*map(int,input().split()))
    b=p-p1
    co=(a.real*b.real+a.imag*b.imag)/dis
    ans=p+2*(co*a-b)
    print(ans.real,ans.imag)