comefrom: <doocs>2033.Minimum Operations to Make a Uni-Value Grid_1.py
code: def minOperations( grid: List[List[int]], x: int) -> int:
      nums = []
      m, n = len(grid), len(grid[0])
      base = grid[0][0]
      for i in range(m):
          for j in range(n):
              if abs(grid[i][j] - base) % x != 0:
                  return -1
              nums.append(grid[i][j])
      nums.sort()
      mid = nums[len(nums) >> 1]
      ans = 0
      for num in nums:
          ans += abs(num - mid) // x
      return ans
masked: def sample_funcname ( var_0 : List [ List [ int ] ] , var_3 : int ) -> int :
      var_4 = [ ]
      var_6 , var_8 = len ( var_0 ) , len ( var_0 [ 0 ] )
      var_9 = var_0 [ 0 ] [ 0 ]
      for var_11 in range ( var_6 ) :
          for var_12 in range ( var_8 ) :
              if abs ( var_0 [ var_11 ] [ var_12 ] - var_9 ) % var_3 != 0 :
                  return - 1
              var_4.append ( var_0 [ var_11 ] [ var_12 ] )
      var_4.sort ( )
      var_17 = var_4 [ len ( var_4 ) >> 1 ]
      var_18 = 0
      for var_19 in var_4 :
          var_18 += abs ( var_19 - var_17 ) // var_3
      return var_18
  