#include #include #include #include #include #include #include #include #include using namespace std; int n; char words[101][101]; char theword[101]; int maxim = 0; bool isPrefix(char* a, char* b) { if (strlen(b) > strlen(a)) return false; int p = strlen(b); for (int i = 0; i < p; i++) { if (a[i] != b[i]) return false; } return true; } bool verifyconcat(char* word, int index) { if (strlen(word) == 0) { return true; } int j; int poz = 0; for (j = 1; j <= n; j++) { if (isPrefix(word, words[j]) && index!=j) { return verifyconcat(word + strlen(words[j]), index); } } return false; } int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); int i; cin >> n; for (i = 1; i <= n; i++) { cin >> words[i]; } int maxim = 0; for (i = 1; i <= n; i++) { if (verifyconcat(words[i], i)) { if (strlen(words[i]) > maxim) { maxim = strlen(words[i]); strcpy(theword, words[i]); } } } if (maxim != 0) { cout << theword; } else cout << -1; return 0; }