using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contests
{
    enum Variant
    {
        Index,
        Minimal,
        Composition,
        Sequence,
        Add,
    }
    class Holder
    {
        public Variant Variant {get;set;}
        public int Start { get; set; }
        public int End { get; set; }
        public char Added { get; set; }
        public int Count { get; set; }
        public Holder(int i)
        {
            Variant = Variant.Index;
            Start = End = i;
        }
        public Holder(int start, int end, Variant variant = Variant.Composition)
        {
            Variant = variant;
            Start = start;
            End = end;
        }
        public Holder(char c, int count)
        {
            Variant = Variant.Add;
            Added = c;
            Count = count;
        }


        public bool IsIndex() { return Variant == Variant.Index; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine();
            var holders = Enumerable.Range(0, n).Select(i => new Holder(i)).ToList();
            while (true)
            {
                var newHolders = new List<Holder>();
                for(int i = 0; i < holders.Count; i++)
                {
                    if(holders[i].IsIndex())
                    {
                        if(i+1 < holders.Count && input[holders[i].Start] == '(')
                        {
                            if(holders[i+1].IsIndex() && input[holders[i+1].Start] == ')')
                            {
                                newHolders.Add(new Holder(holders[i].Start, holders[i + 1].End, Variant.Minimal));
                                i++;
                            }
                            else if(i+2 < holders.Count && !holders[i+1].IsIndex() && holders[i+2].IsIndex() && input[holders[i+2].Start] == ')')
                            {
                                newHolders.Add(new Holder(holders[i].Start, holders[i + 2].End, Variant.Composition));
                                i += 2;

                            }
                            else
                            {
                                newHolders.Add(holders[i]);
                            }
                        }
                        else
                        {
                            newHolders.Add(holders[i]);
                        }
                    }
                    else
                    {
                        if(i + 1 < holders.Count && !holders[i+1].IsIndex())
                        {
                            var h1 = holders[i];
                            var h2 = holders[i + 1];
                            newHolders.Add(new Holder(h1.Start, h2.End));
                            i++;
                        }
                        else
                        {
                            newHolders.Add(holders[i]);
                        }
                    }
                }
                if (holders.Count <= newHolders.Count) break;
                holders = newHolders;
            }
            int left = 0;
            for(int i = 0; i < holders.Count(); i++)
            {
                if (holders[i].IsIndex())
                {
                    if(input[holders[i].Start] == '(')
                    {
                        left++;
                    }
                    else if(left > 0)
                    {
                        holders.Insert(i, new Holder(')', left));
                        left = 0;
                        i++;
                    }
                }
            }
            if(left > 0)
            {
                holders.Add(new Holder(')', left));
            }
            int right = 0;
            for(int i = holders.Count() - 1; i >= 0 ; i--)
            {
                if (holders[i].IsIndex())
                {
                    if(input[holders[i].Start] == ')')
                    {
                        right++;
                    }
                    else if(right > 0)
                    {
                        holders.Insert(i + 1, new Holder(')', right));
                        right = 0;
                    }
                }
            }
            if(right > 0)
            {
                holders.Insert(0, new Holder('(', right));
            }
            foreach (var holder in holders)
            {
                if(holder.Variant == Variant.Index)
                {
                    Console.Write(input[holder.Start]);
                }else if(holder.Variant == Variant.Add)
                {
                    for (int i = 0; i < holder.Count; i++) Console.Write(holder.Added);
                }else
                {
                    for (int i = holder.Start; i <= holder.End; i++) Console.Write(input[i]);
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13396