def find_available_filename(filename):
    if (not os.path.exists(filename)):
        return filename
    attempts = 1
    filename += str(attempts)
    while os.path.exists(filename):
        attempts += 1
        if (attempts > 999):
            print('error: could not find available filename', filename)
            exit()
        filename = (filename[:(len(filename) - 1)] + str(attempts))
    return filename
def find_available_filename(filename):
    if (not os.path.exists(filename)):
        return filename
    attempts = 1
    filename += str(attempts)
    while os.path.exists(filename):
        attempts += 1
        if (attempts > 999):
            print('error: could not find available filename', filename)
            exit()
        filename = (filename[:(len(filename) - 1)] + str(attempts))
    return filename