···11+import fileinput
22+from itertools import count
33+44+from utils import Point, DIRS
55+66+target = int(fileinput.input()[0])
77+pos = Point(0, 0)
88+seen = {pos: 1}
99+facing = 1
1010+1111+answer_1 = None
1212+answer_2 = None
1313+1414+for i in count(start=2):
1515+ pos = pos + DIRS[facing]
1616+1717+ value = sum(seen.get(p, 0) for p in pos.neighbours_8())
1818+ seen[pos] = value
1919+2020+ if i == target and not answer_1:
2121+ answer_1 = pos.manhattan
2222+2323+ if value > target and not answer_2:
2424+ answer_2 = value
2525+2626+ # Check if we should move straight or turn left next
2727+ if (pos + DIRS[(facing - 1) % 4] not in seen):
2828+ facing = (facing - 1) % 4
2929+3030+ if (answer_1 is not None) and (answer_2 is not None):
3131+ break
3232+3333+print "Step to access port:", answer_1
3434+print "First value larger than puzzle input:", answer_2