5599: Borya and Hanabi

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述

你玩过哈纳比吗?如果没有,那么你必须尝试一下!此问题涉及游戏的简化版本。

总体而言,游戏有25种类型的卡片(5种不同的颜色和5种不同的值)。博里亚拿着n张牌。游戏有些复杂,因为除了博里亚本人之外,每个人都可以看到博里亚的牌。博里亚知道他拥有哪些牌,但他对它们所在的顺序一无所知。请注意,博里亚可以拥有多张相同的牌(对于25种牌中的每一张,他确切地知道他有多少张这种类型的牌)。
    其他玩家的目标是达到博里亚知道他的每张牌的颜色和数字值的状态。为此,其他人可以给他提示。提示可以有两种类型:颜色提示和值提示。
颜色提示是这样的:一个玩家命名一些颜色并指向该颜色的所有卡片。
    同样,值提示也是如此。一个玩家命名一些值并指向包含该值的所有卡片。
    确定其他玩家应该为博里亚确定每张卡片的颜色和价值提供最少的提示次数
    Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.
    Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has).

    The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints.
    A color hint goes like that: a player names some color and points at all the cards of this color.
    Similarly goes the value hint. A player names some value and points at all the cards that contain the value.
    Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.
Input
The first line contains integer n (1≤n≤100) − the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters − R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.
Output
Print a single integer − the minimum number of hints that the other players should make.
Examples
Input
2
G3 G3
Output
0
Input
4
G4 R4 R3 B3
Output
2
Input
5
B1 Y1 W1 G1 R1
Output
4
Note
In the first sample Borya already knows for each card that it is a green three.
In the second sample we can show all fours and all red cards.
In the third sample you need to make hints about any four colors.

输入格式

第一行包含整数 n (1≤n≤100) − Borya 的牌数。下一行包含 n 张卡片的描述。每张卡的描述由正好两个字符组成。第一个字符显示颜色(总的来说,这个位置可以包含五个不同的字母 - R,G,BY,W)。第二个字符显示卡的值(从 1 到 5 的数字)。博里亚不知道他们所在的卡片的确切顺序。

输出格式

打印单个整数 - 其他玩家应做出的最小提示数


Input
2
G3 G3
Output
0
Input
4
G4 R4 R3 B3
Output
2
Input
5
B1 Y1 W1 G1 R1
Output
4


注意

在第一个样本中,Borya已经知道每张牌都是绿3。
在第二个样本中,我们可以显示所有四和所有红牌。
在第三个示例中,您需要对任何四种颜色进行提示。

输入样例 复制

2
G3 G3

输出样例 复制

0