# Make Palindrome 2 Difficulty Rating:1393, why do I always get one wrong answer in the test?

int main() {
int t;
std::cin >> t;
while(t–){
int n, ones = 0, zeros = 0;
std::cin >> n;
int s[n], pal[n];
char in;

``````    for(int i = 0; i < n; i++){
std::cin >> in;
s[i] = in - '0';
pal[i] = -1;
if(s[i] == 1)
ones++;
}
zeros = n - ones;
int ops = n / 2, l = 0, r = n - 1;
int rangel = ops, ranger = ops;
if(n % 2 == 0){
rangel--;
}
while((l <= rangel || r >= ranger) && ops >= 0) {
if(s[l] != s[r]){
//std::cout << "BEFORE s[" << l << "]="<<s[l] << ", s[" << r << "]=" << s[r]<<" | \n";
if(ones > zeros){
if(s[l])
r--;
else
l++;
}
else if(zeros > ones){
if(s[l] == 0)
r--;
else
l++;
}
else{
if(s[l + 1] == s[r]){
pal[l + 1] = s[l + 1];
pal[r] = s[r];
r--;
l += 2;
}
else if(s[l] == s[r - 1]){
pal[l] = s[l];
pal[r - 1] = s[r - 1];
r -= 2;
l--;
}
}
ops--;
//std::cout << "AFTER s[" << l << "]="<<s[l] << ", s[" << r << "]=" << s[r]<<" || \n";
}
else{
//std::cout << "s[" << l << "]="<<s[l] << ", s[" << r << "]=" << s[r]<<"||| \n";
pal[l] = s[l];
pal[r] = s[r];
l++;
r--;
}
}

//std::cout << " l = " << l << " r = " << r << "\n";
int count = 0;
for(int i = 0; i < n; i++){
if(pal[i] == -1)
count++;
else
break;
}
if(count < n){
for(int i = 0; i < n; i++){
if(pal[i] != -1)
std::cout << pal[i];
}
}
else
{
for(int i = 0; i < n / 2; i++)
std::cout << s[i];
}
std::cout << "\n";
}
return 0;
``````

}