#P2071. Maximizing Preferred Seated Participants

    ID: 15353 Type: Default 1000ms 256MiB

Maximizing Preferred Seated Participants

Maximizing Preferred Seated Participants

There are N rows of seats in a vehicle with exactly 2 seats per row. A total of 2N participants are taking part in the contest. Each participant has a preferred row in which they want to sit. However, since each row can seat at most two people, if more than two participants prefer the same row, only two of them can be seated in that row. Given the preference for each participant, determine the maximum number of participants that can be assigned a seat in their desired row.

The problem can be mathematically formulated as follows:

For each row \(i\) (where \(1 \leq i \leq N\)), let \(c_i\) be the number of participants whose preferred row is \(i\). Then, the answer is

[ \text{answer} = \sum_{i=1}^{N}\min(c_i, 2). ]

inputFormat

The input consists of two lines:

  • The first line contains an integer N representing the number of rows.
  • The second line contains 2N space-separated integers, where each integer is the preferred row number of a participant. It is assumed that the preferred row numbers are between 1 and N (inclusive).

outputFormat

Output a single integer, the maximum number of participants who can be seated in their preferred rows.

sample

3
1 3 2 2 2 2
4