#K36762. Telepod Swap Pairs

    ID: 25827 Type: Default 1000ms 256MiB

Telepod Swap Pairs

Telepod Swap Pairs

In this problem, you are given a set of telepod codes. A telepod pair is defined as a pair of codes that differ by exactly one swap of two characters. In other words, exactly two positions differ and the characters at these positions are swapped.

Your task is to count the number of such telepod pairs in each test case.

For example, swapping the two characters in "AB" yields "BA", which forms a valid telepod pair.

inputFormat

The input consists of multiple test cases. Each test case begins with an integer n (where n > 0) representing the number of telepod codes. The next n lines each contain a telepod code. The sequence of test cases is terminated by a line containing a single 0.

outputFormat

For each test case, output a single integer on a new line indicating the number of telepod pairs that differ by exactly one swap of two characters.

## sample
4
ABCD
ACBD
BACD
ACDB
0
3

</p>