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 Haskell (judge verdict: Accepted)

{-# LANGUAGE NamedFieldPuns #-}
import Control.Monad (replicateM_)
import Data.Foldable (traverse_)
import Data.Functor ((<$>))
import Numeric (showFFloat)

data Point = Point { x :: Double, y :: Double }

instance Show Point where
  show (Point{x, y}) = sf x ++ " " ++ sf y
     where
     sf x = showFFloat Nothing x $ ""

readLnPoint = do
  [x, y] <- map read . words <$> getLine
  return $ Point {x, y}

dot p1 p2 = x p1 * x p2 + y p1 * y p2
psub p1 p2 = Point { x = x p1 - x p2, y = y p1 - y p2 }
scale a (Point{x, y}) = Point { x = a * x, y = a * y }

reflection a b = scale (2 * dot a b / dot a a) a `psub` b

main = do
  (p1, p2) <- do
    [x1, y1, x2, y2] <- map read . words <$> getLine
    return ( Point {x = x1, y = y1}, Point {x = x2, y = y2} )
  q <- readLn
  let originP1   p = Point { x = x p - x p1, y = y p - y p1 }
      unOriginP1 p = Point { x = x p + x p1, y = y p + y p1 }
      a = p2 `psub` p1
  replicateM_ q $ readLnPoint >>= \p -> let b = originP1 p in print $ unOriginP1 $ reflection a b