#K88487. Sock Pair Counting

    ID: 37319 Type: Default 1000ms 256MiB

Sock Pair Counting

Sock Pair Counting

You are given a collection of socks, each having a color represented by an integer. Your task is to compute the number of pairs that can be formed for each of the given colors.

More formally, you are provided with:

  • An integer \(N\) which denotes the total number of socks.
  • An integer \(K\) which represents the number of distinct colors (colors are numbered from 1 to \(K\)).
  • A list of \(N\) integers where each integer is in the range [1, \(K\)] representing the color of a sock.

A pair consists of two socks of the same color. For each color from 1 to \(K\), you need to output the number of pairs that can be formed from the socks of that color. The number of pairs for a color is \(\lfloor \frac{\text{count}}{2} \rfloor\).

Example:

Input:
7 3
1 2 1 2 1 3 1

Output:
2 1 0

In the above example, there are 7 socks and 3 distinct colors. The counts for the colors {1, 2, 3} are 4, 2, and 1 respectively, yielding pairs of 2, 1, and 0.

inputFormat

The first line of input contains two integers \(N\) and \(K\), separated by a space, representing the total number of socks and the number of distinct colors respectively.

The second line contains \(N\) space-separated integers, where each integer represents the color of a sock.

outputFormat

Output \(K\) space-separated integers in a single line, where the \(i\)-th integer is the number of pairs that can be formed from socks of color \(i\) (considering colors are numbered from 1 to \(K\)).

## sample
7 3
1 2 1 2 1 3 1
2 1 0