#include #include #include #define MA 666013LL #define MB 10009LL #define MC 2017LL #define MD 20173333LL using namespace std; char str[128][128]; bool ap[128][128]; long long pa[128], pb[128], pc[128], pd[128], ha[128][128], hb[128][128], hc[128][128], hd[128][128]; int len[128]; int main () { // freopen ("file.in", "r", stdin); int n; scanf ("%d\n", &n); pa[0] = pb[0] = pc[0] = pd[0] = 1LL; for (int i = 1; i <= 105; ++i) pa[i] = 101LL * pa[i - 1] % MA, pb[i] = 101LL * pb[i - 1] % MB, pc[i] = 101LL * pc[i - 1] % MC, pd[i] = 101LL * pd[i - 1] % MD; for (int i = 1; i <= n; ++i) { gets (str[i] + 1); int m = len[i] = strlen (str[i] + 1); for (int j = 1; j <= m; ++j) { ha[i][j] = (ha[i][j - 1] + pa[j - 1] * str[i][j]) % MA; hb[i][j] = (hb[i][j - 1] + pb[j - 1] * str[i][j]) % MB; hc[i][j] = (hc[i][j - 1] + pc[j - 1] * str[i][j]) % MC; hd[i][j] = (hd[i][j - 1] + pd[j - 1] * str[i][j]) % MD; } } int ma = -1, poz; for (int i = 1; i <= n; ++i) { ap[i][0] = true; int m = strlen (str[i] + 1); for (int j = 1; j <= m; ++j) { if (!ap[i][j - 1]) continue; for (int h = 1; h <= n; ++h) { if (i == h || j + len[h] - 1 > m) continue; int mum = len[h]; long long na = ha[i][j + mum - 1] - ha[i][j - 1]; if (na < 0) na += MA; long long va = (ha[h][mum] * pa[j - 1]) % MA; long long nb = hb[i][j + mum - 1] - hb[i][j - 1]; if (nb < 0) nb += MB; long long vb = (hb[h][mum] * pb[j - 1]) % MB; long long nc = hc[i][j + mum - 1] - hc[i][j - 1]; if (nc < 0) nc += MC; long long vc = (hc[h][mum] * pc[j - 1]) % MC; long long nd = hd[i][j + mum - 1] - hd[i][j - 1]; if (nd < 0) nd += MD; long long vd = (hd[h][mum] * pd[j - 1]) % MD; if (na == va && nb == vb && nc == vc && nd == vd) ap[i][j + mum - 1] = true; } } if (ap[i][m] && m > ma) ma = m, poz = i; } if (ma == -1) printf ("-1\n"); else puts (str[poz] + 1); return 0; }