Hacker went home and started preparing to hack AtForces. He found that the system contains only passwords from the stolen list and that the system determines the equivalence of the passwords aa and bb as follows:

  • two passwords aa and bb are equivalent if there is a letter, that exists in both aa and bb;
  • two passwords aa and bb are equivalent if there is a password cc from the list, which is equivalent to both aa and bb.

If a password is set in the system and an equivalent one is applied to access the system, then the user is accessed into the system.

For example, if the list contain passwords "a", "b", "ab", "d", then passwords "a", "b", "ab" are equivalent to each other, but the password "d" is not equivalent to any other password from list. In other words, if:

  • admin's password is "b", then you can access to system by using any of this passwords: "a", "b", "ab";
  • admin's password is "d", then you can access to system by using only "d".

Only one password from the list is the admin's password from the testing system. Help hacker to calculate the minimal number of passwords, required to guaranteed access to the system. Keep in mind that the hacker does not know which password is set in the system.

Input

The first line contain integer nn (1n21051≤n≤2⋅105) — number of passwords in the list. Next nn lines contains passwords from the list – non-empty strings sisi, with length at most 5050 letters. Some of the passwords may be equal.

It is guaranteed that the total length of all passwords does not exceed 106106 letters. All of them consist only of lowercase Latin letters.

Output

In a single line print the minimal number of passwords, the use of which will allow guaranteed to access the system.

 

Examples

  input

4
a
b
ab
d

output

 

2

 

input

 

3
ab
bc
abc

 

output

 

1

 

 

代码实现  

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 15;
int pre[30], vis[maxn]; //vis数组记录出现的字母种类
void init() {      //并查集数组处理
    for (int i = 0; i < 26; i++)
        pre[i] = i;
}
int Find(int x) { //并查集找根节点函数
    if (x == pre[x])
        return x;
    else
        return pre[x] = Find(pre[x]);
}
void unite(int x, int y) { 
    int xx = Find(x);
    int yy = Find(y);
    if (yy > xx)
        swap(xx, yy);
    if (xx != yy)
        pre[xx] = yy;
    return;
}
int main(){
    init();
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str; 
        int x = Find(str[0] - 'a'); //先处理字符串第一个字母 赋值给x
        vis[x] = 1;  //记录该字母
        for (int j = 1; j < str.length(); j++) { //对字符串剩余字母处理
            int y = str[j] - 'a';
            vis[y] = 1;
            unite(x, y);
        }
    }
    int cnt = 0;
    for (int i = 0; i < 26; i++) {
        if (pre[i] == i && vis[i] == 1) //如果是根节点且记录出现过  vis数组避免了该字母没出现过却满足pre[i] == i情况
cnt++; } cout << cnt << endl; return 0; }

 

题目大意

如果两字符串有相同的字母,那么他们相等;
如果这两个字符串分别和第三个字符串有相同字母 ,那么这两个字符串也相等;
综上 用到并查集 将字符串字母拆分开来, 对26个字母使用并查集;
  然后几个根节点就是答案