Cards

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

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 2×22 \times 2 grid. The set has NN 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.

and match: ,

and match: , , , ,

and 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 NN is given in the first row.

The remaining 2N2N 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.

제한

  • 1N264=456,9761 ≤ N ≤ 26^{4} = 456\\,976