import java.util.ArrayList;

public class match {

    public static int[] matching(String s) {
        int[] res = new int[s.length()];
        for (int i = 0; i < res.length; i++) res[i] = -1;
        Pile p = new TabPile();
        // System.out.println(p.getSize()); interdit getSize n'est pas
        // dans l'interface Pile
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') { p.push(i); }
            else if (s.charAt(i) == ')') {
                int pos = p.pop();
                res[i] = pos;
                res[pos] = i;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] m = matching("()((()())())");
        for (int i = 0; i < m.length; i++)
            System.out.print(" " + m[i]);
        System.out.println();
    }
}
