아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cards

시간 제한1초메모리 제한1024 MB

요약
각 카드는 2x2 격자의 네 글자로 주어지며, 변을 맞붙였을 때 인접한 두 글자 쌍이 같아지는 서로 다른 카드 쌍의 수를 센다.
난이도

보통10점 중 5점

유형
해시맵, 문자열, 배열
정답자
아직 제출이 없습니다

문제

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.

제한

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

예제2

  1. 예제 1

    입력
    3
    IO
    OI
    AA
    AA
    OI
    IO
    
    예상 출력
    1
    
  2. 예제 2

    입력
    2
    QW
    XZ
    AB
    CD
    
    예상 출력
    0