#include using namespace std; int N; string T[205]; vector completions[205]; void dfs(int id, int depth, int balance, string& cur) { if (completions[id].size() == (size_t)N) return; if (balance < 0 || balance > N - depth) return; if (depth == N) { if (balance == 0) { completions[id].push_back(cur); } return; } char c = T[id][depth]; if (c == '(' || c == '.') { cur.push_back('('); dfs(id, depth + 1, balance + 1, cur); cur.pop_back(); } if (completions[id].size() == (size_t)N) return; if (c == ')' || c == '.') { cur.push_back(')'); dfs(id, depth + 1, balance - 1, cur); cur.pop_back(); } } bool dfs_match(int u, vector& vis, vector& match_right, const vector>& adj) { for (int v : adj[u]) { if (vis[v]) continue; vis[v] = 1; if (match_right[v] == -1 || dfs_match(match_right[v], vis, match_right, adj)) { match_right[v] = u; return true; } } return false; } int main() { cin >> N; for (int i = 0; i < N; ++i) { cin >> T[i]; } if (N % 2 != 0) { cout << -1 << "\n"; return 0; } for (int i = 0; i < N; ++i) { string cur = ""; dfs(i, 0, 0, cur); } vector all_strings; for (int i = 0; i < N; ++i) { for (const string& s : completions[i]) { all_strings.push_back(s); } } sort(all_strings.begin(), all_strings.end()); all_strings.erase(unique(all_strings.begin(), all_strings.end()), all_strings.end()); int V = all_strings.size(); vector> adj(N); for (int i = 0; i < N; ++i) { for (const string& s : completions[i]) { int u = lower_bound(all_strings.begin(), all_strings.end(), s) - all_strings.begin(); adj[i].push_back(u); } } vector match_right(V, -1); vector match_left(N, -1); int matches = 0; for (int i = 0; i < N; ++i) { vector vis(V, 0); if (dfs_match(i, vis, match_right, adj)) { matches++; } } if (matches < N) { cout << -1 << "\n"; } else { for (int v = 0; v < V; ++v) { if (match_right[v] != -1) { match_left[match_right[v]] = v; } } for (int i = 0; i < N; ++i) { cout << all_strings[match_left[i]] << "\n"; } } return 0; }