fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val left = s.count{it=='('}
    val right = n - left
    var diff = left - right

    /** (で増えて)で減る */
    var count = 0

    val result = StringBuilder()

    for (c in s) {
        if (c == '(') {
            count++
            result.append('(')

        } else {
            count--
            if (count < 0) {
                result.insert(0, '(')
                result.append(')')
                count++
            } else {
                result.append(')')
            }
        }
    }
    repeat(count) { result.append(')') }

    println(result)

}
