#P7866. Maximize Little Xinxin Pairs

    ID: 21051 Type: Default 1000ms 256MiB

Maximize Little Xinxin Pairs

Maximize Little Xinxin Pairs

In this problem, you are given n playing cards drawn from two decks (each deck being a standard 52-card deck without jokers). Each card is represented by its suit followed by its rank. The suits are denoted by H (hearts), S (spades), C (clubs), and D (diamonds), and the ranks can be any string (for example, 3, 5, etc.).

A special combination called Little Xinxin is defined based on three cards of the same rank that involve exactly two distinct suits. In other words, if you pick any three cards with the same rank, and the suits among them are exactly two different types, they form one valid Little Xinxin. For instance, the triple H3, S3, S3 is a valid combination because all cards have rank 3 and the suits present are hearts and spades.

When a valid combination is formed using three cards, these cards are removed from the hand and cannot be used again. Your task is to determine the maximum number of Little Xinxin combinations that can be formed from the given set of cards.

The condition for a valid combination in LaTeX is as follows:

For three cards with rank \(r\) and suits \(s_1, s_2, s_3\), the combination is valid if
\(s_1, s_2, s_3\) contains exactly 2 distinct elements.

inputFormat

The first line contains an integer n representing the number of cards. The following line (or lines) contains n space-separated strings, each representing a card. Each card is formatted as a suit character (H, S, C, or D) immediately followed by its rank (for example, H3 or S10).

outputFormat

Output a single integer, the maximum number of valid Little Xinxin combinations that can be formed from the given cards.

sample

3
H3 S3 S3
1