why is my code giving run error?
the code—
#include<bits/stdc++.h>
#include
using namespace std;
int main()
{
int n;
cin>>n;
int components[5001];
for(int i=0;i<5001;i++){
components[i]=-1;
}
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int current=arr[0];
components[current]++;
for(int i=0;i<n;i++){
if(current!=arr[i]){
current=arr[i];
components[arr[i]]++;
}
}
if (n==1){
cout<<0;
}
else{
int ele=-1;
int index=-1;
for(int i=0;i<5001;i++){
if (components[i]>ele){
index=i;
ele=components[i];
}
}
ele=index;
current=-1;
int ans=0;
for(int i=0;i<n;i++){
if(arr[i]!=current){
if(arr[i]==ele){
current=ele;
}
else{
ans++;
current=arr[i];
}
}
}
cout<<ans;
}
return 0;
}