1# Runtime: 970 ms (Top 9.86%) | Memory: 20.6 MB (Top 59.47%)2class Solution:3def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:4obs = set(tuple(o) for o in obstacles)5x = y = a = out = 06move = {0: (0, 1), 90: (1, 0), 180: (0, -1), 270: (-1, 0)}7for c in commands:8if c == -1:9a += 9010elif c == -2:11a -= 9012else:13direction = a % 36014dx, dy = move[direction]15for _ in range(c):16if (x + dx, y + dy) in obs:17break18x += dx19y += dy20out = max(out, x**2 + y**2)21return out