This page is still under construction.

Parts of this page are still being built. What you see may change.

Points

Time limit3sMemory limit128 MB

Summary
Given a pattern point set and up to 20 query sets, decide for each whether it is similar to the pattern under rotation, translation, reflection, and scaling.
Level

Medium7 of 10

Topics
Geometry, Sorting, Hash map, Divide and conquer
Solved
No attempts yet

Problem

You are given a set of grid points in the plane (points whose two Cartesian coordinates are both integers); we call this set the pattern. You are also given a family of other sets of grid points in the plane.

For each set, decide whether it is similar to the pattern, i.e. whether it can be turned into a set identical to the pattern by some combination of rotations, translations, reflections and dilations (scalings).

For example, the set {(0,0),(2,0),(2,1)}\{(0,0),(2,0),(2,1)\} is similar to the set {(6,1),(6,5),(4,5)}\{(6,1),(6,5),(4,5)\}, but it is not similar to the set {(4,0),(6,0),(5,−1)}\{(4,0),(6,0),(5,-1)\}.

Write a program that:

  • reads the pattern and the family of investigated sets from standard input,
  • determines which of the investigated sets are similar to the pattern,
  • writes the result to standard output.

Input

The first line contains a single integer kk (1≤k≤25 0001 \le k \le 25\,000) — the number of points in the pattern. Each of the next kk lines contains two integers separated by a single space; the ii-th of them holds the coordinates xix_i and yiy_i (−20 000≤xi,yi≤20 000-20\,000 \le x_i, y_i \le 20\,000) of the ii-th pattern point. The points of the pattern are pairwise distinct.

The next line contains the number of sets to investigate, nn (1≤n≤201 \le n \le 20). Then follow the descriptions of the nn sets. Each description begins with a line containing a single integer ll (1≤l≤25 0001 \le l \le 25\,000) — the number of points in that set. Each of the next ll lines contains two integers xx and yy (−20 000≤x,y≤20 000-20\,000 \le x, y \le 20\,000), the coordinates of one point. The points belonging to the same set are pairwise distinct.

Output

Print nn lines, one for each investigated set. On the ii-th line print TAK (Polish for “yes”) if the ii-th set is similar to the pattern, or NIE (Polish for “no”) otherwise.

Hint

Examples7

  1. Example 1

    Input
    3
    0 0
    2 0
    2 1
    2
    3
    4 1
    6 5
    4 5
    3
    4 0
    6 0
    5 -1
    
    Expected output
    TAK
    NIE
    
  2. Example 2

    Input
    1
    5 5
    3
    1
    0 0
    1
    100 -3
    2
    1 1
    2 2
    
    Expected output
    TAK
    TAK
    NIE
    
  3. Example 3

    Input
    2
    0 0
    4 0
    3
    2
    1 1
    5 5
    2
    -2 -2
    -2 3
    3
    0 0
    1 0
    2 0
    
    Expected output
    TAK
    TAK
    NIE
    
  4. Example 4

    Input
    4
    0 0
    1 0
    1 1
    0 1
    4
    4
    0 0
    2 0
    2 2
    0 2
    4
    0 0
    1 1
    0 2
    -1 1
    4
    0 0
    2 0
    2 1
    0 1
    4
    0 0
    0 1
    1 1
    1 0
    
    Expected output
    TAK
    TAK
    NIE
    TAK
    
  5. Example 5

    Input
    3
    0 0
    4 0
    0 3
    3
    3
    0 0
    0 4
    3 0
    3
    0 0
    8 0
    8 6
    3
    0 0
    5 0
    0 5
    
    Expected output
    TAK
    TAK
    NIE
    
  6. Example 6

    Input
    3
    0 0
    2 0
    2 1
    3
    3
    2 1
    0 0
    2 0
    3
    10 10
    14 10
    14 12
    3
    0 0
    2 0
    1 2
    
    Expected output
    TAK
    TAK
    NIE
    
  7. Example 7

    Input
    3
    0 0
    1 0
    3 0
    4
    3
    0 0
    2 0
    6 0
    3
    5 5
    6 6
    8 8
    3
    0 0
    2 0
    3 0
    3
    0 0
    1 0
    2 0
    
    Expected output
    TAK
    TAK
    TAK
    NIE