#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
string::iterator itb, it;
int len, ans = 0, i, j;
int b = 0;
cin >> len >> s;
itb = s.begin();
it = s.end() - 1;
if(len > 1)
while (true) {
if (it != itb && *itb != *it)
--it;
else if (it == itb) {
if(len % 2 != 1 || b == 1) {
b = 2;
break;
}
char x = *it;
s.erase(it);
s.insert(itb + s.size() / 2, x);
ans += s.size() / 2;
b = 1;
it = s.end() - 1;
}
else {
ans += s.end() - it - 1;
s.erase(it);
s.erase(itb);
if (s.size() < 2)
break;
it = s.end() - 1;
}
}
if (b != 2)
cout << ans;
else
cout << "Impossible";
return 0;
}
文章标题
最新推荐文章于 2023-10-19 15:03:50 发布