Under construction

Still being built. Things may change

PSET

Time limit5sMemory limit1024 MB

Summary
Count the triples of PSET cards that form a PSET, where each card may be flipped and the top and bottom SET cards each form a SET.
Level

Easy3 of 10

Topics
Brute force, Implementation
Solved
No attempts yet

Problem

PSET is a derivative of the game SET. The game SET has 81 cards, each of which has one, two or three of the same shapes. The shapes are (for this problem):

Arrow: Diamond: and Oval: .

Each group of shapes has a color, Red, Green or Blue (labeled R, G or B in case this page is black and white), and a fill type:

Empty: Striped: or Filled: .

This gives 81 possible combinations. Three cards are a SET if, for each property (count, color, fill and shape), the property is the same on all three cards or different on all three cards. For example, for the following cards, 1, 2 and 3 form a SET (different counts, same color, different fill, different shape), but 1, 2 and 4 do not form a SET. One reason is that 1 and 4 have the same count while 2 has a different count.

Given two cards, there is exactly one other card which forms a set with the first two.

We use the code {count}{color}{fill}{shape} to specify a SET card. For example, the cards above are 2GSD, 3GFA, 1GEO and 2BSA. {fill} is E, S or F for Empty, Striped or Filled. {shape} is A, D or O for Arrow, Diamond or Oval.

Each PSET card consists of two SET cards, both different from 2GSD, which form a SET with 2GSD. From the example above, these are 3GFA and 1GEO. The SET cards on the PSET card are placed one above the other and rotated 90 degrees. See the example below.

Three PSET cards form a PSET if (possibly after flipping a card) the top SET cards form a SET and the bottom SET cards form a SET.

In the example below, there are four PSETs: { 1, (flip) 2, 3 }, { 1, 2, 4 }, { (flip) 1, 3, 4 } and { 2, 3, (flip) 4 }.

Write a program which takes as input a collection of distinct PSET cards and outputs the number of (three card) PSETs.

Input

The input consists of multiple lines. The first line contains the number N of PSET cards to follow, where 4≤N≤204 \le N \le 20. This is followed by N lines, one per card. Each card line consists of a four character code for the top of the card, followed by a space and a four character code for the bottom of the card.

Output

The output consists of a single line that contains the integer number of PSETs in the input collection.

Examples1

  1. Example 1

    Input
    4
    3BFD 1RED
    1GSA 3GSO
    3REA 1BFO
    2REO 2BFA
    
    Expected output
    4