#include <iostream>
#include <unordered_map>
using namespace std;
// typedef pair<int,int> PII;
const int N = 2e5 + 10;
int a[N];
bool check(int s,int e){
unordered_map<int,int> h;
for(int i = s;i <= e;i++){
h[a[i]]++;
}
for(const auto& t : h){
if(t.second == 3) return true;
}
return false;
}
int main() {
int n;
cin>>n;
for(int i = 0;i < n;i++){
cin>>a[i];
}
int cnt = 0;
int i = 0;
while(i < n - 3){
if(check(i,i + 3)){
i = i + 4;
cnt++;
}else{
i++;
}
}
cout<<cnt<<endl;
}
// 64 位输出请用 printf("%lld")