#P3670. Spotty Cows Genomic Triple Selection

    ID: 16921 Type: Default 1000ms 256MiB

Spotty Cows Genomic Triple Selection

Spotty Cows Genomic Triple Selection

Farmer John has (N) spotty cows and (N) plain cows. Each cow's genome is a string of length (M) composed of the characters A, C, G, and T. After sequencing, he wants to select a set of three distinct positions (i < j < k) such that looking at the nucleotides in these positions distinguishes all spotty cows from all plain cows. Formally, for a chosen triple of positions, let

[ S = {(s_i, s_j, s_k) \mid \text{s is a spotty cow genome}}
] [ P = {(p_i, p_j, p_k) \mid \text{p is a plain cow genome}}
]

The triple is valid if (S \cap P = \emptyset). Your task is to count the number of valid triples of positions.

inputFormat

The first line contains two integers (N) and (M) (the number of cows in each group and the length of each genome respectively). The next (N) lines each contain a string of length (M) representing the genomes of the spotty cows. The following (N) lines each contain a string of length (M) representing the genomes of the plain cows.

outputFormat

Output a single integer, the number of sets of three distinct positions that can explain spottiness.

sample

1 3
ACT
GTA
1