Language: C++

#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<list>
using namespace std;
const int maxn=2e5+50;
char s[maxn];
bool judge;
int length,cnte,cnto,cnt,temp,T,cnton,index;
int main(){
    //freopen("out.txt", "w", stdout);
    while(scanf("%s",s)!=EOF){
        vector<int> v[30];
        list<int> ss;
        list<int>::reverse_iterator rit;
        judge=true;
        length=strlen(s);
        cnt=cnte=cnto=cnton=0;
        for(int i=0;i<length;i++){
            temp=s[i]-'a';
            ss.push_back(temp);
            v[temp].push_back(i);
        }
        for(int i=0;i<26;i++){
            if(!v[i].size())
                continue;
            if(v[i].size()==length){
                judge=false;
                break;
            }
            if(v[i].size()%2)
                cnto++;
            else
                cnte++;
        }
        //cout<<cnto<<" "<<cnte<<endl;
        if(length==1||!judge)
            printf("0\n");
        else if((length%2&&cnte&&cnto<=1)||(!(length%2)&&!cnto)){
            while(ss.size()){
                    //cout<<ss.size()<<endl;
                    judge=true;
                    index=ss.size()-1;
                    for(rit=ss.rbegin();rit!=ss.rend();rit++,index--){
                        if(*rit==*ss.begin()){
                        cnt+=ss.size()-1-index;
                        //cout<<cnt<<endl;
                        list<int>::iterator it=ss.erase((++rit).base());
                        rit=list<int>::reverse_iterator(it);
                        //cout<<*it<<endl;
                        //ss.erase(it);
                        judge=false;
                        break;
                        }
                    }
                    //cout<<*ss.begin()<<endl;
                    ss.erase(ss.begin());
                    if(judge)
                        cnt+=ss.size()/2;
        }
            printf("%d\n",cnt);
        }
        else
            printf("-1\n");
    }
    return 0;
}


Compiler output:
a.cc:11:39: error: 'int index' redeclared as different kind of entity
   11 | int length,cnte,cnto,cnt,temp,T,cnton,index;
      |                                       ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:2:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:45:37: error: overloaded function with no contextual type information
   45 |                     index=ss.size()-1;
      |                                     ^
a.cc:46:67: error: no post-decrement operator for type
   46 |                     for(rit=ss.rbegin();rit!=ss.rend();rit++,index--){
      |                                                                   ^~
a.cc:48:41: error: invalid operands of types 'std::__cxx11::list<int>::size_type' {aka 'long unsigned int'} and '<unresolved overloaded function type>' to binary 'operator-'
   48 |                         cnt+=ss.size()-1-index;
      |                              ~~~~~~~~~~~^~~~~~