text: class Solution:
    def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:
      dx = [0, 1, 0, -1]
      dy = [1, 0, -1, 0]
      x = y = di = ans = 0
      obstacleSet = set(map(tuple, obstacles))
      for cmd in commands:
        if cmd == -2:
          di = (di - 1) % 4
        elif cmd == -1:
          di = (di + 1) % 4
        else:
          for k in range(cmd):
            if (x+dx[di], y+dy[di]) not in obstacleSet:
              x += dx[di]
              y += dy[di]
              ans = max(ans, x*x + y*y)
      return ans
  