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;

class Program
{
  public struct Vector
  {
    public double x, y;
  }

  public struct Segment
  {
    public Vector p1, p2;
  }

  public static Vector project(Segment seg, Vector p)
  {
    Vector baseV, v, pro;
    baseV.x = seg.p2.x - seg.p1.x;
    baseV.y = seg.p2.y - seg.p1.y;

    v.x = p.x - seg.p1.x;
    v.y = p.y - seg.p1.y;

    double r = dot(v, baseV) / norm(baseV);

    pro.x = seg.p1.x + baseV.x*r;
    pro.y = seg.p1.y + baseV.y*r;
    return pro;
  }

  public static Vector reflect(Segment seg, Vector p)
  {
    Vector v;
    v.x = p.x + (project(seg, p).x - p.x ) * 2.0;
    v.y = p.y + (project(seg, p).y - p.y ) * 2.0;
    return v;
  }

  public static double norm(Vector v)
  {
    return v.x*v.x + v.y*v.y;
  }

  public static double dot(Vector v1, Vector v2)
  {
    return v1.x*v2.x + v1.y*v2.y;
  }

  public static void Main()
  {
    string[] s = Console.ReadLine().Split(' ');
    Vector v1, v2;
    v1.x = int.Parse(s[0]);
    v1.y = int.Parse(s[1]);
    v2.x = int.Parse(s[2]);
    v2.y = int.Parse(s[3]);

    Segment seg;
    seg.p1 = v1;
    seg.p2 = v2;

    int n = int.Parse(Console.ReadLine());
    for(int i=0; i<n; i++)
      {
	string [] s2 = Console.ReadLine().Split(' ');
	Vector v;
	v.x = int.Parse(s2[0]);
	v.y = int.Parse(s2[1]);

	Vector ans = reflect(seg, v);
	Console.WriteLine("{0:f10} {1:f10}", ans.x, ans.y);
      }
  }
}