Cards
문제
In the attic of grandparents’ home Neringa has found a set of cards. Each card has four capital Latin letters written on it as a grid. The set has cards and all of them are distinct.
Neringa noticed that some cards may be placed next to each other so that the pairs of letters on both cards adjacent to the connecting edge would be identical.
Let’s call the pairs of cards that could paired in the way described above as matching. To match a pair of cards it is allowed to move them but not allowed to rotate or flip. A card can form multiple matching pairs.
[이미지 1] and [이미지 2] match: [이미지 3],
[이미지 4] and [이미지 5] match: [이미지 6], [이미지 7], [이미지 8], [이미지 9],
[이미지 10] and [이미지 11] do not match.
Figure 1: Matching and not matching pairs of cards. The second pair of cards can be matched in four different ways.
Calculate the amount of matching card pairs in the card set discovered by Neringa.
입력
The total amount of cards is given in the first row.
The remaining rows describe the cards. Each of the rows contains two capital Latin letters. One card is described by two consecutive input rows.
출력
Output the amount of matching card pairs.
예제
예제 1
3 IO OI AA AA OI IO
1
예제 2
2 QW XZ AB CD
0