#P10295. [CCC 2024 S1] Hat Circle

[CCC 2024 S1] Hat Circle

Problem Description

At a recent party, NN people are sitting around a round table, where NN is even. The seats are numbered 11 to NN in clockwise order. Each person is wearing a hat with a number written on it. Specifically, the person in seat ii is wearing a hat with the number HiH_i on it.

Each person is looking at the person directly opposite them in the circle.

Please find the number of people who see a hat with the same number as their own.

Input Format

The first line contains a positive even integer NN, the number of people at the party.

The next NN lines each contain a non-negative integer HiH_i, representing the number written on the hat of person ii.

Output Format

Output one integer, the number of people who see a hat with the same number as their own.

4
0
1
0
1

4

4
1
0
0
1

0

Hint

[Sample 1 Explanation]

The arrangement of the four seats around the table is shown in the figure below. The number inside each circle is the number on that person’s hat, and the number next to the circle is that person’s index. Note that each person sees a number equal to the number on their own hat. The people in positions 11 and 33 both see the number 00, and the people in positions 22 and 44 both see the number 11.

[Sample 2 Explanation]

The arrangement of the four seats around the table is shown in the figure below. The number inside each circle is the number on that person’s hat, and the number next to the circle is that person’s index. Note that each person sees a number that is not equal to the number on their own hat. The people in positions 11 and 44 both see the number 00, and the people in positions 22 and 33 both see the number 11.

[Constraints]

This problem uses bundled testdata.

For all testdata, it is guaranteed that 1N1061\leq N\leq 10^6 and 0Hi2×1060\leq H_i\leq 2\times 10^6.

The table below shows the distribution of the 1515 points:

Score Description Range of NN Range of HiH_i
22 Very few people; only two possible hat numbers N4N \leq 4 Hi1H_i \leq 1
11 Only one possible hat number N100N \leq 100 Hi=1H_i = 1
22 People in odd positions have hat number 11, and people in even positions have hat number 00 Hi1H_i \leq 1
55 A medium number of people N2×103N \leq 2 \times 10^3 Hi4×103H_i \leq 4 \times 10^3
Many people and many possible hat numbers N106N \leq 10^6 Hi2×106H_i \leq 2 \times 10^6

Translated by ChatGPT 5