#include #include #include #include #include #include #include using namespace std; char word[2][110]; char c[100010]; int K, N, X, Y; int diff[110]; vector > found[2]; pair KMP(const string& str, const string& wzo) { #define KMPH(z) while(k>0 && wzo[k] != z[q]) k = p[k]; \ if (wzo[k] == z[q]) k++; int p[wzo.size()+1], k = 0, q, m; p[1] = 0; for(q=1; q= 26) a-= 26; return a; } void wynajdz(int dlugosc, int a) { int m = strlen(word[a]); for(int i=0; i+m <= N; i++) { for(int j=0; j tmp(diff, diff+dlugosc); found[a].push_back(tmp); } } } string wynik, gen; bool cokolwiek; void generate(const vector& cykl) { gen = ""; int pos = 0; for(int i=0; i b; } else { return b + Y > a; } } bool not_verify(const vector& cykl) { generate(cykl); pair A = KMP(gen, wzo0); pair B = KMP(gen, wzo1); //printf("%d %d\n", A.first, A.second); return cross(A.first, B.second) && cross(A.second, B.first); } int main() { while(true) { cokolwiek = false; scanf("%d",&K); if (K == 0) return 0; scanf("%s %s %s", word[0], word[1], c); wzo0 = word[0]; wzo1 = word[1]; X = strlen(word[0]); Y = strlen(word[1]); N = strlen(c); for(int dl = 1; dl <= K; dl++) { found[0].clear(); found[1].clear(); wynajdz(dl, 0); wynajdz(dl, 1); sort(found[0].begin(), found[0].end()); sort(found[1].begin(), found[1].end()); int i = 0, j = 0; while(i < found[0].size() && j < found[1].size()) { if (found[0][i] == found[1][j]) { if (not_verify(found[0][i])) { if (rand() % 2 == 0) i++; else j++; } else { if (!check()) { goto end; } i++; j++; } } else if (found[0][i] < found[1][j]) { i++; } else { j++; } } } if (cokolwiek) printf("%s\n", wynik.c_str()); else printf("impossible\n"); end:; } return 0; }