Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

Intransitive

Peter has some unconventional dice. A number can appear multiple times on their faces, and the numbers are not necessarily between 1 and 6. For example, he has three dice (A,B,CA,B,C), with the following numbers on their faces:

A: 2, 2, 4, 4, 9, 9
B: 1, 1, 6, 6, 8, 8
C: 3, 3, 5, 5, 7, 7
If Panna uses die AA and Peter uses die BB in a game where the winner is the one who rolls a higher number (neither wins in the case of a tie), then Panna has an advantage. This can be shown by considering the 36 possible ABA−B roll pairs and counting how many times the number rolled on AA is greater than the number rolled on BB. In our case:
(2,1),(2,1)
(2,1),(2,1)
(4,1),(4,1)
(4,1),(4,1)
(9,1),(9,1),(9,6),(9,6),(9,8),(9,8)
(9,1),(9,1),(9,6),(9,6),(9,8),(9,8)

Here, we went through the numbers on die AA one by one and paired them with numbers from die BB that they are greater than. We see that in 20 out of 36 cases, die AA rolls higher numbers than die BB, meaning Panna wins in more than half the cases. Similarly, the same is true for BB versus CC: BB wins in more than half the cases. And most surprisingly, the same holds for CC versus AA. In everyday terms, AA is stronger than BB, BB is stronger than CC, and CC is stronger than AA!

Peter calls such a set of three dice with this property interesting, and now he wants to know how many interesting triples of dice exist in a set of NN unconventional dice.

Input specification

The first line contains the number of dice, NN. Then NN lines follow each of with 6 numbers: fi,1fi,2fi,6i=1Nf_{i,1}\le f_{i,2}\le \ldots \le f_{i,6}\ \ i=1\ldots N. The dice are pairwise different.

Output specification

A line with the number of interesting dice triplets.

Constraints

3N5003\le N \le 500
0fi,j200\le f_{i,j} \le 20

Sample input 1

  1. 3
  2. 2 2 4 4 9 9
  3. 1 1 6 6 8 8
  4. 3 3 5 5 7 7
download as text file

Sample output 1

  1. 1
download as text file

Sample input 2

  1. 4
  2. 4 4 4 4 0 0
  3. 3 3 3 3 3 3
  4. 6 6 2 2 2 2
  5. 5 5 5 1 1 1
download as text file

Sample output 2

  1. 1
download as text file

Sample input 3

  1. 7
  2. 2 2 14 14 17 17
  3. 7 7 10 10 16 16
  4. 5 5 13 13 15 15
  5. 3 3 9 9 21 21
  6. 1 1 12 12 20 20
  7. 6 6 8 8 19 19
  8. 4 4 11 11 18 18
download as text file

Sample output 3

  1. 14
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024