Cards | 프로그래밍의 벗 PivotOJ
PivotOJ

Cards

시간 제한: 1000ms메모리 제한: 1024MB출처: LMIO 2018-2019BOJ 27348
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

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.

[이미지 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 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.

예제

예제 1

입력
3
IO
OI
AA
AA
OI
IO
출력
1

예제 2

입력
2
QW
XZ
AB
CD
출력
0
코드를 제출하려면 로그인하세요.