lines = open("input.txt", 'r').read().splitlines() sum = 0 for l in lines: first = "" firstFound = False last = "" lastFound = False for i in range(len(l)): if not firstFound and l[i].isnumeric(): first = l[i] firstFound = True if not lastFound and l[-i-1].isnumeric(): last = l[-i-1] lastFound = True if firstFound and lastFound: break sum += int(first + last) print(sum)