P7866 "EVOI-RD1" Xiao Xinxin.

Background

A standard deck of playing cards has $54$ cards. After removing the two Jokers, there are $52$ cards. In the same deck, each card can appear at most once. A deck has four suits: spades ($\texttt{spade}$), hearts ($\texttt{heart}$), clubs ($\texttt{club}$), and diamonds ($\texttt{diamond}$). Each suit has $13$ ranks, from $\texttt{A}$ to $\texttt{K}$. In this problem, the four suits are written as $\texttt{S,H,C,D}$. We define that any card is written as **suit + rank**, and we use $\texttt{T}$ to represent $\texttt{10}$, for example $\texttt{SA,D5,HT,CQ}$.

Description

Xinxin has **two decks without Jokers**. She will take out $n$ cards from these cards. Xinxin created a combination called **"Xiao Xinxin"**. It is defined as follows: take any $3$ cards. If these $3$ cards have the **same rank**, and the suits contain **exactly two** different suits, then this is called one "Xiao Xinxin" set. For example, $\texttt{H3,S3,S3}$ is one "Xiao Xinxin" set. After three cards form a **"Xiao Xinxin"**, Xinxin will remove them from the pile, and they **cannot be used again**. Now Xinxin wants you to help her count: what is the maximum number of **"Xiao Xinxin"** sets that can be formed from these cards.

Input Format

The first line contains a positive integer $n$. Lines $2$ to $n+1$ each contain one playing card.

Output Format

Output the maximum number of "Xiao Xinxin" sets that can be formed from these $n$ cards.

Explanation/Hint

**This problem uses bundled testdata.** + $\texttt{Subtask 1 (10 pts)}$: $1 \le n \le 3$. + $\texttt{Subtask 2 (20 pts)}$: $1 \le n \le 5$. + $\texttt{Subtask 3 (30 pts)}$: $1 \le n \le 20$. + $\texttt{Subtask 4 (10 pts)}$: $1 \le n \le 70$. + $\texttt{Subtask 5 (30 pts)}$: no special constraints. For $100\%$ of the data, $1 \le n \le 104$, and it is guaranteed that all input cards exist in two decks without Jokers. Translated by ChatGPT 5