comefrom: <doocs>0564.Find the Closest Palindrome_1.py
code: def nearestPalindromic( n: str) -> str:
      x = int(n)
      l = len(n)
      res = {10 ** (l - 1) - 1, 10**l + 1}
      left = int(n[: (l + 1) >> 1])
      for i in range(left - 1, left + 2):
          j = i if l % 2 == 0 else i // 10
          while j:
              i = i * 10 + j % 10
              j //= 10
          res.add(i)
      res.discard(x)
      
      ans = -1
      for t in res:
          if (
              ans == -1
              or abs(t - x) < abs(ans - x)
              or (abs(t - x) == abs(ans - x) and t < ans)
          ):
              ans = t
      return str(ans)
masked: def sample_funcname ( var_0 : str ) -> str :
      var_3 = int ( var_0 )
      var_5 = len ( var_0 )
      var_8 = { 10 ** ( var_5 - 1 ) - 1 , 10 ** var_5 + 1 }
      var_9 = int ( var_0 [ : ( var_5 + 1 ) >> 1 ] )
      for var_12 in range ( var_9 - 1 , var_9 + 2 ) :
          var_14 = var_12 if var_5 % 2 == 0 else var_12 // 10
          while var_14 :
              var_12 = var_12 * 10 + var_14 % 10
              var_14 //= 10
          var_8.add ( var_12 )
      var_8.discard ( var_3 )
      var_17 = - 1
      for var_18 in var_8 :
          if ( var_17 == - 1 or abs ( var_18 - var_3 ) < abs ( var_17 - var_3 ) or ( abs ( var_18 - var_3 ) == abs ( var_17 - var_3 ) and var_18 < var_17 ) ) :
              var_17 = var_18
      return str ( var_17 )
  