def time_remaining(elapsed, n, length):
    """
    Returns a string indicating the time remaining (if not complete)
    or the total time elapsed (if complete).
    """

    if n == 0:
        return '--:--:--'

    if n == length:
        seconds = int(elapsed) # if complete, total time elapsed
    else:
        seconds = int((elapsed / n) * (length - n)) # otherwise, time remaining

    minutes, seconds = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)

    return '%02d:%02d:%02d' % (hours, minutes, seconds)