1287B.md (2152B)
1 Source: https://codeforces.com/problemset/problem/1287/B 2 3 B. Hyperset 4 5 time limit per test 6 7 3 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look. 22 23  24 25 Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$. 26 27 Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set. 28 29 Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table. 30 31 Input 32 33 The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features. 34 35 Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct. 36 37 Output 38 39 Output a single integer — the number of ways to choose three cards that form a set. 40 41 Examples 42 43 Input 44 45 ``` 46 3 3 47 SET 48 ETS 49 TSE 50 ``` 51 52 Output 53 54 ``` 55 1 56 ``` 57 58 Input 59 60 ``` 61 3 4 62 SETE 63 ETSE 64 TSES 65 ``` 66 67 Output 68 69 ``` 70 0 71 ``` 72 73 Input 74 75 ``` 76 5 4 77 SETT 78 TEST 79 EEET 80 ESTE 81 STES 82 ``` 83 84 Output 85 86 ``` 87 2 88 ``` 89 90 Note 91 92 In the third example test, these two triples of cards are sets: 93 94 1. "SETT", "TEST", "EEET" 95 2. "TEST", "ESTE", "STES"