Count Equal NeighborsEasy

Count Equal Neighbors

EasyPractice library · +10 XPbasicsarraysloops

Given a list of integers, count how many pairs of adjacent elements are equal. For example, in the list [1, 2, 2, 3, 3, 3, 4], the pairs (2, 2), (3, 3), and (3, 3) are equal adjacent pairs. The total count is 3.

Input

The first line contains an integer N, the number of elements. The second line contains N space-separated integers.

Output

Print a single integer: the count of adjacent equal pairs.

Constraints

1 <= N <= 1000. Each integer will be between -1000 and 1000.

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
7
1 2 2 3 3 3 4
Output
3

The adjacent equal pairs are (2, 2), (3, 3), and (3, 3), so the count is 3.

Example 2

Input
5
10 10 10 10 10
Output
4

All adjacent pairs are equal (10, 10), (10, 10), (10, 10), (10, 10), giving a count of 4.

Hints