direction = (1, 0) position = [0, 0] def D(x, y): def mv(n): position[0] += x*n position[1] += y*n return mv def F(n): position[0] += direction[0]*n position[1] += direction[1]*n def R(d): def rt(n): global direction directions = [(1, 0), (0, -1), (-1, 0), (0, 1)] direction = directions[int(directions.index(direction) + d * (n/90)) % len(directions)] return rt methods = {"N": D(0, 1), "S": D(0, -1), "E": D(1, 0), "W": D(-1, 0), "L": R(-1), "R": R(1), "F": F} [methods[s[0]](int(s[1:])) for s in open("input", "r").read().split("\n") if s] print(position) print(abs(position[0]) + abs(position[1]))