luogu#P7930. [COCI 2021/2022 #1] Set

[COCI 2021/2022 #1] Set

Background

In the well-known game SET, there are cards with different numbers, shapes, colors, and so on. The player’s goal is to find an existing triplet of cards (a triple of cards, i.e., a combination of three cards) that satisfies certain rules. Marin and Josip quickly got bored with this game and made it harder.

Problem Description

In this problem, each card is defined as a length kk sequence consisting only of 1,2,31, 2, 3. There are nn cards. The cards are unordered, and it is guaranteed that the cards are pairwise different.

We define a SET as an unordered triplet of cards such that, for every position, the three sequences are either all the same or all different. Using the original wording, this is “same” or “pairwise different”. More rigorously, let the three sequences be Si,Sj,SkS_i, S_j, S_k. Then the following conditions must hold:

  • i<j<ki \lt j \lt k.
  • x[1,k]\forall x \in \left[1, k\right], we have Si(x)=Sj(x)=Sk(x)S_i(x) = S_j(x) = S_k(x) or Si(x)Sj(x)Sk(x)S_i(x) \neq S_j(x) \neq S_k(x).

For example, (1123,1322,1221)(1123, 1322, 1221) satisfies the rule: positions 1,31, 3 are the same, and positions 2,42, 4 are all different.

Given these sequences, find how many essentially different SETs can be formed.

Input Format

The first line contains two positive integers n,kn, k.

The next nn lines each contain a length kk sequence consisting only of 1,2,31, 2, 3, representing a card.

It is guaranteed that the sequences on the cards are all different.

Output Format

Output one integer in a single line, representing the number of essentially different SETs that can be formed.

3 4
1123
1322
1221

1

2 2
11
22

0

5 3
111
222
333
123
132

2

Hint

[Sample Explanation #3]

The two SETs that can be formed are (S1,S2,S3)(S_1, S_2, S_3) and (S1,S4,S5)(S_1, S_4, S_5).

[Constraints]

For all testdata, 1k121\le k\le 12, 1n3k1\le n\le 3^k, all SiS_i are different, and 1Si(x)31\le S_i(x) \le 3.

Subtask Special Constraints Score
11 k5k\le 5 1010
22 k7k\le 7 3030
33 No special constraints 7070

Notes

The total score for this problem is 110110 points.

This problem is translated from Croatian Open Competition in Informatics 2021/2022 Contest #1 T4 Set。

Translated by ChatGPT 5