#!/usr/bin/python3

"""Print the Loday coordinates of a parenthesized expression.

   The atoms of the expression must be digits or letters.
   Spaces and commas are ignored.
   Initial and trailing parens can be omitted.

   Examples:

   python3 coordinates.py "(01)(23)"
   -> 1/4/1

   python3 coordinates.py "(AA)(AA)"
   -> 1/4/1

   python3 coordinates.py "((((0, 1), 2), (3, 4)), 5)"
   -> 1/2/6/1/5

   python3 coordinates.py "xx)x)x)x)x)x)x)x)x)x)x"
   -> 1/2/3/4/5/6/7/8/9/10/11

"""

import re
def coordinate(S):
    S=re.sub('[ ,]', '', S)

    parens = re.split('[0-9A-Za-z]',S)[1:-1]

    N = len(parens)
    dp = [parens[h].count('(') - parens[h+1].count(')') for h in range(N-1)]

    LC = []
    for k in range(N):

        a = 1
        d = 0
        for h in range(k,N-1):
            d += dp[h]
            if d <= 0: break
            a += 1

        b = 1
        d = 0
        for h in range(k):
            d -= dp[k-h-1]
            if d <= 0: break
            b += 1

        LC.append(str(a*b))

    print ('/'.join(LC))

import sys
coordinate(sys.argv[1])
