This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string S,S1,S2,S3;
   int N,A;
   scanf("%d",&N);
   cin>>S;
   A=N/2;
   for(int j=0,i=A;j<A && i<N;i++,j++){
      if(S[i]==S[j])
         S1+=S[i];
      else{
         for(int k=i+1,l=j;l<A && k<N;k++,l++){
            if(S[k]==S[l])
               S2+=S[k];
            else {
               S2.clear();
               break;
            }
         }
         if(S1.size()+S2.size()==A)
            S1+=S2;
         S2.clear();
         for(int k=i,l=j+1;l<A && k<N;k++,l++){
            if(S[k]==S[l])
               S2+=S[k];
            else {
               S2.clear();
               break;
            }
         }
         if(S1.size()+S2.size()==A)
            S1+=S2;
         S2.clear();
         break;
      }
   }
   for(int j=0,i=A+1;j<=A && i<N;i++,j++){
      if(S[i]==S[j])
         S3+=S[i];
      else{
         for(int k=i+1,l=j;l<=A && k<N;k++,l++){
            if(S[k]==S[l])
               S2+=S[k];
            else {
               S2.clear();
               break;
            }
         }
         if(S3.size()+S2.size()==A)
            S3+=S2;
         S2.clear();
         for(int k=i,l=j+1;l<=A && k<N;k++,l++){
            if(S[k]==S[l])
               S2+=S[k];
            else {
               S2.clear();
               break;
            }
         }
         if(S3.size()+S2.size()==A)
            S3+=S2;
         S2.clear();
         break;
      }
   }
   //cout<<S1<<endl;
   //cout<<S3<<endl;
   if(S1!=S3 && S1.size() == A && S3.size() == A)
      cout<<"NOT UNIQUE"<<endl;
   else if(S1.size()==A){
      cout<<S1<<endl;
   }
   else if(S3.size()==A){
      cout<<S3<<endl;
   }
   else
      cout<<"NOT POSSIBLE"<<endl;
   return 0;
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:23:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          if(S1.size()+S2.size()==A)
                                ^
friends.cpp:34:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          if(S1.size()+S2.size()==A)
                                ^
friends.cpp:52:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          if(S3.size()+S2.size()==A)
                                ^
friends.cpp:63:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          if(S3.size()+S2.size()==A)
                                ^
friends.cpp:71:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(S1!=S3 && S1.size() == A && S3.size() == A)
                           ^
friends.cpp:71:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(S1!=S3 && S1.size() == A && S3.size() == A)
                                             ^
friends.cpp:73:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if(S1.size()==A){
                     ^
friends.cpp:76:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if(S3.size()==A){
                     ^
friends.cpp:8:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&N);
                  ^| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |