#!/usr/bin/perl -l

print $_ = "()" x shift;
print while s{^  ( \(+ )  ( \)+ ) \(  }
             {"()" x (length($2) - 1)
              . "("  x (length($1) - length($2) + 2)
              . ")"
             }xe;
