#C3997. Count Identical Employee Rankings

    ID: 47485 Type: Default 1000ms 256MiB

Count Identical Employee Rankings

Count Identical Employee Rankings

You are given the ranking preferences of N employees. Each employee ranks a certain number of unique items in order of preference. Two employees are said to have identical rankings if their ordered list of rankings is exactly the same.

Your task is to count how many distinct groups of employees exist such that each group contains more than one employee with identical ranking preferences.

Note: If no employee exists or if all employees have unique rankings, the answer should be 0.

The problem essentially requires you to compare lists (or strings) of numbers and count the number of ranking patterns that occur more than once.

All formulas used in this problem (if any) must be written in LaTeX format. For example, if you refer to the total number of groups, denote it as \(G\) such that \(G = \sum_{i} \mathbf{1}_{\{count_i > 1\}}\), where \(count_i\) is the frequency of the \(i\)-th unique ranking.

inputFormat

The input is given via standard input (stdin) with the following format:

  1. The first line contains a single integer \(N\) denoting the number of employees.
  2. The next \(N\) lines each contain a space-separated list of integers. Each line represents the ranking preferences of one employee. All integers in a line are unique. The number of integers in each line (denoted as \(K\)) is the same for every employee.

If \(N = 0\), then no further lines follow.

outputFormat

The output is a single integer printed to standard output (stdout), representing the number of groups that have more than one employee with identical ranking preferences.

## sample
5
1 2 3 4 5
2 3 4 5 1
1 2 3 4 5
5 4 3 2 1
2 3 4 5 1
2