The Lottery WINNER

시간 제한1초메모리 제한2048 MB

요약
각 12진법 복권 번호에서 두 글자가 10과 11을 나타낼 때, 모든 문자열에 등장하는 가장 작은 문자 집합의 크기를 구한다.
난이도

보통10점 중 6점

유형
그리디, 문자열, 해시맵, 완전 탐색
정답자
아직 제출이 없습니다

문제

WINNER is fed up with implementing the Z-function for the 500-th time at his new accountant job at NUP, and now he is looking for a quick way to retire. Thanks to his wide network of connections, he managed to obtain the winning numbers from all the nn lotteries in Paphos. These winning numbers are written in base 1212, where the numbers can include leading zeros.

However, the lotteries couldn't agree on a standard for representing the digits 1010 and 1111 using letters (from the uppercase English alphabet), so each lottery uses its own choice of two letters for these values. Despite having access to this information, WINNER is still uncertain about the exact rules for winning. He suspects that, in order to claim a prize, he only needs to correctly guess at least one digit from the winning number for each lottery.

WINNER forgot how to write with pen and paper, so he needs help figuring out the minimum number of unique alphanumerics he should learn in order to "win" (according to his understanding) at all the lotteries.

입력

The input begins with a single integer nn (1≤n≤2.5⋅1051 \leq n \leq 2.5 \cdot 10^5), representing the number of lotteries.

Each of the next nn lines contains a number in base 1212, representing the winning numbers for each lottery. For each line, there is an uppercase letter that means the digit 1010, and a different uppercase letter that means the digit 1111. This line can contain only digits and these two letters.

It is guaranteed that the total length of all the numbers is at most 4⋅1064 \cdot 10^6.

출력

The output should consist of a single integer, kk, indicating the minimum number of unique alphanumerics WINNER needs to learn in order to believe he can win every lottery.

예제1

  1. 예제 1

    입력
    4
    EEXEE
    X221
    DEE
    2555539BD
    
    예상 출력
    2