import sys

path = sys.argv[1] if len(sys.argv) > 1 else "input.txt"
with open(path) as f:
   input = list(map(int,f.readlines()))

preamble_length = 5 if path == "example.txt" else 25
preamble = set()
index = 0

while index < preamble_length and index < len(input):
    preamble.add(input[index])
    index += 1

is_valid = True
while index < len(input) and is_valid:
    is_valid = False
    for p in preamble:
        if input[index] - p in preamble:
            is_valid = True
            preamble.remove(input[index - preamble_length])
            preamble.add(input[index])
            index += 1

print(index)
invalid_number = input[index]
print(f"Part One: {invalid_number}")

index_low = index - 1
index_high = index

while sum(input[index_low:index_high]) != invalid_number:
    if sum(input[index_low:index_high]) > invalid_number:
        index_high -= 1
        index_low = index_high -1
    else:
        index_low -= 1

range = input[index_low:index_high]
print(f"Part Two: {min(range) + max(range)}")
0c04550673db17cb00a60465e6c86eb3572e4d84
<mask token>

<mask token>
with open(path) as f:
    input = list(map(int, f.readlines()))
<mask token>
while index < preamble_length and index < len(input):
    preamble.add(input[index])
    index += 1
<mask token>
while index < len(input) and is_valid:
    is_valid = False
    for p in preamble:
        if input[index] - p in preamble:
            is_valid = True
            preamble.remove(input[index - preamble_length])
            preamble.add(input[index])
            index += 1
print(index)
<mask token>
print(f'Part One: {invalid_number}')
<mask token>
while sum(input[index_low:index_high]) != invalid_number:
    if sum(input[index_low:index_high]) > invalid_number:
        index_high -= 1
        index_low = index_high - 1
    else:
        index_low -= 1
<mask token>
print(f'Part Two: {min(range) + max(range)}')

<mask token>
path = sys.argv[1] if len(sys.argv) > 1 else 'input.txt'
with open(path) as f:
    input = list(map(int, f.readlines()))
preamble_length = 5 if path == 'example.txt' else 25
preamble = set()
index = 0
while index < preamble_length and index < len(input):
    preamble.add(input[index])
    index += 1
is_valid = True
while index < len(input) and is_valid:
    is_valid = False
    for p in preamble:
        if input[index] - p in preamble:
            is_valid = True
            preamble.remove(input[index - preamble_length])
            preamble.add(input[index])
            index += 1
print(index)
invalid_number = input[index]
print(f'Part One: {invalid_number}')
index_low = index - 1
index_high = index
while sum(input[index_low:index_high]) != invalid_number:
    if sum(input[index_low:index_high]) > invalid_number:
        index_high -= 1
        index_low = index_high - 1
    else:
        index_low -= 1
range = input[index_low:index_high]
print(f'Part Two: {min(range) + max(range)}')

import sys
path = sys.argv[1] if len(sys.argv) > 1 else 'input.txt'
with open(path) as f:
    input = list(map(int, f.readlines()))
preamble_length = 5 if path == 'example.txt' else 25
preamble = set()
index = 0
while index < preamble_length and index < len(input):
    preamble.add(input[index])
    index += 1
is_valid = True
while index < len(input) and is_valid:
    is_valid = False
    for p in preamble:
        if input[index] - p in preamble:
            is_valid = True
            preamble.remove(input[index - preamble_length])
            preamble.add(input[index])
            index += 1
print(index)
invalid_number = input[index]
print(f'Part One: {invalid_number}')
index_low = index - 1
index_high = index
while sum(input[index_low:index_high]) != invalid_number:
    if sum(input[index_low:index_high]) > invalid_number:
        index_high -= 1
        index_low = index_high - 1
    else:
        index_low -= 1
range = input[index_low:index_high]
print(f'Part Two: {min(range) + max(range)}')

import sys

path = sys.argv[1] if len(sys.argv) > 1 else "input.txt"
with open(path) as f:
   input = list(map(int,f.readlines()))

preamble_length = 5 if path == "example.txt" else 25
preamble = set()
index = 0

while index < preamble_length and index < len(input):
    preamble.add(input[index])
    index += 1

is_valid = True
while index < len(input) and is_valid:
    is_valid = False
    for p in preamble:
        if input[index] - p in preamble:
            is_valid = True
            preamble.remove(input[index - preamble_length])
            preamble.add(input[index])
            index += 1

print(index)
invalid_number = input[index]
print(f"Part One: {invalid_number}")

index_low = index - 1
index_high = index

while sum(input[index_low:index_high]) != invalid_number:
    if sum(input[index_low:index_high]) > invalid_number:
        index_high -= 1
        index_low = index_high -1
    else:
        index_low -= 1

range = input[index_low:index_high]
print(f"Part Two: {min(range) + max(range)}")