import copy

example = [
    ["nop", "+0"],
    ["acc", "+1"],
    ["jmp", "+4"],
    ["acc", "+3"],
    ["jmp", "-3"],
    ["acc", "-99"],
    ["acc", "+1"],
    ["jmp", "-4"],
    ["acc", "+6"]
]

def one(data):
    n = len(data)
    count = 0
    acc = 0
    idx = []
    done = False
    while True:
        if count in idx:
            break

        if count == n:
            done = True
            break

        act, val = data[count]
        idx.append(count)
        if act == 'jmp':
            count += int(val)
        elif act == 'acc':
            acc += int(val)
            count += 1
        else:
            count += 1
            
    return acc, done

def two(data):
    for i, line in enumerate(data):
        d = copy.deepcopy(data)
        if "jmp" in line:
            d[i][0] = "nop"
        elif "nop" in line:
            d[i][0] = "jmp"
        else:
            continue

        acc, done = one(d)
        if done:
            break
            
    return acc, done

with open('input.txt', 'r') as f:
    raw = f.read().splitlines()
    data = [r.split(' ') for r in raw]

print(one(example))
print(one(data))
print(two(data))