import sequtils,strutils,algorithm,math proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: var k = getchar_unlocked() if k < '0' or k > '9': break else: result = 10 * result + k.ord - '0'.ord proc putchar_unlocked(c:char){.header: "" .} proc printInt(a:int32) = if a == 0: putchar_unlocked('0') return var n = a var rev = a var cnt = 0 while rev mod 10 == 0: cnt += 1 rev = rev div 10 rev = 0 while n != 0: rev = (rev shl 3) + (rev shl 1) + n mod 10 n = n div 10 while rev != 0: putchar_unlocked((rev mod 10 + '0'.ord).chr) rev = rev div 10 while cnt != 0: putchar_unlocked('0') cnt -= 1 template useStack() = type Stack*[T] = ref object data: seq[T] size: int index: int proc newStack*[T](size: int = 64): Stack[T] = new(result) result.data = newSeq[T](size) result.size = size result.index = -1 proc `$`*[T](self: Stack[T]): string = $(self.data[..self.index]) proc isEmpty*[T](self: Stack[T]): bool = self.index < 0 proc isValid*[T](self: Stack[T]): bool = self.index >= 0 and self.index < self.size proc len*[T](self: Stack[T]): int = (if self.isEmpty(): 0 else: self.index + 1) proc top*[T](self: Stack[T]): T = self.data[self.index] proc pop*[T](self: var Stack[T]): T {.discardable.} = (result = self.top(); self.index -= 1) proc push*[T](self: var Stack[T], elem: T) = self.index += 1 if self.index < self.size: self.data[self.index] = elem else: self.data.add(elem) self.size += 1 useStack() let n = scan() var A = newSeq[int32](n + 1) var s = newStack[int32](n div 2 + 10) for i in 1.int32 .. n.int32: if getchar_unlocked() == '(': s.push(i) else: A[i] = s.pop() A[A[i]] = i for i in 1..n: A[i].printInt() putchar_unlocked('\n')