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

class Vector:
    def __init__(self, x=None, y=None):
        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, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.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 norm(self):
        return self.x * self.x + self.y * self.y

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

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        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 reflect(s, p):
    return p + (project(s, p) - p) * 2

def read_and_print_results(s, n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p = Vector(int(line[0]), int(line[1]))
        x = reflect(s, p)
        print('{0:0.10f} {1:0.10f}'.format(x.x, x.y))

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

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

q=int(input())

if xp1==xp2:
    for i in range(q):
        x0,y0=map(int,input().split())
        print('{:.10f}'.format(2*xp1-x0),'{:.10f}'.format(y0))
else:
    a=float((yp2-yp1)/(xp2-xp1))
    for i in range(q):
        x0,y0=map(int,input().split())
        x=a*((y0-yp1)-a*(x0-xp1))/(1+a**2)+x0
        y=(a*(a*y0+x0-xp1)+yp1)/(1+a**2)
        print('{:.10f}'.format(2*x-x0),'{:.10f}'.format(2*y-y0))

Solution (Python):
class Vector:
    __slots__ = ['x', 'y']

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

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

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

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

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

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


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


x1, y1, x2, y2 = map(float, input().split())
p1, p2 = Vector(x1, y1), Vector(x2, y2)
n = (p2 - p1) / (p2 - p1).norm()

q = int(input())

for _ in range(q):
    p = Vector(*map(float, input().split()))
    p_prj = p1 + n * dot(p - p1, n)
    p_ref = p_prj * 2 - p
    print('{:.10f} {:.10f}'.format(p_ref.x, p_ref.y))

Solution (Python):


from typing import List
from math import sqrt

EPS = 1e-10


def float_equal(x: float, y: float) -> bool:
    return abs(x - y) < EPS


class Point:

    def __init__(self, x: float=0.0, y: float=0.0) -> None:
        self.x = x
        self.y = y

    def __repr__(self) -> str:
        return "Point({}, {})".format(self.x, self.y)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Point):
            
            return NotImplemented
        return float_equal(self.x, other.x) and \
            float_equal(self.y, other.y)

    def __add__(self, other: 'Point') -> 'Point':
        return Point(self.x + other.x, self.y + other.y)

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

    def __mul__(self, k: float) -> 'Point':
        return Point(self.x * k, self.y * k)

    def __rmul__(self, k: float) -> 'Point':
        return self * k

    def __truediv__(self, k: float) -> 'Point':
        return Point(self.x / k, self.y / k)

    def __lt__(self, other: 'Point') -> bool:
        return self.y < other.y \
            if abs(self.x - other.x) < EPS \
            else self.x < other.x

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

    def abs(self):
        return sqrt(self.norm())

    def dot(self, other: 'Point') -> float:
        return self.x * other.x + self.y * other.y

    def cross(self, other: 'Point') -> float:
        return self.x * other.y - self.y * other.x

    def is_orthogonal(self, other: 'Point') -> bool:
        return float_equal(self.dot(other), 0.0)

    def is_parallel(self, other: 'Point') -> bool:
        return float_equal(self.cross(other), 0.0)


Vector = Point


class Segment:

    def __init__(self, p1: Point = None, p2: Point = None) -> None:
        self.p1: Point = Point() if p1 is None else p1
        self.p2: Point = Point() if p2 is None else p2

    def __repr__(self) -> str:
        return "Segment({}, {})".format(self.p1, self.p2)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Segment):
            
            return NotImplemented
        return self.p1 == other.p1 and self.p2 == other.p2

    def vector(self) -> Vector:
        return self.p2 - self.p1

    def is_orthogonal(self, other: 'Segment') -> bool:
        return self.vector().is_orthogonal(other.vector())

    def is_parallel(self, other: 'Segment') -> bool:
        return self.vector().is_parallel(other.vector())

    def projection(self, p: Point) -> Point:
        v = self.vector()
        vp = p - self.p1
        return v.dot(vp) / v.norm() * v + self.p1

    def reflection(self, p: Point) -> Point:
        x = self.projection(p)
        return p + 2 * (x - p)


Line = Segment


class Circle:

    def __init__(self, c: Point=None, r: float=0.0) -> None:
        self.c: Point = Point() if c is None else c
        self.r: float = r

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Circle):
            return NotImplemented
        return self.c == other.c and self.r == other.r

    def __repr__(self) -> str:
        return "Circle({}, {})".format(self.c, self.r)


def main() -> None:
    x1, y1, x2, y2 = [int(x) for x in input().split()]
    p1 = Point(x1, y1)
    p2 = Point(x2, y2)
    l = Line(p1, p2)

    q = int(input())

    for _ in range(q):
        x, y = [int(x) for x in input().split()]
        p = Point(x, y)
        a = l.reflection(p)
        print(a.x, a.y)


if __name__ == "__main__":
    main()

Solution (Python):
class Point(object):
    __slots__ = ["x", "y"]

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

    def __iter__(self):
        yield self.x
        yield self.y

    def __add__(self, other: "Point") -> "Point":
        return Point(self.x + other.x, self.y + other.y)

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

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

    def project(self, vector: "Vector") -> "Point":
        return (vector * (Vector(vector.p1, self).dot(vector) / vector.norm)).p2

    def reflect(self, vector: "Vector") -> "Point":
        return self + (self.project(vector) - self) * 2


class Vector(object):
    __slots__ = ["p1", "p2", "x", "y", "norm", "abs"]

    def __init__(self, p1: Point, p2: Point):
        self.p1 = p1
        self.p2 = p2
        self.x = p2.x - p1.x
        self.y = p2.y - p1.y
        self.norm = self.x ** 2 + self.y ** 2
        self.abs = abs(self.x + self.y)

    def __mul__(self, s):
        return Vector(self.p1, Point(self.p1.x + self.x * s, self.p1.y + self.y * s))

    def __lt__(self, other: "Vector"):
        return other.abs > self.abs

    def __gt__(self, other: "Vector"):
        return other.abs < self.abs

    def dot(self, other: "Vector"):
        return self.x * other.x + self.y * other.y

    def cross(self, other: "Vector"):
        return self.x * other.y - self.y * other.x


if __name__ == "__main__":
    x1, y1, x2, y2 = map(int, input().split())
    vector1 = Vector(Point(x1, y1), Point(x2, y2))
    for point in (Point(*map(int, input().split())) for _ in [0]*int(input())):
        print(*point.reflect(vector1))

Solution (Python):
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
def MI(): return map(int, input().split())



"""
x,y,s,t = map(float, input().split())
a = int(input())
s-=x
t-=y
while a:
    a -= 1
    p,q = map(float, input().split())
    p-=x
    q-=y
    ans_x = s*(q*t+p*s)/(t*t+s*s)
    ans_y = t*(q*t+p*s)/(t*t+s*s)
    print(x+ans_x, y+ans_y)
"""


p1x,p1y,c,d = MI()
q = II()
if p1x == c:
    f = 0
elif p1y == d:
    f = 1
else:
    f = 2
    m = (d-p1y)/(c-p1x)
for _ in range(q):
    px,py = MI()
    if not f:
        a = 2*p1x-px
        b = py
    elif f == 1:
        a = px
        b = 2*p1y-py
    else:
        a = (2*py+(1/m-m)*px+2*m*p1x-2*p1y)/(m+1/m)
        b = -1/m*(a-px)+py
    print(a,b)

Solution (Python):





import sys
input = sys.stdin.readline

from math import cos,sin,radians,sqrt

def Reflection(p1,p2):
    (x,y) = p2
    (tx,ty) = Projection(p1,(x,y))
    rx = (tx - x) * 2 + x 
    ry = (ty - y) * 2 + y
    return (rx,ry)


def Projection(p1,p2):
    (x1,y1,x2,y2) = p1
    if (x1*x1+y1*y1 > x2*x2 + y2*y2):
        (x1,y1,x2,y2) = (x2,y2,x1,y1)
    (x3,y3) = p2

    tx = x2 -x1
    ty = y2 -y1
    l = sqrt(tx*tx+ty*ty)

    nx = tx / l
    ny = ty / l
    pl = nx * (x3 - x1)  + ny * (y3 - y1)
    return (nx * pl + x1, ny * pl + y1 )


def main():
    (x1,y1,x2,y2) = map(int,input().split())
    for i in range(int(input())):
        (x3,y3) = map(int,input().split())
        print('{:.10f} {:.10f}'.format(*Reflection((x1,y1,x2,y2),(x3,y3))))

    
if __name__ == '__main__':
    main()

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

xp = complex(xp2- xp1, yp2 - yp1)

for _ in range(q):
    x, y = map(int, input().split())
    xpi = complex(x - xp1, y - yp1)
    dot = xp.real * xpi.real + xp.imag * xpi.imag
    v1 = dot * xp / (abs(xp) ** 2)
    v2 = v1 - xpi
    ans = complex(x, y) + v2 * 2
    print("{:.9f} {:.9f}".format(ans.real, ans.imag))

Solution (Python):




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


def proj(p1, p2, p):
    x1, y1 = p1
    x2, y2 = p2
    x, y = p

    v1 = (x2-x1, y2-y1)
    v2 = (x-x1, y-y1)
    r = dprod(v1, v2) / dprod(v1, v1)

    return (x1 + r*v1[0], y1 + r*v1[1])


def refl(p1, p2, p):
    px, py = p
    hx, hy = proj(p1, p2, p)
    return (px + 2.0*(hx - px), py + 2.0*(hy - py))


def run():
    x1, y1, x2, y2 = [int(i) for i in input().split()]
    q = int(input())

    for _ in range(q):
        x, y = [int(i) for i in input().split()]
        print("{:.10f} {:.10f}".format(*refl((x1, y1), (x2, y2), (x, y))))


if __name__ == '__main__':
    run()

Solution (Python):
import math
from typing import Union


class Point(object):
    __slots__ = ['x', 'y']

    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: Union[int, float]):
        return Point(self.x * other, self.y * other)

    def __repr__(self):
        return f"({self.x},{self.y})"


class Segment(object):
    __slots__ = ['pt1', 'pt2', 'vector']

    def __init__(self, x: Point, y: Point):
        self.pt1 = x
        self.pt2 = y
        self.vector = self.pt2 - self.pt1

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

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

    def norm(self):
        return pow(self.vector.x, 2) + pow(self.vector.y, 2)

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

    def projection(self, pt: Point)-> Point:
        t = self.dot(Segment(self.pt1, pt)) / pow(self.abs(), 2)
        return Point(self.pt1.x + t * self.vector.x, self.pt1.y + t * self.vector.y)

    def reflection(self, pt: Point) -> Point:
        return self.projection(pt) * 2 - pt

    def __repr__(self):
        return f"{self.pt1},{self.pt2},{self.vector}"


def main():
    p0_x, p0_y, p1_x, p1_y = map(int, input().split())
    seg = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
    num_query = int(input())
    for i in range(num_query):
        pt_x, pt_y = map(int, input().split())
        reflection = seg.reflection(Point(pt_x, pt_y))
        print("{:.10f} {:.10f}".format(reflection.x, reflection.y))
    return


main()

Solution (Python):
sx, sy, ex, ey = (int(n) for n in input().split(" "))
trial = int(input())
for _ in range(trial):
    x, y = (int(n) for n in input().split(" "))
    if sx == ex:
        print(-x, y)
    elif sy == ey:
        print(x, -y)
    else:
        grad = (ey - sy) / (ex - sx)
        y_seg = sy - (grad * sx)
        per_grad = -1 / grad
        per_y_seg = y - (per_grad * x)
        ans_x = (y_seg - per_y_seg) / (-1 * (grad - per_grad))
        ans_y = per_grad * ans_x + per_y_seg
        diff_x = ans_x - x
        diff_y = diff_x * per_grad
        print(ans_x + diff_x, ans_y + diff_y)

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

def equals(a, b):
    return abs(a - b) < 1e-10


class Point:
    def __init__(self, x=0, y=0):
        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, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

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

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

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

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


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


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) / base.norm()
    return s.p1 + base * r


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


if __name__ == '__main__':
    x1, y1, x2, y2 = [int(v) for v in input().split()]
    s = Segment(Point(x1, y1), Point(x2, y2))
    q = int(input())
    ans = []
    for i in range(q):
        x, y = [int(v) for v in input().split()]
        p = Point(x, y)
        ans.append(reflect(s, p))

    for v in ans:
        print('{0:.10f} {1:.10f}'.format(v.x, v.y))