# frozen_string_literal: true def solve result = Array.new(N) stack = [] S.each_with_index do |s, i| case s when '(' stack << i when ')' a = stack.pop result[i] = a result[a] = i end end result.map { _1 + 1 } end N = gets.to_i S = gets.chomp.chars puts solve