def run(commands):
    """
    Execute an input program. Returns the acc value and a boolean indicating if
    the program exited cleanly or encountered a loop.
    """

    run_count = set()
    acc = 0
    line = 0

    while line not in run_count:
        run_count.add(line)

        if commands[line][0] == 'acc':
            acc += int(commands[line][1])

        if commands[line][0] == 'jmp':
            line += int(commands[line][1])
        else:
            line += 1

        if line >= len(commands):
            return acc, True

    return acc, False