/*
Failure is not the reason for you to stop trying
it is actually a remainder that you should
KEEP GOING
*/
#include<bits/stdc++.h>
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false), cin.tie(0);
using namespace std;
int main()
{
SaveTime
string a,b; cin >> a >> b;
if (a == b) {
cout << a;
return 0;
}
else {
int n1 = a.size(), n2 = b.size();
if ((n1+n2) %2) {
cout << -1;
return 0;
}
string ans = "-1";
for (int i = 0; i < n1; i++) {
string s1 = a.substr(0, i+1);
int nb = (n1+n2)/2;
int rem = n2+i+1-nb;
if (rem <= 0)
continue;
if (n2-rem <= 0) {
continue;
}
string s2 = b.substr(n2-rem, rem);
string ch1 = s2+a.substr(i+1, n1-i-1);
string ch2 = b.substr(0, n2-rem) + s1;
if (ch1 == ch2) {
ans = ch1;
break;
}
}
cout << ans;
}
}
Copy