local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
local str2tbl = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
--
local N = read.nl()
local S = str2tbl(read.l())
local depth = 0
local after = {}
for i=N,1,-1 do
    if S[i] == '(' then
        depth = depth - 1
    else
        depth = depth + 1
    end
    if depth < 0 then
        table.insert(after, ')')
        depth = depth + 1
    end
end
local before = {}
for i=1,depth do
    table.insert(before, '(')
end
local function t2s(t) return table.concat(t,"") end
print(t2s(before) .. t2s(S) .. t2s(after))
