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):
class Point:
    def __init__(self, x, y):
        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(self.x * other, self.y * other)
    def __floordiv__(self, other):
        return Point(self.x / other, self.y / other)
    def __repr__(self):
        return str(self.x) + ' ' + str(self.y)

class Vector(Point):
    pass

class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

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

def vector(p):
    return Vector(p.x, p.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 norm(v):
    return v.x**2 + v.y**2

def project(s, p):
    base = points_to_vector(s.p1, s.p2)
    hypo = points_to_vector(p, s.p1)
    r = dot(hypo, base) / norm(base)
    return s.p1 + base * r

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

import sys


s = list(map(int, input().split()))
p1 = Point(s[0], s[1])
p2 = Point(s[2], s[3])
segment = Segment(p1, p2)

q = int(input())
for i in range(q):
    x, y = map(int, input().split())
    p = Point(x, y)
    ans = reflect(segment, p)
    print(ans)

Solution (Python):
import math

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

    def __add__(self,a):
        return self.__class__(self.x+a.x,self.y+a.y)

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

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

    def __truediv__(self,d):
        return self.__class__(self.x/d,self.y/d)

    def __str__(self):
        return '%.10f %.10f'%(self.x,self.y)

    def abs(self):
        return self.norm()**(1.0/2.0)

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

    def rotate(self,d):
        r = math.pi*d/180.0
        return self.__class__( self.x*math.cos(r)-self.y*math.sin(r),
                               self.x*math.sin(r)+self.y*math.cos(r))

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

class Segment:
    def __init__(self,p1,p2):
        self.p1 = p1
        self.p2 = p2

def project(s,p):
    v = s.p2-s.p1
    r = v.dot(p-s.p1)/v.norm()
    return s.p1+v*r

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

def main():
    a,b,c,d = map(float,input().split())
    s = Segment(Point(a,b),Point(c,d))
    q = int(input())
    for _ in range(q):
        e,f = map(float,input().split())
        p = Point(e,f)
        print (reflect(s,p))


if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,d = map(float,input().split())
a = complex(a,b)
b = complex(c,d)
for _ in range(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):
def reflection(line, point):
    x0, y0, x1, y1 = line
    p, q = point
    x1 -= x0; y1 -= y0
    p -= x0; q -= y0
    cv = p*x1 + q*y1
    sv = p*y1 - q*x1
    cv2 = cv**2 - sv**2
    sv2 = 2*cv*sv
    dd = (p**2 + q**2)*(x1**2 + y1**2)
    if dd == 0:
        return x0 + p, y0 + q
    return x0 + (cv2 * p - sv2 * q) / dd, y0 + (sv2 * p + cv2 * q) / dd

def solve():
    x0, y0, x1, y1 = map(int, input().split())
    q = int(input())
    for i in range(q):
        x, y = map(int, input().split())
        print("%.16f %.16f" % reflection((x0, y0, x1, y1), (x, y)))
solve()

Solution (Python):
import math

EPS = 1e-10

class Segment():
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

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

    def __add__(self, point):
        
        return Point(self.x+point.x, self.y+point.y)

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

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

    def __truediv__(self, a):
        
        return Point(self.x/a, self.y/a)

    def __abs__(self):
        
        return math.sqrt(self.norm())

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

    def __eq__(self, point):
        
        return abs(self.x-point.x) < EPS and abs(self.y-point.y) <EPS

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 isOrthogonal(a, b):
    return dot(a, b) == 0

def isParallel(a, b):
    return cross(a, b) == 0

def project(s, p):
    
    base = s.p2 - s.p1
    r = dot(p-s.p1, base)/base.norm()
    return s.p1+base*r

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

if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    x1, y1, x2, y2 = map(int, input().split())
    s = Segment(Point(x1, y1), Point(x2, y2))

    q = int(input())
    for _ in range(q):
        x0, y0 = map(int, input().split())
        p = Point(x0, y0)
        reflection = reflect(s, p)
        print(reflection.x, reflection.y)

Solution (Python):
from math import pi, cos, sin, atan2
EPS = 10**(-9)

def eq(value1, value2):
    return abs(value1-value2) <= EPS

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.arg = atan2(y, x) 
    
    def __str__(self):
        return "{0:.8f} {1:.8f}".format(self.x, self.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, scal):
        return Point(self.x*scal, self.y*scal)
    
    def __truediv__(self, scal):
        return Point(self.x/scal, self.y/scal)
    
    def __eq__(self, other):
        return eq(self.x, other.x) and eq(self.y, other.y)

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

def Rotation(vec: Point, rad):
    return Point(vec.x*cos(rad)-vec.y*sin(rad), vec.x*sin(rad)+vec.y*cos(rad))


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


class Line():
    
    def __init__(self, a, b):
        self.a = a
        self.b = b
        self.arg = (a-b).arg % pi
    
    def __str__(self):
        return "[({0}, {1}) - ({2}, {3})]".format(self.a.x, self.a.y, self.b.x, self.b.y)

    
    def par(self, point):
        return Line(point, point+(self.a-self.b))

    
    def tan(self, point):
        return Line(point, point + Rotation(self.a-self.b, pi/2))


class Segment(Line):
    def __init__(self, a, b):
        super(Line, self).__init__(a, b)



def cross(vec1: Point, vec2: Point):
    return vec1.x*vec2.y - vec1.y*vec2.x


def dot(vec1: Point, vec2: Point):
    return vec1.x*vec2.x + vec1.y*vec2.y


def ccw(a, b, c):
    if cross(b-a, c-a) > EPS: return +1 
    if cross(b-a, c-a) < -EPS: return -1 
    if dot(c-a, b-a) < -EPS: return +2 
    if abs(b-a) < abs(c-a): return -2 
    return 0 



def projection(l, p):
    t = dot(l.b-l.a, p-l.a) / abs(l.a-l.b)**2
    return l.a + (l.b-l.a)*t


def reflection(l, p):
    return p + (projection(l, p) - p)*2

def isPararell(l1, l2):
    return eq(cross(l1.a-l1.b, l2.a-l2.b), 0)

def isVertical(l1, l2):
    return eq(dot(l1.a-l1.b, l2.a-l2.b), 0)


def isIntersect_lp(l, p):
    return abs(ccw(l.a, l.b, p)) != 1

def isIntersect_ll(l1, l2):
    return not isPararell(l1, l2) or isIntersect_lp(l1, l2.a)

def isIntersect_sp(s, p):
    return ccw(s.a, s.b, p) == 0

def isIntersect_ss(s1, s2):
    return ccw(s1.a, s1.b, s2.a)*ccw(s1.a, s1.b, s2.b) <= 0 and ccw(s2.a, s2.b, s1.a)*ccw(s2.a, s2.b, s1.b) <= 0

def isIntersect_ls(l, s):
    return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS

def isIntersect_cp(c, p):
    return abs(abs(c.p - p) - c.r) < EPS

def isIntersect_cl(c, l):
    return distance_lp(l, c.p) <= c.r + EPS

def isIntersect_cs(c, s):
    pass

def isIntersect_cc(c1, c2):
    pass


def distance_pp(p1, p2):
    return abs(p1-p2)

def distance_lp(l, p):
    return abs(projection(l,p)-p)

def distance_ll(l1, l2):
    return 0 if isIntersect_ll(l1, l2) else distance_lp(l1, l2.a)

def distance_sp(s, p):
    r = projection(s, p)
    if isIntersect_sp(s, r): return abs(r-p)
    return min(abs(s.a-p), abs(s.b-p))

def distance_ss(s1, s2):
    if isIntersect_ss(s1, s2): return 0
    return min([distance_sp(s1, s2.a), distance_sp(s1, s2.b), distance_sp(s2, s1.a), distance_sp(s2, s1.b)])

def distance_ls(l, s):
    if isIntersect_ls(l, s): return 0
    return min(distance_lp(l, s.a), distance_lp(l, s.b))


def crosspoint_ll(l1, l2):
    A = cross(l1.b - l1.a, l2.b - l2.a)
    B = cross(l1.b - l1.a, l1.b - l2.a)
    if eq(abs(A), 0) and eq(abs(B), 0): return l2.a
    return l2.a + (l2.b - l2.a) * B / A

def crosspoint_ss(s1, s2):
    return crosspoint_ll(s1, s2)

def crosspoint_lc(l, c):
    if eq(distance_lp(l, c.p), c.r): return [c.p]
    p = projection(l, c.p)
    e = (l.b - l.a) / abs(l.b-l.a)
    dis = (c.r**2-abs(p-c.p)**2)**0.5
    return [p + e*dis, p - e*dis]

def crosspoint_sc(s, c):
    pass

def crosspoint_cc(c1, c2):
    d = abs(c1.p-c2.p)
    if not abs(c1.r-c2.r) <= d <= c1.r+c2.r:
        return []
    mid_p = (c2.p * (c1.r**2-c2.r**2+d**2) + c1.p * (c2.r**2-c1.r**2+d**2)) / (2*d**2)
    tanvec = Rotation(c1.p-c2.p, pi/2)
    return crosspoint_lc(Line(mid_p, mid_p+tanvec), c1)



def tangent_cp(c, p):
    return crosspoint_cc(c, Circle(p, (abs(p-c.p)**2 - c.r**2)**0.5))





import sys
input = sys.stdin.readline

def verify_1A():
    p1x, p1y, p2x, p2y = map(int, input().split())
    l = Line(Point(p1x, p1y), Point(p2x, p2y))
    Q = int(input())
    Query = [list(map(int, input().split())) for _ in range(Q)]
    for px, py in Query:
        p = Point(px, py)
        print(projection(l, p))

def verify_1B():
    p1x, p1y, p2x, p2y = map(int, input().split())
    l = Line(Point(p1x, p1y), Point(p2x, p2y))
    Q = int(input())
    Query = [list(map(int, input().split())) for _ in range(Q)]
    for px, py in Query:
        p = Point(px, py)
        print(reflection(l, p))

verify_1B()

Solution (Python):
def project(x,y):
    base=[x2-x1,y2-y1]
    hypo=[x-x1,y-y1]
    r=(base[0]*hypo[0]+base[1]*hypo[1])/(base[0]**2+base[1]**2)
    return x1+base[0]*r,y1+base[1]*r


def reflect(x,y):
    px,py=project(x,y)
    return x+(px-x)*2,y+(py-y)*2


x1,y1,x2,y2=map(int,input().split())
q=int(input())
for i in range(q):
    x,y=map(int,input().split())
    print(*reflect(x,y))

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

x1, y1, x2, y2 = map(int, input().split())
p1=x1+y1*1j
p2=x2+y2*1j
l=p2-p1
l_norm=dot(l,l)         
q=int(input())

for x3, y3 in (map(int, input().split()) for _ in [0]*q):
    p3=x3+y3*1j
    a=p3-p1
    k=dot(a,l)/l_norm
    projection_vector=k*l
    reflect_vector=projection_vector-a
    print(x3+2*reflect_vector.real,y3+2*reflect_vector.imag)

Solution (Python):
EPS = 0.0000000001

class Point:
    
    global EPS
    
    def __init__(self, x = 0, y = 0):
        self.x = x
        self.y = y
        
        
    def __add__(a, b):
        s = a.x + b.x
        t = a.y + b.y
        return Point(s, t)
        
    def __sub__(a, b):
        s = a.x - b.x
        t = a.y - b.y
        return Point(s, t)
            
    def __mul__(self, a):
        s = a * self.x
        t = a * self.y
        return Point(s, t)
        
    def __truediv__(self, a):
        s = self.x / a
        t = self.y / a
        return Point(s, t)
            
            
            
            
    def norm(self):
        return self.x * self.x + self.y * self.y
        
    def abs(self):
        return self.norm() ** 0.5
            
    
            
            
    def __eq__(self, other):
        return abs(self.x - other.y) < self.EPS and abs(self.y - other.y) < self.EPS
            
            
            
    def dot(self, b):
        return self.x * b.x + self.y * b.y
        
    def cross(self, b):
        return self.x * b.y - self.y * b.x
    
    
class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

def project(s, p):
    base = s.p2 - s.p1
    hypo = p - s.p1
    r = hypo.dot(base) / base.norm()
    return s.p1 + base * r

def reflecton(s, p):
    return p + (project(s,p) - p) * 2


nums=list(map(int,input().split()))
s = Segment(Point(nums[0], nums[1]), Point(nums[2], nums[3]))

n = int(input())
for i in range(n):
    nums=list(map(int,input().split()))
    p = Point(nums[0], nums[1])
    x = reflecton(s, p)
    print(x.x, x.y)

Solution (Python):
import cmath
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


PI = cmath.pi
TAU = cmath.pi * 2


class Point:
    EPS = 1e-9

    def __init__(self, c: complex):
        self.c = c

    @property
    def x(self):
        return self.c.real

    @property
    def y(self):
        return self.c.imag

    @staticmethod
    def from_rect(x: float, y: float):
        return Point(complex(x, y))

    @staticmethod
    def from_polar(r: float, phi: float):
        return Point(cmath.rect(r, phi))

    def __add__(self, p):
        """
        :param Point p:
        """
        return Point(self.c + p.c)

    def __iadd__(self, p):
        """
        :param Point p:
        """
        self.c += p.c
        return self

    def __sub__(self, p):
        """
        :param Point p:
        """
        return Point(self.c - p.c)

    def __isub__(self, p):
        """
        :param Point p:
        """
        self.c -= p.c
        return self

    def __mul__(self, f: float):
        return Point(self.c * f)

    def __imul__(self, f: float):
        self.c *= f
        return self

    def __truediv__(self, f: float):
        return Point(self.c / f)

    def __itruediv__(self, f: float):
        self.c /= f
        return self

    def __repr__(self):
        return "({}, {})".format(round(self.x, 10), round(self.y, 10))

    def __neg__(self):
        return Point(-self.c)

    def __eq__(self, p):
        return abs(self.c - p.c) < self.EPS

    def __abs__(self):
        return abs(self.c)

    def dot(self, p):
        """
        内積
        :param Point p:
        :rtype: float
        """
        return self.x * p.x + self.y * p.y

    def det(self, p):
        """
        外積
        :param Point p:
        :rtype: float
        """
        return self.x * p.y - self.y * p.x

    def dist(self, p):
        """
        距離
        :param Point p:
        :rtype: float
        """
        return abs(self.c - p.c)

    def r(self):
        """
        原点からの距離
        :rtype: float
        """
        return abs(self.c)

    def phase(self):
        """
        原点からの角度
        :rtype: float
        """
        return cmath.phase(self.c)

    def angle(self, p, q):
        """
        p に向かってる状態から q まで反時計回りに回転するときの角度
        :param Point p:
        :param Point q:
        :rtype: float
        """
        return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c)) % TAU

    def area(self, p, q):
        """
        p, q となす三角形の面積
        :param Point p:
        :param Point q:
        :rtype: float
        """
        return abs((p - self).det(q - self) / 2)

    def projection_point(self, p, q, allow_outer=False):
        """
        線分 pq を通る直線上に垂線をおろしたときの足の座標
        :param Point p:
        :param Point q:
        :param allow_outer: 答えが線分の間になくても OK
        :rtype: Point|None
        """
        diff_q = q - p
        
        r = (self - p).dot(diff_q) / abs(diff_q)
        
        phase = diff_q.phase()

        ret = Point.from_polar(r, phase) + p
        if allow_outer or (p - ret).dot(q - ret) < self.EPS:
            return ret
        return None

    def reflection_point(self, p, q):
        """
        直線 pq を挟んで反対にある点
        :param Point p:
        :param Point q:
        :rtype: Point
        """
        
        r = abs(self - p)
        
        angle = p.angle(q, self)
        
        angle = (q - p).phase() - angle
        return Point.from_polar(r, angle) + p

    def on_segment(self, p, q):
        """
        点が線分 pq の上に乗っているか
        :param Point p:
        :param Point q:
        :rtype: bool
        """
        return abs((p - self).det(q - self)) < self.EPS and (p - self).dot(q - self) < self.EPS


p1x, p1y, p2x, p2y = list(map(float, sys.stdin.buffer.readline().split()))
Q = int(sys.stdin.buffer.readline())
XY = [list(map(float, sys.stdin.buffer.readline().split())) for _ in range(Q)]

p1 = Point.from_rect(p1x, p1y)
p2 = Point.from_rect(p2x, p2y)

for x, y in XY:
    p = Point.from_rect(x, y)
    ans = p.reflection_point(p1, p2)
    print('{:.10f} {:.10f}'.format(ans.x, ans.y))

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

def main():
    x1, y1, x2, y2 = map(int, input().split())
    q = int(input())
    if x2 - x1 == 0:
        for i in range(q):
            xp, yp = map(int, input().split())
            print(xp + 2 * (x1 - xp), yp)
    else:
        m = (y2 - y1) / (x2 - x1)
        for i in range(q):
            xp, yp = map(int, input().split())
            yq = (2 * m * (xp - x1) + yp * (m * m - 1) + 2 * y1) / (1 + m * m)
            xq = xp - m * (yq - yp)
            print(xq, yq)

if __name__ == "__main__":
    main()

Solution (Python):


import array
from fractions import Fraction
import math
import os
import sys


class Vec(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        super().__init__()

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

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

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

    def __rmul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __truediv__(self, scalar):
        return Vec(self.x / scalar, self.y / scalar)

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

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

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

    def __idiv__(self, scalar):
        self.x /= scalar
        self.y /= scalar
        return self

    def __neg__(self):
        return Vec(-self.x, -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 abs2(self):
        return self.x * self.x + self.y * self.y

    def __abs__(self):
        return math.sqrt(float(self.abs2()))

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


def main():
    x1, y1, x2, y2 = read_ints()
    Q = read_int()
    for _ in range(Q):
        x, y = read_ints()
        print(*solve(Vec(x1, y1), Vec(x2, y2), Vec(x, y)))


def solve(u, v, a):
    v -= u
    a -= u
    b = Fraction(2 * v.dot(a), v.abs2()) * v - a
    b += u
    return float(b.x), float(b.y)





DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Solution (Python):


import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

class Geometry:

    def add(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1+x2, y1+y2)

    def sub(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1-x2, y1-y2)

    def mul(self, a, b):
        x1, y1 = a
        if not isinstance(b, tuple):
            return (x1*b, y1*b)
        x2, y2 = b 
        return (x1*x2, y1*y2)

    def dot(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*x2 + y1*y2

    def norm(self, a):
        x, y = a
        return x**2 + y**2

    def project(self, seg, p):
        """ 線分segに対する点pの射影 """
        p1, p2 = seg
        base = self.sub(p2, p1)
        r = self.dot(self.sub(p, p1), base) / self.norm(base)
        return self.add(p1, self.mul(base, r))

    def reflect(self, seg, p):
        """ 線分segを対称軸とした点pの線対称の点 """
        return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2))

gm = Geometry()
x1, y1, x2, y2 = MAP()
seg = ((x1, y1), (x2, y2))
Q = INT()
for i in range(Q):
    x, y  = MAP()
    res = gm.reflect(seg, (x, y))
    print(*res)

Solution (Python):
if __name__ == "__main__":
    x_p1, y_p1, x_p2, y_p2 = map(lambda x: int(x), input().split())
    q = int(input())

    p1p2 = (x_p2 - x_p1, y_p2 - y_p1)
    for _ in range(q):
        x_p0, y_p0 = map(lambda x: int(x), input().split())
        p1p0 = (x_p0 - x_p1, y_p0 - y_p1)
        r = (p1p2[0] * p1p0[0] + p1p2[1] * p1p0[1]) / (p1p2[0] ** 2 + p1p2[1] ** 2)
        proj_p = (x_p1 + p1p2[0] * r, y_p1 + p1p2[1] * r)
        proj_v = (proj_p[0] - x_p0, proj_p[1] - y_p0)
        print(x_p0 + 2 * proj_v[0], y_p0 + 2 * proj_v[1])

Solution (Python):
import math
class Point:
	def __init__(self,x,y):
		self.x = x
		self.y = y
	def __add__(self,p):
		return Point(self.x+p.x,self.y+p.y)
	def __sub__(self,p):
		return Point(self.x-p.x,self.y-p.y)
	def __mul__(self,p):
		return Point(self.x*p,self.y*p)

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 Dis(a,b):
	return math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) )
def Dis2(a,b):
	return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)

x1,y1,x2,y2 = map(int,input().split())
p1 = Point(x1,y1)
p2 = Point(x2,y2)
p1p2_dis2 = Dis2(p1,p2)

q = int(input())
for i in range(q):
	x,y = map(int,input().split())
	p = Point(x,y)
	dot_res = Dot(p-p1,p2-p1)
	h = (p2-p1) * (dot_res/p1p2_dis2) + p1

	p_ = h + (h-p)
	print(p_.x,p_.y)

Solution (Python):
def Reflection(point, begin, end):
	tmp = (point-begin) / (end-begin)
	return tmp.conjugate() * (end-begin) + begin

a, b, c, d = map(int, input().split())
q, r = complex(a, b), complex(c, d)
n = int(input())
for _ in range(n):
	x, y = map(int, input().split())
	p = complex(x, y)
	refl = Reflection(p, q, r)
	print(refl.real, refl.imag)

Solution (Python):




L1=input().split( )
[xp1,yp1,xp2,yp2]=[int(L1[0]),int(L1[1]),int(L1[2]),int(L1[3])]
direction=[xp2-xp1,yp2-yp1]
norm_direc=[(xp2-xp1)/((xp2-xp1)**2+(yp2-yp1)**2)**(1/2),(yp2-yp1)/((xp2-xp1)**2+(yp2-yp1)**2)**(1/2)]
q=int(input())
L=[]
for i in range(q):
    L2=input().split( )
    L.append([int(L2[0]),int(L2[1])])

Point=[]
for i in range(q):
    Point.append([(L[i][0]-xp1),(L[i][1]-yp1)])

Vec=[]
for i in range(q):
    Vec.append([L[i][0]-xp1,L[i][1]-yp1])
Proj=[]
for i in range(q):
    inter=Vec[i][0]*norm_direc[0]+Vec[i][1]*norm_direc[1]
    Proj.append([norm_direc[0]*inter,norm_direc[1]*inter])








vert=[]
for i in range(q):
    vert.append([Vec[i][0]-Proj[i][0],Vec[i][1]-Proj[i][1]])
L3=[]
for i in range(q):
    a=L[i][0]-2*vert[i][0]
    b=L[i][1]-2*vert[i][1]
    if -0.00000001<a<0.00000001:
        a=0
    if -0.00000001<b<0.00000001:
        b=0
    L3.append([a,b])

for i in range(q):
    print(*L3[i])

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):
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 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):
    Plist = ConvexHull(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

x1,y1,x2,y2 = inpl()
a,b = Point(x1,y1), Point(x2,y2)
q = inp()
for _ in range(q):
    p = Point(*inpl())
    q = Vfoot(a,b,p)
    q += q-p
    print(*q.tolist())

Solution (Python):
pp = list(map(int, input().split()))
n = int(input())

def project(bb, p=pp):
    ans = []
    a = (p[2]-p[0], p[3]-p[1])
    b = (bb[0]-p[0], bb[1]-p[1])
    if dot(a,b)<0:
        a = (-a[0], -a[1])
    c = dot(a,b)/length(a)**2
    ans += [c*v+p[i] for i, v in enumerate(a)] 
    return ans
    
def length(vector):
    ans = 0
    for i in vector:
        ans += i**2
    return ans**(1/2)
    
def dot(a, b):
    n = len(a)
    if n != len(b):
        return None
    ans = 0
    for i, j in zip(a, b):
        ans += i*j
    return ans
    
def reflection(b, p = pp):
    a = project(b)
    ans = (b[0]+2*(a[0]-b[0]), b[1]+2*(a[1]-b[1]))
    print(f'{ans[0]:.8f} {ans[1]:.8f}')
    
for i in range(n):
    b = list(map(int, input().split()))
    reflection(b)

Solution (Python):
import math


class Point:
    EPS = 1 << 10

    def __init__(self, x, y):
        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(self.x*other, self.y*other)

    def __floordiv__(self, other):
        return Point(self.x/other.x, self.y/other.y)

    def __abs__(self):
        return math.sqrt(self.norm())

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

    def __eq__(self, other):
        EPS = self.__class__.EPS
        return abs(self.x-other.x) < EPS and abs(self.x-other.x) < EPS

    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 isOrthogonal(self, a, b):
        return a.dot(b) == 0.0

    def isParallel(self, a, b):
        return a.cross(b) == 0.0

    def __str__(self):
        return str(self.x)+' '+str(self.y)


class Vector(Point):
    pass


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

    def isOrthogonal(s1, s2):
        return (s1.p2-s1.p1).dot(s2.p2-s2.p1) == 0.0

    def isParallel(s1, s2):
        return (s1.p2-s1.p1).cross(s2.p2-s2.p1) == 0.0


class Line(Segment):
    pass


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


class Polygon:
    def __init__(self, *points):
        self.points = points


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


def project(s, p):
    base = s.p2 - s.p1
    r = (p-s.p1).dot(base) / base.norm()
    return s.p1 + base * r


x1, y1, x2, y2 = map(int, input().split())
p1, p2 = Point(x1, y1), Point(x2, y2)
s = Segment(p1, p2)

q = int(input())
for i in range(q):
    p = Point(*map(int, input().split()))
    print(reflect(s, p))

Solution (Python):
import math


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

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

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

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

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

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

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

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


x1, y1, x2, y2 = map(int, input().split())
v12 = Vector2(x2-x1, y2-y1).norm()
q = int(input())
for i in range(q):
    x, y = map(int, input().split())
    v = Vector2(x-x1, y-y1)
    d = v12.dot(v)
    a = Vector2(x1+v12.x*d, y1+v12.y*d)
    p = Vector2(x, y)
    b = p+(a-p)*2.0
    print(f"{b.x:.9f} {b.y:.9f}")