CCCGuide

Problem S1: Hat Circle

2024 · S1 · Original problem · DMOJ

Problem Description

At a recent social gathering, NN people sit around a circular table, where NN is even. The seats are numbered clockwise from 11 to NN. Each person is wearing a hat with a number on it. Specifically, the person at seat ii is wearing a hat with the number HiH_i on it.

Each person looks at the person who is directly across (diametrically opposite) them in the circle.

Determine the number of people who see someone with a hat with the same number as their own.

Input Specification

The first line of input will consist of one even positive integer NN, representing the number of people at the social gathering.

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

The following table shows how the available 1515 marks are distributed:

MarksDescriptionBounds on NNBounds on HiH_i
22Very small number of people; only two hat numbersN≤4N \le 4Hi≤1H_i \leq 1
11Only one hat numberN≤100N \le 100Hi=1H_i = 1
22People in even numbered seats have hat number 1; people in odd numbered seats have hat number 0N≤100N \le 100Hi≤1H_i \leq 1
55Medium number of peopleN≤2 000N \le 2\,000Hi≤4 000H_i \leq 4\,000
55Large number of people and hat numbersN≤1 000 000N \le 1\,000\,000Hi≤2 000 000H_i \le 2\,000\,000

Output Specification

Output a single integer representing the number of people who see their hat number on the person directly across from them.

Sample Input 1

4
0
1
0
1 

Output for Sample Input 1

4

Explanation of Output for Sample Input 1

The four seats around the table are shown below. Hat numbers are shown inside each seat and seat numbers are shown beside each seat.

Around a circle, seat 1 with hat number 0 is at the top, seat 2 with hat number 1 is on the right side, seat 3 with hat number 0 is at the bottom, and seat 4 with hat number 1 is on the left side.

Notice that every person sees their hat number. The people in seats 11 and 33 both see hat number 00, and the people in seats 22 and 44 both see hat number 11.

Sample Input 2

4
1
0
0
1 

Output for Sample Input 2

0

Explanation of Output for Sample Input 2

The four seats around the table are shown below. Hat numbers are shown inside each seat and seat numbers are shown beside each seat.

Around a circle, seat 1 with hat number 1 is at the top, seat 2 with hat number 0 is on the right side, seat 3 with hat number 0 is at the bottom, and seat 4 with hat number 1 is on the left side.

Notice that no person sees their hat number. The people in seats 11 and 44 both see hat number 00, and the people in seats 22 and 33 both see hat number 11.