#pragma GCC optimize ("O2") #pragma GCC target ("avx2") #include using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); string S, T; cin >> S >> T; int N = S.size(); int M = T.size(); int A[100001]; int saidai = N; int kari = M - 1; for (int i = N - 1; i >= 0; i--) { while (kari >= 0 && S[i] != T[kari]) { kari--; } A[i] = kari; } vector SL[26]; deque TL[26]; rep(j, N) { SL[S[j] - 'a'].pb(j); } rep(j, M) { TL[T[j] - 'a'].pb(j); } int i = 0, j = 0; string kotae; int iketa = 1; while (iketa) { iketa = 0; rep(p, 26) { auto itr = lower_bound(SL[p].begin(), SL[p].end(), i); if (itr == SL[p].end()) continue; int ind = *itr; int ue = A[ind]; while (TL[p].size() && TL[p].front() < j) TL[p].pop_front(); if (TL[p].size() == 0) { kotae += char('a' + p); co(kotae); return 0; } if (TL[p].front() > ue) { kotae += char('a' + p); i = ind + 1; j = TL[p].front() + 1; TL[p].pop_front(); iketa = 1; break; } } } co(-1); Would you please return 0; }