import sys, os from collections import Counter as C from collections import defaultdict as dd """ same convention as SVG W (0,0)┌───────────► x │ H │ │ │ ▼ y grid G store list of rows to get G(x,y), must first extract row y and then col y => G[y][x] """ def grid_geom(G): H = len(G) W = len(G[0]) return W, H def in_grid(G, x, y) -> bool: W, H = grid_geom(G) return x>=0 and x=0 and y