Language: C++

#include<algorithm>
int N;
int solve(std::vector<int> &v);
int main(void){
    std::vector<int> v;
    int tmp,ans;
    std::cin>>N;
    while(std::cin>>tmp){
        v.push_back(tmp);
    }
    ans=solve(v);
    std::cout<<ans<<std::endl;
    return 0;
}
int solve(std::vector<int> &v){
    int head,tail,count,max=-1;
    std::sort(v.begin(), v.end());
    head=*(v.begin());
    tail=*(v.end()-1);
    for(int i=head;i!=tail+1;i++){
        count=0;
        for(auto x:v){
            if(x-1<=i && i<=x+1){
                count++;
            }
        }
        if(count>max){
            max=count;
        }
    }
    return max;
}


Compiler output:
a.cc:3:16: error: 'vector' is not a member of 'std'
    3 | int solve(std::vector<int> &v);
      |                ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include<algorithm>
  +++ |+#include <vector>
    2 | int N;
a.cc:3:23: error: expected primary-expression before 'int'
    3 | int solve(std::vector<int> &v);
      |                       ^~~
a.cc: In function 'int main()':
a.cc:5:10: error: 'vector' is not a member of 'std'
    5 |     std::vector<int> v;
      |          ^~~~~~
a.cc:5:10: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:5:17: error: expected primary-expression before 'int'
    5 |     std::vector<int> v;
      |                 ^~~
a.cc:7:10: error: 'cin' is not a member of 'std'
    7 |     std::cin>>N;
      |          ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include<algorithm>
  +++ |+#include <iostream>
    2 | int N;
a.cc:8:16: error: 'cin' is not a member of 'std'
    8 |     while(std::cin>>tmp){
      |                ^~~
a.cc:8:16: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:9:9: error: 'v' was not declared in this scope
    9 |         v.push_back(tmp);
      |         ^
a.cc:11:15: error: 'v' was not declared in this scope
   11 |     ans=solve(v);
      |               ^
a.cc:11:16: error: 'solve' cannot be used as a function
   11 |     ans=solve(v);
      |                ^
a.cc:12:10: error: 'cout' is not a member of 'std'
   12 |     std::cout<<ans<<std::endl;
      |          ^~~~
a.cc:12:10: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:12:26: error: 'endl' is not a member of 'std'
   12 |     std::cout<<ans<<std::endl;
      |                          ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include<algorithm>
  +++ |+#include <ostream>
    2 | int N;
a.cc: At global scope:
a.cc:15:5: error: redefinition of 'int solve'
   15 | int solve(std::vector<int> &v){
      |     ^~~~~
a.cc:3:5: note: 'int solve' previously defined here
    3 | int solve(std::vector<int> &v);
      |     ^~~~~
a.cc:15:16: error: 'vector' is not a member of 'std'
   15 | int solve(std::vector<int> &v){
      |                ^~~~~~
a.cc:15:16: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:15:23: error: expected primary-expression before 'int'
   15 | int solve(std::vector<int> &v){
      |                       ^~~