Problem:
Problem B: Polygonal Line Search

Multiple polygonal lines are given on the xy-plane.
Given a list of polygonal lines and a template,
you must find out polygonal lines
which have the same shape as the template.

A polygonal line consists of several line segments parallel to x-axis or
y-axis. It is defined by a list of xy-coordinates of vertices from the start-point to the end-point in order,
and always turns 90 degrees at each vertex.
A single polygonal line does not pass the same point twice.

Two polygonal lines have the same shape when they
fully overlap each other only with rotation and translation
within xy-plane (i.e. without magnification or a flip).
The vertices given in reverse order from the start-point to the end-point is the
same as that given in order.

Figure 1 shows examples of polygonal lines.
In this figure, polygonal lines A and B have the same shape.

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

Figure 1: Polygonal lines

Input

The input consists of multiple datasets.
The end of the input is indicated by a line which contains a zero.

A dataset is given as follows.

n

Polygonal line0

Polygonal line1

Polygonal line2

...

Polygonal linen

n is the number of polygonal lines for the object of search on
xy-plane.
n is an integer, and 1 <= n <= 50.
Polygonal line0 indicates the template.

A polygonal line is given as follows.

m

x1 y1

x2 y2

...

xm ym

m is the number of the vertices of a polygonal line (3 <= m <= 10).

xi and yi, separated by a space,
are the x- and y-coordinates
of a vertex, respectively (-10000 < xi < 10000, -10000 <yi < 10000).

Output

For each dataset in the input, your program should report numbers assigned to the polygonal lines that have the same shape as the template, in ascending order.
Each number must be written in a separate line without any other characters such as leading or trailing spaces.

Five continuous "+"s must be placed in a line at the end of each dataset.

Sample 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

Output for the Sample Input

1
3
5
+++++
3
4
+++++
+++++

Solution in C# (judge verdict: Accepted)

using System.IO;
using System;
using System.Diagnostics;



namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int om = int.Parse(Console.ReadLine());
                int[,] otable = new int[om, 2];
                for (int oj = 0; oj < om; oj++)
                {
                    string[] ostr = Console.ReadLine().Split(' ');
                    otable[oj, 0] = int.Parse(ostr[0]);
                    otable[oj, 1] = int.Parse(ostr[1]);
                }
                int[,] revotable = Rev(otable, om);
                int ox = otable[0, 0];
                int oy = otable[0, 1];
                for(int oj = 0; oj < om; oj++)
                {
                    otable[oj, 0] = otable[oj, 0] - ox;
                    otable[oj, 1] = otable[oj, 1] - oy;
                }
                Debug.WriteLine("after reversion");
                ox = revotable[0, 0];
                oy = revotable[0, 1];
                for (int oj = 0; oj < om; oj++)
                {

                    revotable[oj, 0] = revotable[oj, 0] - ox;
                    revotable[oj, 1] = revotable[oj, 1] - oy;
                    
                    Debug.WriteLine(revotable[oj, 0] + " " + revotable[oj, 1]);
                }

                for (int i = 0; i < n; i++)
                {
                    int m = int.Parse(Console.ReadLine());
                    int[,] table = new int[m, 2];
                    for (int j = 0; j < m; j++)
                    {
                        string[] str = Console.ReadLine().Split(' ');
                        table[j, 0] = int.Parse(str[0]);
                        table[j, 1] = int.Parse(str[1]);

                    }
                    // ???????????§??\???
                    int ox2 = table[0, 0];
                    int oy2 = table[0, 1];
                    for (int j = 0; j < m; j++)
                    {
                        table[j, 0] = table[j, 0] - ox2;
                        table[j, 1] = table[j, 1] - oy2;//?????????????????????
                    }

                    if (Checker(otable, table) || Checker(otable, Rot(table, 90)) || Checker(otable, Rot(table, 180)) || Checker(otable, Rot(table, 270))
                        || Checker(revotable, table) || Checker(revotable, Rot(table, 90)) || Checker(revotable, Rot(table, 180)) || Checker(revotable, Rot(table, 270)))
                    {
                        Console.WriteLine(i+1);
                    }
                    

                }
                Console.WriteLine("+++++");
            }
            //otable?????¢???????????????????????????????????§table(n???)????????§otable????????????????????´?????????????????¢????????????
            Console.ReadLine();
        }
        static int[,] Rev(int[,] table, int m) //?????????????§??????¨?????????????????????
        {
            int[,] tmp = new int[m, 2];
            for (int i = 0; i < m; i++)
            {
                tmp[i, 0] = table[m - 1 - i, 0];
                tmp[i, 1] = table[m - 1 - i, 1];
            }
            
            return tmp;
        }
        
        static int[,] Rot(int[,] table,int para) //?????¢?????????
        {
            int temp;
            switch (para)
            {
                case 90:
                    for(int j = 0; j< table.GetLength(0); j++)
                    {
                        temp = table[j, 0];
                        table[j, 0] = -table[j, 1];
                        table[j, 1] = temp;
                    }
                    break;
                case 180:
                    for (int j = 0; j < table.GetLength(0); j++)
                    {
                        table[j, 0] = -table[j, 0];
                        table[j, 1] = -table[j, 1];
                    }
                    break;
                case 270:
                    for(int j = 0; j < table.GetLength(0); j++)
                    {
                        temp = table[j, 0];
                        table[j, 0] = table[j, 1];
                        table[j, 1] = -temp;
                    }
                    break;

            }
            return table;

        }


        static bool Checker(int[,] t1, int[,] t2) //?????´??????????????§??????
        {
            if (t1.GetLength(0) != t2.GetLength(0)) return false;
            bool result = true;
            for (int i = 0; i < t1.GetLength(0); i++)
            {
                if (t1[i, 0] != t2[i, 0] || t1[i, 1] != t2[i, 1]) result = false;            
            }
            return result;
        }
    }
}