#P3298. Fountain Flow Matching Pairs

    ID: 16555 Type: Default 1000ms 256MiB

Fountain Flow Matching Pairs

Fountain Flow Matching Pairs

In this problem, you are given historical records on water flow indices from six different fountain regions over NN years. In the ii-th year, the water flow indices for the six regions are represented by Ai,1,Ai,2,,Ai,6A_{i,1}, A_{i,2}, \dots, A_{i,6} (each index is a non-negative integer less than 2302^{30}).

Your task is to count the number of pairs of different years (i,j)(i, j) (with i<ji < j) such that exactly KK fountain regions have the same water flow index in both years. In other words, you need to count the number of pairs (i,j)(i, j) satisfying:

[ \sum_{r=1}^{6} \mathbf{1}(A_{i,r} = A_{j,r}) = K, ]

where (\mathbf{1}(\cdot)) is the indicator function that is 1 when the condition is true and 0 otherwise.

Note: It is guaranteed that the 6 values in each record pertain to distinct fountain regions.

inputFormat

The first line contains two integers $N$ and $K$, where $N$ is the number of years, and $K$ is the exact number of regions that must match between two years.

Then follow $N$ lines, each containing 6 space-separated non-negative integers: $A_{i,1}, A_{i,2}, \dots, A_{i,6}$.

outputFormat

Output a single integer, the number of pairs $(i, j)$ (with $i < j$) that satisfy the condition that exactly $K$ fountain regions have the same water flow indexes.

sample

3 2
1 2 3 4 5 6
1 2 7 8 9 10
1 3 3 4 5 11
1