criyle/codenet-compile-errors huggingface dataset:
Language: C++

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

string s;

signed main() {
    cin >> s;
    unsigned ans = s.size();
    for (unsigned i = 0; i < s.size() - 1; i++) {
        if (s[i] != s[i + 1]) {
            unsigned cur = max(i + 1, s.size() - i - 1);
            ans = min(ans, cur);
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:31: error: no matching function for call to 'max(unsigned int, std::__cxx11::basic_string<char>::size_type)'
   17 |             unsigned cur = max(i + 1, s.size() - i - 1);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:17:31: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   17 |             unsigned cur = max(i + 1, s.size() - i - 1);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:17:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   17 |             unsigned cur = max(i + 1, s.size() - i - 1);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    string s;
    cin >> s;
    int m = 0;
    for(int i=0; i<s.size(); ++i)
        if(s[i]=='1') m++;
    if(m==s.size()) cout << s.size() << endl;
    //else cout << max((int)s.size()-m, m) << endl;
    int t0 = 0;
    int t1 = 0;

    string tmp = "";
    tmp.push_back(s[0]);
    for(int i=1; i<s.size(); ++i) {
        if(tmp[tmp.size()-1]==s[i]) tmp.push_back(s[i]);
        else {
            if(tmp[tmp.size()-1]=='1') t1 = max(t1, (int)tmp.size());
            else t0 = max(t0, (int)tmp.size());
            tmp = "";
            tmp.push_back(s[i]);
        }
    }
    cout << max(t1, t2) << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:28:21: error: 't2' was not declared in this scope; did you mean 't1'?
   28 |     cout << max(t1, t2) << endl;
      |                     ^~
      |                     t1
Language: C++

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

string s;

signed main() {
    cin >> s;
    int ans = s.size();
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] != s[i + 1]) {
            int cur = max(i + 1, s.size() - i - 1);
            ans = min(ans, cur);
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:26: error: no matching function for call to 'max(long long int, long long unsigned int)'
   17 |             int cur = max(i + 1, s.size() - i - 1);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:17:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   17 |             int cur = max(i + 1, s.size() - i - 1);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:17:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |             int cur = max(i + 1, s.size() - i - 1);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<limits>
#include<queue>

#define ll long long

using namespace std;

int main(void) {
	string S;
	cin >> S;
	int ans = LONG_MAX;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == '1') {
			ans = min(ans, max(i + 1, (int)S.length() - i));
		}
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:19: error: 'LONG_MAX' was not declared in this scope
   16 |         int ans = LONG_MAX;
      |                   ^~~~~~~~
a.cc:8:1: note: 'LONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    7 | #include<queue>
  +++ |+#include <climits>
    8 |
Language: C++

#include <iostream>
#include <string>
using namespace std;

int main() {

  string s;
  cin >> s;

  long long int ans = s.size();

  for ( long long int i = 0; i < s.size() - 1; i++ ) {

    if ( s[i] != s[i+1] ) {
      ans = min( max( i + 1, 0LL + s.size() - i - 1 ), ans );
    }

  }

  cout << ans << endl;

  return 0;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:21: error: no matching function for call to 'max(long long int, long long unsigned int)'
   15 |       ans = min( max( i + 1, 0LL + s.size() - i - 1 ), ans );
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:15:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   15 |       ans = min( max( i + 1, 0LL + s.size() - i - 1 ), ans );
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
Language: C++

#include <iostream>
#include <string>
using namespace std;

int main() {

  string s;
  cin >> s;

  long long int ans = s.size();

  for ( long long int i = 0; i < s.size() - 1; i++ ) {

    if ( s[i] != s[i+1] ) {
      ans = min( max( i + 1, s.size() - i - 1 ), ans );
    }

  }

  cout << ans << endl;

  return 0;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:21: error: no matching function for call to 'max(long long int, long long unsigned int)'
   15 |       ans = min( max( i + 1, s.size() - i - 1 ), ans );
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:15:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   15 |       ans = min( max( i + 1, s.size() - i - 1 ), ans );
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
Language: C++

//
//  main.cpp
//  D
//
//  Created by Charles on 2017/12/23.
//  Copyright © 2017年 Charles. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=1e5+5;
char s[maxn];
int main(int argc, const char * argv[]) {
    while(~scanf("%s",s)){
        int len=(int)strlen(s);
        int ans=0;
        for(int i=0;i<len;++i) if(s[i]=='0') ans++;
        cout<<ans<<endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:16:22: error: 'strlen' was not declared in this scope
   16 |         int len=(int)strlen(s);
      |                      ^~~~~~
a.cc:11:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   10 | #include <cstdio>
  +++ |+#include <cstring>
   11 | using namespace std;
Language: C++

#include <bits/stdc++.h>
#define INF 1e+9
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    char c;
    int t = 0, f = 0;
    while(getchar(c) != EOF){
        if(c == '1') t++;
        if(c == '0') f++;
    }
    cout << max(t, f) << '\n';
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:18: error: too many arguments to function 'int getchar()'
   11 |     while(getchar(c) != EOF){
      |           ~~~~~~~^~~
In file included from /usr/include/c++/14/cstdio:42,
                 from /usr/include/c++/14/ext/string_conversions.h:45,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/stdio.h:582:12: note: declared here
  582 | extern int getchar (void);
      |            ^~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    string s;
    cin >> s;
    int m = 0;
    for(int i=0; i<s.size(); ++i)
        if(s[i]=='1') m++;
    if(m==s.size()) cout << s.size() << endl;
    else cout << max(s.size()-m, m) << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:13:21: error: no matching function for call to 'max(long long unsigned int, long long int&)'
   13 |     else cout << max(s.size()-m, m) << endl;
      |                  ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:13:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
   13 |     else cout << max(s.size()-m, m) << endl;
      |                  ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:13:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   13 |     else cout << max(s.size()-m, m) << endl;
      |                  ~~~^~~~~~~~~~~~~~~
Language: C++

#include 
using namespace std;

int main()
{
	string S;
	cin >> S;
	vector st;
	char t = S.front();
	int tmp = 0;
	for (auto c : S) {
		if (c != t) {
			st.push_back(tmp);
			tmp = 1;
			t = c;
		}
		else {
			tmp++;
		}
	}
	st.push_back(tmp);
	int res = S.back() == '0' && S.front() == '0' ? (int)S.size() : max(st.back(), st.front());
	for (int i = 1; i < (int)st.size(); i++) {
		res = min(res, st[i - 1] + st[i]);
	}
	cout << res << endl;
	return 0;
}


Compiler output:
a.cc:1:10: error: #include expects "FILENAME" or <FILENAME>
    1 | #include
      |          ^
a.cc: In function 'int main()':
a.cc:6:9: error: 'string' was not declared in this scope
    6 |         string S;
      |         ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | #include
a.cc:7:9: error: 'cin' was not declared in this scope
    7 |         cin >> S;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #include
a.cc:7:16: error: 'S' was not declared in this scope
    7 |         cin >> S;
      |                ^
a.cc:8:9: error: 'vector' was not declared in this scope
    8 |         vector st;
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #include
a.cc:13:25: error: 'st' was not declared in this scope; did you mean 't'?
   13 |                         st.push_back(tmp);
      |                         ^~
      |                         t
a.cc:21:9: error: 'st' was not declared in this scope; did you mean 't'?
   21 |         st.push_back(tmp);
      |         ^~
      |         t
a.cc:22:73: error: 'max' was not declared in this scope
   22 |         int res = S.back() == '0' && S.front() == '0' ? (int)S.size() : max(st.back(), st.front());
      |                                                                         ^~~
a.cc:24:23: error: 'min' was not declared in this scope; did you mean 'main'?
   24 |                 res = min(res, st[i - 1] + st[i]);
      |                       ^~~
      |                       main
a.cc:26:9: error: 'cout' was not declared in this scope
   26 |         cout << res << endl;
      |         ^~~~
a.cc:26:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:26:24: error: 'endl' was not declared in this scope
   26 |         cout << res << endl;
      |                        ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | #include
Language: C++

#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int licz[26];
int ans=0;
int32_t main()
{
  BOOST;
  string s;
  cin>>s;
  int n=sz(s);
  for (auto it:s)licz[it-'a']++;
  int cnt=0;
  for (int i=0;i<26;i++)cnt+=licz[i]%2;
  if (cnt>1){cout<<"-1";return 0;};
  int x=-10000000;
  if (cnt)
  {
  	int wsk=0;
  	int srodek=n/2;
  	for (int i=0;i<26;i++) if (licz[i]%2==1)wsk=i;
  	for (int i=0;i<n;i++)
  	{
  		if (s[i]-'a'==wsk && abs(x-srodek)>abs(i-srodek))
  		{
  			x=i;
  		}
  	}
  	
  	int pr=1;
  	if (x<srodek) for (int i=x;i<=srodek-1;i++)swap(s[i],s[i+1]),ans++;
  	else for (int i=x;i>=srodek+1;i--)swap(s[i],s[i-1]),ans++;
  }
  
  for (int i=0;i<n;i++)
  {
  	if (s[i]==s[n-1-i])continue;
  	if (i==srodek)continue;
  	else
  	{
  		int id=-1;
  		for (int j=n-i-1;j>=0;j--)if (s[j]==s[i]) {id=j;break;}
  		for (int j=id;j<=n-i-2;j++)swap(s[j],s[j+1]),ans++;
  	}
  }
  cout<<ans;
  return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:50:16: error: 'srodek' was not declared in this scope
   50 |         if (i==srodek)continue;
      |                ^~~~~~
Language: C++

#include <bits/stdc++.h>
#include "../lib/data_structure/bit.hpp"

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  map<char, int> mp;
  int sz = SZ(s);
  REP(i, sz) {
    mp[s[i]]++;
  }

  int cnt = 0;
  vector<P> p(sz);
  REP(i, sz) {
    p[i].first = -1;
    p[i].second = i;
  }
  for(auto &e: mp) {
    if(e.second % 2) {
      cnt++;
    }
  }

  if(cnt > 1) {
    cout << -1 << endl;
    return 0;
  }

  map<char, map<int, bool>> mp2;
  REP(i, sz) {
    mp2[s[i]][i] = false;
  }

  map<char, map<int, bool>::reverse_iterator> itr;
  for(auto &e: mp2) {
    itr[e.first] = e.second.rbegin();
  }

  int num = 0;
  REP(i, sz) {
    if(mp2[s[i]][i]) continue;
    mp2[s[i]][i] = true;
    if(itr[s[i]]->first == i) {
      p[i].first = sz/2;
      continue;
    }
    p[i].first = num;
    p[itr[s[i]]->first].first = sz - 1 - num;
    itr[s[i]]->second = true;
    itr[s[i]]++;
    num++;
  }

  sort(ALL(p));

  BIT<ll> bit(sz);
  ll ans = 0;
  REP(i, sz) {
    ans += i - bit.sum(p[i].second);
    bit.add(p[i].second, 1);
  }
  cout << ans << endl;

}
























Compiler output:
a.cc:2:10: fatal error: ../lib/data_structure/bit.hpp: No such file or directory
    2 | #include "../lib/data_structure/bit.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#include "../lib/data_structure/bit.hpp"

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  map<char, int> mp;
  int sz = SZ(s);
  map<char, int> idx;
  REP(i, sz) {
    mp[s[i]]++;
    idx[s[i]] = i;
  }

  int cnt = 0;
  vector<P> p(sz);
  REP(i, sz) {
    p[i].first = -1;
    p[i].second = i;
  }
  for(auto &e: mp) {
    if(e.second % 2) {
      cnt++;
      p[idx[e.first]].first = sz/2;
    }
  }

  if(cnt > 1) {
    cout << -1 << endl;
    return 0;
  }

  map<char, map<int, bool>> mp2;
  REP(i, sz) {
    mp2[s[i]][i] = false;
  }

  map<char, map<int, bool>::reverse_iterator> itr;
  for(auto &e: mp2) {
    itr[e.first] = e.second.rbegin();
  }

  int num = 0;
  REP(i, sz) {
    if(num == sz/2) break;
    if(mp2[s[i]][i]) continue;
    p[i].first = num;
    p[itr[s[i]]->first].first = sz - 1 - num;
    itr[s[i]]->second = true;
    itr[s[i]]++;
    num++;
  }

  sort(ALL(p));

  BIT<ll> bit(sz);
  ll ans = 0;
  REP(i, sz) {
    ans += i - bit.sum(p[i].second);
    bit.add(p[i].second, 1);
  }
  cout << ans << endl;

}
























Compiler output:
a.cc:2:10: fatal error: ../lib/data_structure/bit.hpp: No such file or directory
    2 | #include "../lib/data_structure/bit.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

struct BIT{
    int M;
    vector<ll> bit;
    BIT(int n): M(n), bit(M+1,0) {}

    void add(int a, ll w=1) { // aを +w  aは 1-indexed
        for(int x=a; x<=M; x+= x& -x){
            bit[x] += w;
        }
    }

    ll sum(int a) { // [1,a] 1-indexed
        ll ret=0;
        for(int x=a; x>0; x-= x& -x){
            ret+= bit[x];
        }
        return ret;
    } // 左上のものをすべて足す
};

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;

    ll N=S.size();
    vector<deque<ll>> A(26);
    rep(i,N){
        A[S[i]-'a'].emplace_back(i);
    }
    ll ct=0;
    ll mid=-1;
    rep(i,26){
        if(A[i].size()%2==1) {++ct; mid=i;} 
    }
    if(ct>1) dame;

    BIT bi(N+2);
    ll hai=0;
    ll cost=0;
    rep(i,N){
        ll c=S[i]-'a';
        ll dore;
        ll togo;
        if(A[c].size()==0) continue;
        if(A[c].size()==1) {
            cost+=abs(N/2-hai);
            A[c].pop_back();
            continue;
        }
        
        togo=N-1-hai;
        dore=A[c].back();
        A[c].pop_front();
        A[c].pop_back();
        
        cost+=togo-(dore-bi.sum(dore+1));
        bi.add(dore+1,1);
        else ++hai;
    }
    cout<< cost <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Compiler output:
a.cc: In function 'void Main()':
a.cc:80:9: error: 'else' without a previous 'if'
   80 |         else ++hai;
      |         ^~~~
Language: C++

#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

struct BIT{
    int M;
    vector<ll> bit;
    BIT(int n): M(n), bit(M+1,0) {}

    void add(int a, ll w=1) { // aを +w  aは 1-indexed
        for(int x=a; x<=M; x+= x& -x){
            bit[x] += w;
        }
    }

    ll sum(int a) { // [1,a] 1-indexed
        ll ret=0;
        for(int x=a; x>0; x-= x& -x){
            ret+= bit[x];
        }
        return ret;
    } // 左上のものをすべて足す
};

//--MAIN-----------------------------------
void Main() {
    ll S; cin>>S;

    ll N=S.size();
    vector<deque<ll>> A(26);
    rep(i,N){
        A[S[i]-'a'].emplace_back(i);
    }
    ll ct=0;
    ll mid=-1;
    rep(i,26){
        if(A[i].size()%2==1) {++ct; mid=i;} 
    }
    if(ct>1) dame;

    BIT bi(N+1);
    ll hai=0;
    ll cost=0;
    rep(i,N){
        ll c=S[i]-'a';
        ll dore;
        ll togo;
        if(c==mid) {togo=N/2; dore=i;}
        else{
            if(A[c].empty()) continue;
            togo=N-1-hai;
            dore=A[c].back();
            A[c].pop_front();
            A[c].pop_back();
        }
        cost+=togo-(dore-bi.sum(dore));
        bi.add(dore,1);
        if(c==mid) bi.add(togo,-1)
        ++hai;
    }
    cout<< cost <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Compiler output:
a.cc: In function 'void Main()':
a.cc:47:12: error: request for member 'size' in 'S', which is of non-class type 'll' {aka 'long long int'}
   47 |     ll N=S.size();
      |            ^~~~
a.cc:50:12: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   50 |         A[S[i]-'a'].emplace_back(i);
      |            ^
a.cc:63:15: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript
   63 |         ll c=S[i]-'a';
      |               ^
a.cc:76:26: error: no post-increment operator for type
   76 |         if(c==mid) bi.add(togo,-1)
      |                    ~~~~~~^~~~~~~~~
Language: C++

#include "stdafx.h"

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

template<typename T>
struct BIT {
	int n;
	vector<T>dat;
	BIT(int n = 0) {
		initialize(n);
	}
	void initialize(int temp) {
		n = temp;
		dat.resize(n);
		rep(i, 0, n)dat[i] = 0;
	}
	T sum(int i) {
		T s = 0;
		while (i >= 0) {
			s += dat[i];
			i = (i & (i + 1)) - 1;
		}
		return s;
	}
	T sum_between(int i, int j) {
		if (i > j)return 0;
		return sum(j) - sum(i - 1);
	}
	void plus(int i, T x) {
		while (i < n) {
			dat[i] += x;
			i |= i + 1;
		}
	}
	int lower_bound(T x) {
		if (sum(n - 1) < x)return -1;
		else if (sum(0) >= x)return 0;
		int ng = 0, ok = n - 1;
		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (sum(mid) >= x)ok = mid;
			else ng = mid;
		}
		return ok;
	}
};

ll bub(vector<ll>li){
	ll N = li.size();
	map<ll,ll>mp;
	for (int i = 0; i < N; i++)mp[li[i]] = i;
	vector<ll>to(N);
	for (int i = 0; i < N; i++)to[i] = mp[i];

	BIT<ll>bit(101010);
	ll ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		ans += bit.sum_between(0,to[i]-1);
		bit.plus(to[i], 1);
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string S;
	cin >> S;
	set<ll>st[26];
	ll N = S.size();
	for (int i = 0; i < N; i++)st[S[i] - 'a'].insert(i);
	ll cntodd = 0;
	for (int i = 0; i < 26; i++)cntodd += st[i].size()%2;

	if (cntodd >= 2) {
		puts(-1);
		return 0;
	}

	vector<ll>li(N, -1);
	ll cur = 0;
	for (int i = 0; i < N; i++) {
		int num = S[i] - 'a';
		if (li[i] == -1) {
			if (st[num].size() >= 2) {
				int fr = *st[num].begin();
				auto itr = st[num].end();
				itr--;
				int ba = *itr;
				li[fr] = cur;
				li[ba] = N - 1 - cur;
				st[num].erase(fr);
				st[num].erase(itr);
				cur++;
			}
			else {
				li[i] = N/2;
				st[num].erase(i);
			}
		}
	}

	puts(bub(li));

	return 0;
}

Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
#define MAXN 400005
#define LL long long
using namespace std;

int N;
string s;

vector<int> adj[26];
int pos[MAXN];

//
int fw[MAXN];

int lbt(int x){
	return x & (-x);
} 

int getsum(int x){
	int ans = 0;
	for(;x;x -= lbt(x)){
		ans += fw[x];
	}
	return ans;
}

void change(int x, int dv){
	for(;x<=2*N;x += lbt(x)){
		fw[x] += dv;
	}
}

//

int main(){
	
	cin>>s;
	N = s.length();
	s = "%" + s;
	
	for(int i=1;i<=N;i++){
		adj[s[i]-'a'].push_back(i);
	}
	
	int n1 = 0;
	for(int i=0;i<26;i++){
		if(adj[i].size()%2) ++n1;
		if(adj[i].size()==0) continue;
		
		int l = 0, r = adj[i].size()-1;
		while(l <= r){
			pos[adj[i][l]] = adj[i][r];
			l++;
			r--;
		}
	}

	if(n1 > 1){
		cout<<"-1"<<endl;
		return 0;
	}
	
	for(int i=1;i<=N;i++){
		//cout<<i<<" "<<pos[i]<<endl;
		change(i, +1);
	}
	
	LL ans = 0;
	int p1 = 0;s
	for(int i=1;i<=N;i++){
		if(pos[i]==0) continue;
		if(pos[i]==i){
			change(N+1, +1);
			continue;
		} 
		++p1;
		ans += getsum(N+1) - getsum(pos[i]);
		//cout<<i<<" "<<getsum(N)<<" "<<getsum(pos[i])<<" "<<ans<<endl;
		change(pos[i], -1);
	}
	cout<<ans<<endl;
	return 0;
}
/*
babaabbbaaa
*/

Compiler output:
a.cc: In function 'int main()':
a.cc:69:21: error: expected ';' before 'for'
   69 |         int p1 = 0;s
      |                     ^
      |                     ;
   70 |         for(int i=1;i<=N;i++){
      |         ~~~          
a.cc:70:21: error: 'i' was not declared in this scope
   70 |         for(int i=1;i<=N;i++){
      |                     ^
Language: C++

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
#include <conio.h>
using namespace std;

const int MAXN = 2E5+2;

struct FenwickTree{
    vector<int> F;
    void init(int n){
      F.assign(n+1, 0);
        
    }
    void update(int p, int val){
        for(int i=p; i< F.size(); i+= i&(-i)) F[i]+= val;
    }
    int get(int p){
        if(p==0) return 0;
        return F[p]+ get(p-(p&(-p)));
    }
};


int n;
string S;
vector<int> pos[26];
vector<pair<int,int> >P;
vector<int> id(MAXN, 0);
FenwickTree fen;
long long ret = 0;

bool check(){
    int cnt = 0;
    for(int i=0; i< 26; ++i) cnt+= (int)(pos[i].size()%2);
    return (cnt <= 1);
}

void pairing(){
		
    for(int i=0; i< 26; ++i){
			//	cerr << i << " " << pos[i].size() << "\n";
        int half = (int)(pos[i].size()+1)/2;
        for(int j=0; j< half; ++j){
					int o =(int)pos[i].size()-j-1;
					if(o==j) ret += 2LL*abs(pos[i][j] - (n+1)/2);
        	else P.push_back({pos[i][j], pos[i][o]});
				}
            
    }
		sort(P.begin(), P.end());
    /*int cur = 1;
    for(int i=0; i< P.size(); ++i){
			id[cur] = P[i].first;
			id[n+1-cur] = P[i].second;
			++cur;
		}*/
}

signed main()
{
	//	freopen("input.txt", "r", stdin);
	//	freopen("output1.txt", "w", stdout);
    cin >>  S;
    n = S.length();
    for(int i=0; i< n; ++i){
        pos[S[i]-'a'].push_back(i+1);
    }
    if(!check()){
        cout << -1;
        return 0;
    }

    pairing();
    fen.init(n);
    vector<int> X(n+1, -1);
    for(int i=0; i< P.size(); ++i){
    	X[P[i].first] = fen.get(P[i].first);
    	X[P[i].second] = fen.get(P[i].second);
			ret += 1LL*(X[P[i].first] + X[P[i].second]);
			fen.update(P[i].second, 1);
		}
	//cout << i << " " << X[i] << "\n";
		//cout << ret;
    //according to the first element
    /*fen.init(n);
    for(int i=n; i>= 1; --i){
			ret += 1LL*fen.get(id[i]);
			fen.update(id[i], 1);
		}*/
		cout << ret;
}

Compiler output:
a.cc:10:10: fatal error: conio.h: No such file or directory
   10 | #include <conio.h>
      |          ^~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

vector < int > V[33];
int T[33],W[33],H[N],X[N],XX[N],F[N],n,i,j,tek,x,r,rr;
char A[N];
long long ans;

void f(){
//    cout << r << " " << rr << " ss\n";
//    for(i=1;i<=r;i++) cout << X[i] << " "; puts("");
//    for(i=1;i<=r;i++) cout << XX[i] << " "; puts("");
    for(i=r ;i ;i--) V[ X[i] ].pb(i); 
    for(i=1;i<=r;i++){
        x = XX[i];
        if(V[x].size == 0) while(1);
        T[ V[x].back() ] = i;
        V[x].pop_back();
    }
    for(i=r; i ;i--){
        for(x=T[i] ;x; x -= x&-x) ans += F[x];
        for(x=T[i] ;x <= r; x += x&-x) F[x]++;
    }
}

int main(){
    cin >> A+1;
    n = strlen(A+1);
    if(n&1) assert(0);
    for(i=1;i<=n;i++) { A[i] -= 'a'; T[ A[i] ]++; }
    tek = -1;
    for(i=0;i<26;i++){
        if(T[i] & 1){
            if(tek != -1) { cout << -1; return 0; }
            tek = i;
        }
        T[i] >>= 1;
    }
    
    if(tek == -1){
        for(i=1;i<=n/2;i++){
            x = A[i]; W[x]++; 
            if(W[x] > T[x]){ X[++r] = x; H[i] = 1; }
        }
        for(j=0,i=n/2; i ;i--){
            W[ A[i] ]--; 
            if(H[i]) ans += n/2-i - j++;
        }
        
        for(i=n; i>n/2;i--){
            x = A[i]; W[x]++;
            if(W[x] > T[x]) { XX[++rr] = A[i]; H[i] = 1; }
        }
        for(j=0,i=n/2+1; i<=n ;i++){
            if(H[i]) ans += i-n/2-1 - j++;
            else X[++r] = A[i];
        }
        ans += 1LL*j*j;
        for(i=n/2; i ;i--){
            if(!H[i]) XX[++rr] = A[i];
        }
    }
    
    f();
    cout << ans;
    return 0;
}

Compiler output:
a.cc: In function 'void f()':
a.cc:24:17: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   24 |         if(V[x].size == 0) while(1);
      |            ~~~~~^~~~
      |                     ()
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


struct SegmentTree {
private:
    ll n;
    vector<ll> node;
 
public:
    SegmentTree(vector<ll> v) {
        int sz = v.size();
        //cout << sz << endl;
        n = 1; while(n < sz) n *= 2;
        //cout << n << endl;
        node.resize(2*n-1, 0);
        for(ll i=0; i<sz; i++) node[i+n-1] = v[i];
        for(ll i=n-2; i>=0; i--){
            //cout << i << endl;
            node[i] = node[2*i+1] + node[2*i+2];
        }
        //cout << "b" << endl;
    }
 
    void update(ll x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }
 
    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    //cout.precision(10);
    string s;
    map<char, vector<int> > vec;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        vec[s[i]].push_back(i);
    }
    char odd = '#';
    for(char buf = 'a'; buf <= 'z'; buf++){
        if(vec[buf].size() % 2 != 0){
            if(s.size() % 2 == 0){
                cout << -1 << endl;
                return 0;
            }
            if(odd != '#'){
                cout << -1 << endl;
                return 0;
            }
            odd = buf;
        }
    }
    map<char, int> now;
    int complete[200500];
    int posi = 0;
    for(int i = 0; i < s.size(); i++){
        char buf = s[i];
        if(vec[buf].size() == (now[buf] * 2 + 1)){
            now[buf]++;
            complete[i] = (s.size() / 2);
            continue;
        }
        if(vec[buf].size() > (now[buf] * 2)){
            now[buf]++;
            complete[i] = posi;
            posi++;
            continue;
        }
        int mirror = vec[buf].size() - 1 - now[buf];
        mirror = vec[buf][mirror];
        now[buf]++;
        complete[i] = s.size() - 1 - complete[mirror];
    }
    vector<ll> in(s.size();
    SegmentTree seg(in);
    ll ans = 0;
    for(ll i = 0; i < s.size(); i++){
        //cout << seg.getsum(0, complete[i]) << endl;
        ans += (i - seg.getsum(0, complete[i]));
        seg.update(i, 1);
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:93:27: error: expected ')' before ';' token
   93 |     vector<ll> in(s.size();
      |                  ~        ^
      |                           )
Language: C++

#include <iostream>
#include <string>
#include <queue>
using namespace std;

string s;
deque<int> c['z' - 'a' + 1];
int seg[4 * 100000-1], ans = 0, n;

int query(int a) {//絶対ここ‼
	int res = seg[0], l = 0, r = n, k = 0;

	while (r-l > 1) {
		int mid = (l + r) / 2;
		if (a < mid) {
			k = k * 2 + 1;
			r = mid;
		}
		else {
			k = k * 2 + 2;
			l = mid;
		}
		res += seg[k];
	}

	return res;
}

void update(int a, int b, int k, int l, int r, int num) {//
	if (r <= a || b <= l)return;

	if (a <= l && r <= b)seg[k] += num;
	else {
		update(a, b, k * 2 + 1, l, (l + r) / 2, num);
		update(a, b, k * 2 + 2, (l + r) / 2, r, num);
	}
}

int main() {
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		c[s[i] - 'a'].push_back(i);
	}

	int i = 0;
	n = s.length();
	while (true) {
		int num = -1, sum = INT32_MAX;

		for (int j = 0; j < 'z' - 'a' + 1; j++) {
			if (c[j].size() <= 1)continue;

			int a = c[j].front() + query(c[j].front()) - i;
			int b = (n - i - 1) - (c[j].back() + query(c[j].back()));

			if (num == -1 || sum > a + b) {
				num = j;
				sum = a + b;
			}
		}
		if (num == -1)break;

		//ansとseg,vecを更新
		if (num < 0 || num >= 'z' - 'a') {
			cout << "a" << endl;
			return;
		}
		ans += sum;
		update(0, c[num].front(), 0, 0, n, 1);
		update(c[num].back() + 1, n, 0, 0, n, -1);
		c[num].pop_front();
		c[num].pop_back();
		i++;
	}

	cout << ((s.length() - 2 * i <= 1) ? ans : -1) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:37: error: 'INT32_MAX' was not declared in this scope
   48 |                 int num = -1, sum = INT32_MAX;
      |                                     ^~~~~~~~~
a.cc:4:1: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    3 | #include <queue>
  +++ |+#include <cstdint>
    4 | using namespace std;
a.cc:66:25: error: return-statement with no value, in function returning 'int' [-fpermissive]
   66 |                         return;
      |                         ^~~~~~
Language: C++

#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#define debug cout<<"debug"<<endl;
using namespace std;
const int maxn=1e6+50;
char s[maxn];
int c[maxn],cnt[maxn],ok;
bool vis[maxn];

int lowbit(int x){
	return x&(-x);
}

void add(int x,int d){
	for(int i=x;i<=strlen(s+1);i+=lowbit(i)){
		c[i]+=d;
	}
}

int sum(int x){
	int ret=0;
	for(int i=x;i>0;i-=lowbit(i)){
		ret+=c[i];
	}
	return ret;
}

int main(){
	scanf("%s",s+1);
		memset(c,0,sizeof(c));
		memset(cnt,0,sizeof(cnt));
		memset(vis,0,sizeof(vis));
		ok=0; 
		vector<int> loc[30];
		for(int i=1;i<=strlen(s+1);i++){
			cnt[s[i]-'a']++;
			loc[s[i]-'a'].push_back(i);
		}
		for(int i=0;i<26;i++){
			if(cnt[i]%2) ok++;
		}
		if(ok>1){
			printf("-1\n");
			return 0;
		}
		for(int i=1;i<=strlen(s+1)+1;i++){
			add(i,1);
		}
		ll ans=0;
		for(int i=1;i<=strlen(s+1);i++){
			if(vis[i]) continue;
			int loc_right=loc[s[i]-'a'].back();
			if(loc_right==i){
				ans+=(sum(strlen(s+1))-sum(loc_right))>>1;///当遍历到只有一个字母的时候 根据对称性得 
			}
			else{
				ans+=sum(strlen(s+1))-sum(loc_right);
			}
			loc[s[i]-'a'].pop_back();
			add(i,-1); 
			add(loc_right,-1);
			vis[i]=vis[loc_right]=true;
		}
		printf("%d\n",ans);
		//memset(s,0,sizeof(s));
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:51:17: error: 'll' was not declared in this scope
   51 |                 ll ans=0;
      |                 ^~
a.cc:56:33: error: 'ans' was not declared in this scope; did you mean 'abs'?
   56 |                                 ans+=(sum(strlen(s+1))-sum(loc_right))>>1;///当遍历到只有一个字母的时候 根据对称性得
      |                                 ^~~
      |                                 abs
a.cc:59:33: error: 'ans' was not declared in this scope; did you mean 'abs'?
   59 |                                 ans+=sum(strlen(s+1))-sum(loc_right);
      |                                 ^~~
      |                                 abs
a.cc:66:31: error: 'ans' was not declared in this scope; did you mean 'abs'?
   66 |                 printf("%d\n",ans);
      |                               ^~~
      |                               abs
Language: C++

/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int mx=2e5+5;
char str[mx];
vector <int> index[26];
int ara[mx],temp[mx];
ll ans;

void inversion_count(int lo,int hi)
{
    if (lo==hi) return;
    int mid=(lo+hi)/2;

    inversion_count(lo,mid);
    inversion_count(mid+1,hi);

    int i,j,k;
    for (i=lo,j=mid+1,k=lo;k<=hi;k++) {
        if (i==mid+1) temp[k]=ara[j++];
        else if (j==hi+1) temp[k]=ara[i++];
        else if (ara[i]<=ara[j]) temp[k]=ara[i++];
        else {
            ans+=mid-i+1;
            temp[k]=ara[j++];
        }
    }
    for (i=lo;i<=hi;i++) ara[i]=temp[i];
}

int main ()
{
    int i,n;

    scanf ("%s",str);
    n=strlen(str);
    for (i=0;i<n;i++) {
        index[str[i]-'a'].push_back(i);
    }
    int cnt=0;
    for (i=0;i<26;i++) cnt+=index[i].size()%2;
    if (cnt>1) {
        printf("-1\n");
        return 0;
    }

    cnt=0;
    for (i=0;i<26;i++) {
        if (index[i].size()%2) {
            ara[index[i][0]]=n/2+1;
            break;
        }
    }
    for (i=0;i<n;i++) {
        if (ara[i]) continue;
        ara[index[str[i]-'a'].back()]=n-cnt;
        ara[i]=++cnt;
        index[str[i]-'a'].pop_back();
    }
  //  for (i=0;i<n;i++) printf ("%d ",ara[i]);cout<<endl<<ans<<endl;
    inversion_count(0,n-1);
    printf ("%lld\n",ans);

    return 0;
}


Compiler output:
a.cc:9:22: error: 'std::vector<int> index [26]' redeclared as different kind of entity
    9 | vector <int> index[26];
      |                      ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:3:
/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:41:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   41 |         index[str[i]-'a'].push_back(i);
      |              ^
a.cc:44:34: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   44 |     for (i=0;i<26;i++) cnt+=index[i].size()%2;
      |                                  ^
a.cc:52:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   52 |         if (index[i].size()%2) {
      |                  ^
a.cc:53:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |             ara[index[i][0]]=n/2+1;
      |                      ^
a.cc:59:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   59 |         ara[index[str[i]-'a'].back()]=n-cnt;
      |                  ^
a.cc:61:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   61 |         index[str[i]-'a'].pop_back();
      |              ^