Олимпиадный тренинг

Задача 31926. Snowflake classification


Stella studies snowflakes, measuring the length of their six rays, and has already collected a lot of data. Now Stella is going to determine how many different types of snowflakes she has found. She considers snowflakes to be the same if the snowflakes can be combined after being rotated and/or flipped.
Write a program to help Stella classify snowflakes.
The first input line contains one integer N (2 ≤ N ≤ 100000). Then N lines follow, each containing 6 integers a1 a2 a3 a4 a 5 a6 from 1 to 109 separated by spaces – lengths of snowflake rays in clockwise order.
Output a single integer – the number of different snowflakes found by Stella.

Enter Output
5
1 2 3 4 5 6
3 4 5 6 1 2
3 2 1 4 5 6
6 5 4 3 2 1
2 3 6 5 4 1
2
Note
Snowflakes 1 and 2 and 4 after rotation or after turning over and snowflakes 3 and 5 after turning and turning coincide.