classSolution:defmovingCount(self,m:int,n:int,k:int) ->int: seen =set()defdfs(i,j):if (i, j) in seen:returnifnot0<= i < m ornot0<= j < n:return total =0 ti, tj = i, jwhile ti: total += ti - (ti //10) *10if ti >9else ti ti = ti //10while tj: total += tj - (tj //10) *10if tj >9else tj tj = tj //10if total > k:return seen.add((i, j))dfs(i -1, j)dfs(i +1, j)dfs(i, j -1)dfs(i, j +1)dfs(0, 0)returnlen(seen)