#include #include #include #include #include using namespace std; template void print(const T t, bool ln = true) { cout << t; if (ln) { cout << '\n'; } else { cout << ' '; } } template void printv(const vector &v) { for (int i = 0; i < (int)v.size(); i++) { print(v[i], false); } cout << '\n'; } template void printvv(const vector> &vv) { for (int i = 0; i < (int)vv.size(); i++) { vprint(vv[i]); } } bool check(const vector> &v) { int n = v.size(); vector p(n); for (int i = 0; i < n; i++) p[i] = i; int cnt = 0; do { int now = 0; for (auto i: p) { now -= v[i].first; if (now < 0) { break; } now += v[i].second; } if (now == 0) { cnt++; } } while (next_permutation(p.begin(), p.end())); if (cnt == 1) { return true; } else { return false; } } void solve() { int n; cin >> n; vector> a(n); for (int i = 0, j = n - 1; i <= j; i++, j--) { a[i].second = i + 1; a[j].first = i + 1; a[i].first = i; a[j].second = i; } for (const auto &[l, r]: a) { for (int i = 0; i < l; i++) { cout << ')'; } for (int i = 0; i < r; i++) { cout << '('; } cout << '\n'; } if (check(a)) { cerr << "YES" << endl; } else { cerr << "NO" << endl; } } int main() { int q = 1; // cin >> q; while (q--) { solve(); } }