Count Elements with Equal Neighbors
Given an array of N integers, count how many elements are equal to at least one of their immediate neighbors. An element at index i (where 0 < i < N-1) has two neighbors: A[i-1] and A[i+1]. Elements at index 0 and N-1 have only one neighbor.
Input
The first line contains an integer N. The second line contains N space-separated integers representing the array elements.
Output
Print a single integer, the count of elements satisfying the condition.
Constraints
1 <= N <= 200000 -10^9 <= A[i] <= 10^9
Example 1
5 1 2 2 3 3
4
Elements at index 1 (value 2) and index 2 (value 2) are equal to their neighbor(s). Elements at index 3 (value 3) and index 4 (value 3) are equal to their neighbor(s). Total count is 4.
Example 2
3 5 5 5
3
Element at index 0 (value 5) equals A[1]. Element at index 1 (value 5) equals A[0] and A[2]. Element at index 2 (value 5) equals A[1]. Total count is 3.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 1 2 2 3 3
3 5 5 5