PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000056. Các mật khẩu tương đương (Secret Passwords)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Các mật khẩu tương đương (Secret Passwords)

Secret Passwords

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn passwords. Each password is a nonempty string of lowercase English letters. Different entries in the list are not necessarily distinct.

Two passwords are directly linked if they share at least one letter, regardless of its position. This relation extends through chains: if the first password is linked to a second and the second is linked to a third, then the first and third belong to the same group even if they share no letter themselves.

The secret password is known to be one of the listed passwords. Trying a password lets you cover its entire linked group. Determine the minimum number of attempts required to cover the group of the secret password, whichever listed password it happens to be.

Input

The first line contains nn, followed by nn nonempty password strings.

Output

Print the minimum number of passwords to try.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20, ∑∣si∣≤1000\sum |s_i|\le1000; 1≤∣si∣≤501\le |s_i|\le50; every character is a lowercase letter a–z.
  • Subtask 2 (30 points): 1≤n≤42001\le n\le4200, ∑∣si∣≤105\sum |s_i|\le10^5; 1≤∣si∣≤501\le |s_i|\le50; every character is a lowercase letter a–z.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5, ∑∣si∣≤106\sum |s_i|\le10^6; 1≤∣si∣≤501\le |s_i|\le50; every character is a lowercase letter a–z.

Examples

Input

4
a
b
ab
d

Output

2

Explanation

Password ab connects a and b, producing one equivalence class {a,b,ab}; d is in another. One representative from each class suffices, so the answer is 2.