#include #include #include using namespace std; vector> getNext(const string& s){ vector> res(s.size(), vector(26, s.size())); vector last(26, s.size()+1); for(int i=s.size()-1;i>=0;i--){ last[s[i]-'a'] = i+1; for(int j=0;j<26;j++) res[i][j] = last[j]; } return res; } string solve(const string& S, const string& T){ auto nextS = getNext(S); auto nextT = getNext(T); vector> dp(S.size()+1, vector(T.size()+1, 0)); for(int i=S.size()-1;i>=0;i--){ for(int j=T.size()-1;j>=0;j--){ dp[i][j] = dp[i+1][j+1] + (S[i] == T[j] ? 1 : 0); dp[i][j] = max(dp[i][j], dp[i+1][j]); dp[i][j] = max(dp[i][j], dp[i][j+1]); } } if(dp[0][0] == S.size()) return "-1"; int posS = 0, posT = 0; string res = ""; while(posS < S.size()){ for(int i=0;i<26;i++){ int ns = nextS[posS][i]; int nt = (posT < T.size() ? nextT[posT][i] : T.size()+1); if(ns > S.size()) continue; if(nt > T.size()){ res += 'a'+i; return res; } if(dp[ns][nt] != S.size()-ns){ res += 'a'+i; posS = ns; posT = nt; break; } } } return res; } int main(){ string S, T; while(cin >> S >> T){ cout << solve(S, T) << endl; } }