def loopToWord(loop):
    """
    Write a loop in gap notation using the standard generators of pi_1(D).

    The return format is a list of integers with the following meaning:
        [1, -2] = x_1 x_2^{-1}
    ...where x_i (1 <= i <= n) is the anticlockwise loop around puncture i.

    By convention, path composition is left-to-right. That is, "x_1 x_2"
    means "follow x_1, then follow x_2".

    """
    if loop[0] < 0:
        raise NotImplementedError
    i = iter(loop)
    ans = []
    while True:
        try:
            up = i.next()
        except StopIteration:
            break
        down = -i.next()
        if down == up:
            continue
        elif down > up:
            down = -down
            up = -up
        else:
            down -= 1
            up -= 1
        ans.extend(range(up, down, -1))
    return ans
