You are given M M strings, each of length N N. The i i-th string is called S i S i .…
- User
You are given M M strings, each of length N N. The i i-th string is called S i S i . The strings contain only the characters 0 0, 1 1, or ? ?.
You must replace every ? ? with either a 0 0 or a 1 1, hence obtaining M M binary strings. If you perform these replacements optimally, find the maximum possible sum of Hamming distances between each pair of strings.
Formally, your aim is to maximize
∑ i
1 M ∑ j
i + 1 M f ( S i , S j ) i=1 ∑ M
j=i+1 ∑ M f(S i ,S j ) where f ( S i , S j ) f(S i ,S j ) denotes the Hamming distance between strings S i S i and S j S j .
The Hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different. For example, the Hamming distance between 1001 1001 and 0011 0011 is 2 2, since they differ at the first and third characters.
Input Format The first line of input will contain a single integer T T, denoting the number of test cases. Each test case consists of multiple lines of input. The first line of each test case contains two space-separated integers N N and M M — the length of the strings and the number of strings, respectively. The next M M lines contains the strings each of length N N. Output Format For each test case, output on a new line the maximum sum of Hamming distances between each pair of strings that can be obtained.
Constraints 1 ≤ T ≤ 1 0 5 1≤T≤10 5
1 ≤ N ≤ 1.5 ⋅ 1 0 5 1≤N≤1.5⋅10 5
2 ≤ M ≤ 3 ⋅ 1 0 5 2≤M≤3⋅10 5
The sum of N × M N×M over all test cases won't exceed 3 ⋅ 1 0 5 3⋅10 5 . The strings contain only 0 0, 1 1, or ? ?.
- Assistant