#C2210. Maximum Bridges Construction

    ID: 45502 Type: Default 1000ms 256MiB

Maximum Bridges Construction

Maximum Bridges Construction

Given a list of towers represented by their heights, your task is to determine the maximum number of bridges that can be constructed. A bridge can only be built between two towers of the same height, and each tower can participate in at most one bridge.

Formally, you are given an integer \(N\) which is the number of towers and a list of \(N\) integers where each integer represents the height of a tower. For each distinct height \(h\) with frequency \(f\), you can form at most \(\lfloor \frac{f}{2} \rfloor\) bridges. The total number of bridges will be the sum of \(\lfloor \frac{f}{2} \rfloor\) for all distinct heights.

Your program should read the input from standard input and output the result to standard output.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(N\) (the number of towers).
  • The second line contains \(N\) space-separated integers representing the heights of the towers.

outputFormat

Output a single integer representing the maximum number of bridges that can be constructed.

## sample
6
1 3 2 3 2 1
3