Language: C++

#include <iostream>                                                                                      #include <vector>                                                                                        
                                                                                                         
using namespace std;                                                                                     
                                                                                                         
int main() {                                                                                             
  int n;                                                                                                 
  cin >> n;                                                                                              
  vector<int> sum(n);                                                                                    
  for (auto &x: sum) {                                                                                   
    cin >> x;                                                                                            
  }                                                                                                      
  int count = 0;                                                                                         
  int same = 0;                                                                                          
  for (int i=0; i < n-2; i++) {                                                                          
    if (sum[i] != sum[i+1]) {                                                                            
      same += 1;                                                                                         
    }                                                                                                    
    if (!(sum[i] == sum[i+2])) {                                                                         
      count += 1;                                                                                        
    }                                                                                                    
  }                                                                                                      
  if (sum[n-1] != sum[n]){                                                                               
    same += 1;                                                                                           
  }                                                                                                      
  if (same != 0) {                                                                                       
    cout << 2;                                                                                           
  } else {                                                                                               
    cout << count;                                                                                       
  }                                                                                                      
}                                                                                                        
               

Compiler output:
a.cc:1:106: warning: extra tokens at end of #include directive
    1 | #include <iostream>                                                                                      #include <vector>
      |                                                                                                          ^
a.cc: In function 'int main()':
a.cc:8:3: error: 'vector' was not declared in this scope
    8 |   vector<int> sum(n);
      |   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>                                                                                      #include <vector>
  +++ |+#include <vector>
    2 | 
a.cc:8:10: error: expected primary-expression before 'int'
    8 |   vector<int> sum(n);
      |          ^~~
a.cc:9:17: error: 'sum' was not declared in this scope
    9 |   for (auto &x: sum) {
      |                 ^~~
a.cc:15:9: error: 'sum' was not declared in this scope
   15 |     if (sum[i] != sum[i+1]) {
      |         ^~~
a.cc:18:11: error: 'sum' was not declared in this scope
   18 |     if (!(sum[i] == sum[i+2])) {
      |           ^~~
a.cc:22:7: error: 'sum' was not declared in this scope
   22 |   if (sum[n-1] != sum[n]){
      |       ^~~