import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;

void main()
{
  int n = readln.chomp.to!int;
  string s = readln.chomp;
  string sub, ans;
  int index = 0;
  foreach (c; s) {
    final switch(c) {
      case '(':
        ans ~= sub;
        sub = "";
        ++index;
        break;
      case ')':
        if (index == 0) {
          sub = sub ~ ")";
          ans = "(" ~ ans;
        } else {
          sub = "(" ~ sub ~ ")";
          --index;
        }
        break;
    }
  }
  //)))()()()))()()
  foreach (i; 0..index) {
    sub = "(" ~ sub ~ ")";
  }
  writeln = ans ~ sub;
}
