#K61437. Count Similar Pairs in Binary Strings

    ID: 31309 Type: Default 1000ms 256MiB

Count Similar Pairs in Binary Strings

Count Similar Pairs in Binary Strings

You are given n binary strings. Two binary strings are considered similar if they differ in exactly one position. Your task is to count the number of pairs of strings that are similar.

Formally, given a list of binary strings \(S = [s_1, s_2, \dots, s_n]\), compute the number of pairs \((i,j)\) with \(1 \le i < j \le n\) such that the Hamming distance between \(s_i\) and \(s_j\) is exactly 1. The Hamming distance between two strings \(s\) and \(t\) is defined as \(\sum_{k=1}^{m} \mathbf{1}_{\{s_k \neq t_k\}}\), where \(m\) is the length of the strings and \(\mathbf{1}\) is the indicator function.

inputFormat

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

n
s1
s2
...
sn

Here, the first line contains an integer n representing the number of binary strings. The following n lines each contain a binary string of equal length.

outputFormat

Output a single integer to stdout representing the number of similar pairs of binary strings.

## sample
3
101
111
011
2

</p>