luogu#P7866. 「EVOI-RD1」小昕昕

「EVOI-RD1」小昕昕

Background

A standard deck of playing cards has 5454 cards. After removing the two Jokers, there are 5252 cards. In the same deck, each card can appear at most once.

A deck has four suits: spades (spade\texttt{spade}), hearts (heart\texttt{heart}), clubs (club\texttt{club}), and diamonds (diamond\texttt{diamond}). Each suit has 1313 ranks, from A\texttt{A} to K\texttt{K}.

In this problem, the four suits are written as S,H,C,D\texttt{S,H,C,D}.

We define that any card is written as suit + rank, and we use T\texttt{T} to represent 10\texttt{10}, for example SA,D5,HT,CQ\texttt{SA,D5,HT,CQ}.

Problem Description

Xinxin has two decks without Jokers. She will take out nn cards from these cards.

Xinxin created a combination called "Xiao Xinxin". It is defined as follows: take any 33 cards. If these 33 cards have the same rank, and the suits contain exactly two different suits, then this is called one "Xiao Xinxin" set. For example, H3,S3,S3\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 nn.

Lines 22 to n+1n+1 each contain one playing card.

Output Format

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

3
S3
H3
S3
1
7
ST
ST
HT
HT
CT
CT
DT
2
6
DA
HA
D4
C5
DA
D4
1

Hint

This problem uses bundled testdata.

  • Subtask 1 (10 pts)\texttt{Subtask 1 (10 pts)}: 1n31 \le n \le 3.
  • Subtask 2 (20 pts)\texttt{Subtask 2 (20 pts)}: 1n51 \le n \le 5.
  • Subtask 3 (30 pts)\texttt{Subtask 3 (30 pts)}: 1n201 \le n \le 20.
  • Subtask 4 (10 pts)\texttt{Subtask 4 (10 pts)}: 1n701 \le n \le 70.
  • Subtask 5 (30 pts)\texttt{Subtask 5 (30 pts)}: no special constraints.

For 100%100\% of the data, 1n1041 \le n \le 104, and it is guaranteed that all input cards exist in two decks without Jokers.

Translated by ChatGPT 5