#K10436. Count Common Stop Pairs

    ID: 23246 Type: Default 1000ms 256MiB

Count Common Stop Pairs

Count Common Stop Pairs

You are given n bus routes. Each bus route is represented by a non-empty string where each character represents a bus stop. Two routes are said to share a common stop if their corresponding strings have at least one character in common.

Formally, for each route i (with stop set denoted as \(S_i\)), you need to count the number of pairs \((i, j)\) with \(i < j\) such that \(S_i \cap S_j \neq \emptyset\).

Your task is to write a program that reads the routes from standard input and outputs the number of such route pairs to standard output.

inputFormat

The input is read from stdin and has the following format:

The first line contains an integer n, the number of bus routes.
The following n lines each contain a string representing a bus route.

It is guaranteed that each route is non-empty and consists only of printable characters.

outputFormat

Output a single integer to stdout: the number of pairs of routes that have at least one common stop.

## sample
3
abc
bcd
def
2