Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll; 
#define endl '\n';
#define mp make_pair
#define pb push_back

void solve (){
    string a,b;
    cin>>a>>b;
    if(a==b){
        cout<<a;
        return;
    }
    if(a.size()%2 || b.size()%2){
        cout<<-1;
        return;
    }
    string aa,bb;
    int l=0,r=a.size()/2;
    while (r!=a.size()){
        if(a[r]!=a[l]){
            cout<<-1;
            return;
        }
        else aa+=a[l];
        l++;
        r++;
    }
    l=0,r=a.size()/2;
    while (r!=b.size()){
        if(b[r]!=b[l]){
            cout<<-1;
            return;
        }
        else bb+=b[l];
        l++;
        r++;
    }
    cout<<bb+aa;
}
int main ()
{    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen ("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int t=1;
    //cin>>t;
    while (t--)
        solve();

    return 0;
}
Copy
Right into Two noomaL
GNU G++17
0 ms
512 KB
Wrong Answer