Help me in solving BROKENSTRING problem

My issue

can anyone please explain , why this code is wrong.

My code

#include <iostream>
using namespace std;

int main() {

    int T;
    string S;
    
    
    cin >> T;
    
    for(int i = 0; i < T; i++){
        
        cin >> S;
        
        int length = S.length();
        int middle = length/2;
        string first_half = S.substr(0,middle);
        string second_half = S.substr(middle);
        
        if(first_half+second_half == S || second_half+first_half == S ||  first_half == second_half )
        {
            cout << "YES" << endl;
        }
        
        else {
            cout << "NO" << endl;
        }
        
        
    }
    
	return 0;
}
	

	

Problem Link: BROKENSTRING Problem - CodeChef

for _ in range(int(input())):
n = int(input())
s = input()
s1 = s[:n//2]
s2 = s[n//2:]
if s1 == s2[::-1]:
print(“YES”)
else:
print(“NO”)

@mukesh_575
Have corrected your code. u haven’t taken input for n .
include
using namespace std;

int main() {

int T;



cin >> T;

for(int i = 0; i < T; i++){
    int n;
    cin>>n;
    
        string S;
    cin >> S;
    
    int length = S.length();
    int middle = length/2;
    string first_half = S.substr(0,middle);
    string second_half = S.substr(middle,middle);
    if(first_half == second_half )
    {
        cout << "YES" << endl;
    }
    
    else {
        cout << "NO" << endl;
    }
    
    
}

return 0;

}