def part_1(program):
    memory = {}
    mask_to_0 = 0
    mask_to_1 = 0
    for line in program:
        if (line[:4] == 'mask'):
            mask = line[7:]
            mask_to_1 = int(''.join(((m if (m == '1') else '0') for m in mask)), 2)
            mask_to_0 = int(''.join(((m if (m == '0') else '1') for m in mask)), 2)
        else:
            (address, value) = (int(x) for x in re.findall('(\\d+)', line))
            memory[address] = ((value | mask_to_1) & mask_to_0)
    return sum(memory.values())
def part_1(program):
    memory = {}
    mask_to_0 = 0
    mask_to_1 = 0
    for line in program:
        if (line[:4] == 'mask'):
            mask = line[7:]
            mask_to_1 = int(.join(((m if (m == '1') else '0') for m in mask)), 2)
            mask_to_0 = int(.join(((m if (m == '0') else '1') for m in mask)), 2)
        else:
            (address, value) = (int(x) for x in re.findall('(\\d+)', line))
            memory[address] = ((value | mask_to_1) & mask_to_0)
    return sum(memory.values())