from collections import deque





def check(s):

    x = 0

    for i in range(len(s)):

        if s[i] == "(":

            x += 1

        else:

            x -= 1



        if x < 0:

            return False



    if x == 0:

        return True

    else:

        return False





def main():

    n, s = int(eval(input())), eval(input())



    ss, q = "", deque()

    for i in range(len(s)):

        if s[i] == "(":

            ss += "("

        else:

            if len(ss) != 0:

                ss += ")"

                if check(ss):

                    q.append(ss)

                    ss = ""

            else:

                ss = "("

                while len(q) != 0:

                    ss += q.popleft()

                ss += ")"

                q.append(ss)

                ss = ""



    if len(ss) != 0:

        c = 0

        for i in range(len(ss)):

            if ss[i] == "(":

                c += 1

            else:

                c -= 1

        ss += ")" * c



    s = ""

    while len(q) != 0:

        s += q.popleft()



    print((s+ss))





if __name__ == '__main__':

    main()

def main():

    n, s = int(eval(input())), eval(input())



    cnt, f = 0, 0

    for i in range(n):

        if s[i] == "(":

            cnt += 1

        else:

            cnt -= 1

            if cnt < 0:

                f += 1

                cnt = 0



    ans = f * "(" + s + cnt * ")"

    print(ans)





if __name__ == '__main__':

    main()

from collections import deque


def check(s):
    x = 0
    for i in range(len(s)):
        if s[i] == "(":
            x += 1
        else:
            x -= 1
        if x < 0:
            return False
    if x == 0:
        return True
    else:
        return False


def main():
    n, s = int(eval(input())), eval(input())
    ss, q = "", deque()
    for i in range(len(s)):
        if s[i] == "(":
            ss += "("
        else:
            if len(ss) != 0:
                ss += ")"
                if check(ss):
                    q.append(ss)
                    ss = ""
            else:
                ss = "("
                while len(q) != 0:
                    ss += q.popleft()
                ss += ")"
                q.append(ss)
                ss = ""
    if len(ss) != 0:
        c = 0
        for i in range(len(ss)):
            if ss[i] == "(":
                c += 1
            else:
                c -= 1
        ss += ")" * c
    s = ""
    while len(q) != 0:
        s += q.popleft()
    print((s + ss))


if __name__ == "__main__":
    main()

def main():
    n, s = int(eval(input())), eval(input())
    cnt, f = 0, 0
    for i in range(n):
        if s[i] == "(":
            cnt += 1
        else:
            cnt -= 1
            if cnt < 0:
                f += 1
                cnt = 0
    ans = f * "(" + s + cnt * ")"
    print(ans)


if __name__ == "__main__":
    main()

-from collections import deque - - -def check(s): -    x = 0 -    for i in range(len(s)): -        if s[i] == "(": -            x += 1 -        else: -            x -= 1 -        if x < 0: -            return False -    if x == 0: -        return True -    else: -        return False - - -    ss, q = "", deque() -    for i in range(len(s)): +    cnt, f = 0, 0 +    for i in range(n): -            ss += "(" +            cnt += 1 -            if len(ss) != 0: -                ss += ")" -                if check(ss): -                    q.append(ss) -                    ss = "" -            else: -                ss = "(" -                while len(q) != 0: -                    ss += q.popleft() -                ss += ")" -                q.append(ss) -                ss = "" -    if len(ss) != 0: -        c = 0 -        for i in range(len(ss)): -            if ss[i] == "(": -                c += 1 -            else: -                c -= 1 -        ss += ")" * c -    s = "" -    while len(q) != 0: -        s += q.popleft() -    print((s + ss)) +            cnt -= 1 +            if cnt < 0: +                f += 1 +                cnt = 0 +    ans = f * "(" + s + cnt * ")" +    print(ans)