code: def compress_amount(n):
      
      if not n: return 0
      e = 0
      while (n % 10) == 0 and e < 9:
          n = n // 10
          e = e + 1
      if e < 9:
          n, d = divmod(n, 10);
          return 1 + (n*9 + d - 1)*10 + e
      else:
          return 1 + (n - 1)*10 + 9
docs: \
      Compress 64-bit integer values, preferring a smaller size for whole
      numbers (base-10), so as to achieve run-length encoding gains on real-
      world data. The basic algorithm:
          * If the amount is 0, return 0
          * Divide the amount (in base units) evenly by the largest power of 10
            possible; call the exponent e (e is max 9)
          * If e<9, the last digit of the resulting number cannot be 0; store it
            as d, and drop it (divide by 10); regardless, call the result n
          * Output 1 + 10*(9*n + d - 1) + e
          * If e==9, we only know the resulting number is not zero, so output
            1 + 10*(n - 1) + 9.
      (This is decodable, as d is in [1-9] and e is in [0-9].)