def format_length(length):
    """Return length in the format MM:SS or HH:MM:SS."""
    length = int(length)
    if length < 3600:
        minutes = length // 60
        seconds = length % 60
        return '{}:{}'.format(format(minutes, '02'), format(seconds, '02'))
    else:
        hours = length // 3600
        minutes = length % 3600 // 60
        seconds = length % 3600 % 60
        return '{}:{}:{}'.format(hours, format(minutes, '02'), format(
            seconds, '02'))
