Under construction

Still being built. Things may change

Polygonal Line Shape Search

Time limit1sMemory limit128 MB

Summary
Given a template orthogonal polygonal line, report which of up to 50 other lines match its shape under rotation and translation.
Level

Medium5 of 10

Topics
Geometry, Implementation, Hash map
Solved
No attempts yet

Problem

Several polygonal lines are given on the xy-plane. Given a list of polygonal lines together with one template, determine which of the polygonal lines have the same shape as the template.

A polygonal line is made of straight segments that are each parallel to the x-axis or the y-axis. It is described by the coordinates of its vertices listed in order from the start point to the end point, and it turns exactly 90 degrees at every intermediate vertex. A single polygonal line never passes through the same point twice.

Two polygonal lines have the same shape when one can be made to coincide exactly with the other using only rotation and translation in the plane (no scaling and no reflection/flip). Listing a polygonal line's vertices in reverse order — from the end point back to the start point — describes the same polygonal line, so a line and its reversal are considered identical.

Write a program that reports which polygonal lines have the same shape as the template.

Input

The input consists of several datasets. A line containing a single 0 marks the end of the input.

Each dataset has the following format:

n
Polygonal line 0
Polygonal line 1
Polygonal line 2
...
Polygonal line n

nn is the number of polygonal lines to search through, an integer with 1≤n≤501 \le n \le 50. Polygonal line 0 is the template; the remaining lines are numbered 11 through nn.

Each polygonal line is given as:

m
x1 y1
x2 y2
...
xm ym

mm is the number of vertices of the polygonal line (3≤m≤103 \le m \le 10). xix_i and yiy_i, separated by a space, are the x- and y-coordinates of the ii-th vertex (−10000<xi<10000-10000 < x_i < 10000, −10000<yi<10000-10000 < y_i < 10000).

Output

For each dataset, print the numbers of the polygonal lines (from 11 to nn) that have the same shape as the template, one per line in ascending order, with no leading or trailing spaces.

After the numbers for each dataset, print a line containing exactly five + characters (+++++).

Examples2

  1. Example 1

    Input
    5
    5
    0 0
    2 0
    2 1
    4 1
    4 0
    5
    0 0
    0 2
    -1 2
    -1 4
    0 4
    5
    0 0
    0 1
    -2 1
    -2 2
    0 2
    5
    0 0
    0 -1
    2 -1
    2 0
    4 0
    5
    0 0
    2 0
    2 -1
    4 -1
    4 0
    5
    0 0
    2 0
    2 1
    4 1
    4 0
    4
    4
    -60 -75
    -60 -78
    -42 -78
    -42 -6
    4
    10 3
    10 7
    -4 7
    -4 40
    4
    -74 66
    -74 63
    -92 63
    -92 135
    4
    -12 22
    -12 25
    -30 25
    -30 -47
    4
    12 -22
    12 -25
    30 -25
    30 47
    3
    5
    -8 5
    -8 2
    0 2
    0 4
    8 4
    5
    -3 -1
    0 -1
    0 7
    -2 7
    -2 16
    5
    -1 6
    -1 3
    7 3
    7 5
    16 5
    5
    0 1
    0 -2
    8 -2
    8 0
    17 0
    0
    
    Expected output
    1
    3
    5
    +++++
    3
    4
    +++++
    +++++
    
  2. Example 2

    Input
    2
    3
    0 0
    2 0
    2 2
    3
    0 0
    0 2
    -2 2
    3
    0 0
    2 0
    2 3
    0
    
    Expected output
    1
    +++++