Problem:
Reflection

For given three points p1, p2, p, find the reflection point x of p onto p1p2.

Input

xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−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 ≤ xi, yi ≤ 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 in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            MyPoint a = new MyPoint(input[0], input[1]);
            MyPoint b = new MyPoint(input[2], input[3]);

            Segment s = new Segment(a, b);

            int q = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < q; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                MyPoint p = new MyPoint(input[0], input[1]);

                sb.AppendLine(Reflect(s, p).ToString());
            }
            Console.Write(sb);
        }

        static MyPoint Reflect(Segment s, MyPoint p)
        {
            return p + (Project(s, p) - p) * 2;
        }

        static MyPoint Project(Segment s, MyPoint p)
        {
            MyPoint b = s.p2 - s.p1;
            double r = Dot(p - s.p1, b) / b.Norm;
            return s.p1 + b * r;
        }

        static double Dot(MyPoint a, MyPoint b)
        {
            return a.x * b.x + a.y * b.y;
        }

        static double Cross(MyPoint a, MyPoint b)
        {
            return a.x * b.y - a.y * b.x;
        }
    }

    class MyPoint : IComparable<MyPoint>
    {
        static readonly double EPS = 1E-10;

        internal double x, y;

        public MyPoint(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public double Abs { get { return Math.Sqrt(Norm); } }
        public double Norm { get { return x * x + y * y; } }

        public static MyPoint operator +(MyPoint a, MyPoint b) { return new MyPoint(a.x + b.x, a.y + b.y); }
        public static MyPoint operator -(MyPoint a, MyPoint b) { return new MyPoint(a.x - b.x, a.y - b.y); }
        public static MyPoint operator *(MyPoint p, double d) { return new MyPoint(p.x * d, p.y * d); }
        public static MyPoint operator /(MyPoint p, double d) { return new MyPoint(p.x / d, p.y / d); }
        public static bool operator <(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) > EPS ? a.x < b.x : a.y < b.y; }
        public static bool operator >(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) > EPS ? a.x > b.x : a.y > b.y; }
        public static bool operator ==(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) < EPS && Math.Abs(a.y - b.y) < EPS; }
        public static bool operator !=(MyPoint a, MyPoint b) { return Math.Abs(a.x - b.x) >= EPS || Math.Abs(a.y - b.y) >= EPS; }

        public int CompareTo(MyPoint other)
        {
            return x != other.x ? (int)(x - other.x) : (int)(y - other.y);
        }

        public override bool Equals(object obj)
        {
            MyPoint other = obj as MyPoint;
            return Math.Abs(x - other.x) < EPS && Math.Abs(y - other.y) < EPS;
        }

        public override int GetHashCode()
        {
            return x.GetHashCode() ^ y.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0:f10} {1:f10}", x, y);
        }
    }

    class Segment
    {
        internal MyPoint p1, p2;

        public Segment(MyPoint a, MyPoint b)
        {
            p1 = a;
            p2 = b;
        }
    }
}