




def    UpperCAmelCase_				( __UpperCAmelCase		:      str     ,     __UpperCAmelCase		:      int				)   ->					list:
      SCREAMING_SNAKE_CASE_      		=     word.split()

      def justify(__UpperCAmelCase		:      list     ,     __UpperCAmelCase		:      int     ,     __UpperCAmelCase		:      int				) -> str:
            SCREAMING_SNAKE_CASE_      		=     max_width - width
            SCREAMING_SNAKE_CASE_      		=     len(__UpperCAmelCase				)
            if len(__UpperCAmelCase				) == 1:
                  # if there is only word in line
                  # just insert overall_spaces_count for the remainder of line
                  return line[0] + " " * overall_spaces_count
            else:
                  SCREAMING_SNAKE_CASE_      		=     words_count - 1
                  # num_spaces_between_words_list[i] : tells you to insert
                  # num_spaces_between_words_list[i] spaces
                  # after word on line[i]
                  SCREAMING_SNAKE_CASE_      		=     spaces_to_insert_between_words * [
                      overall_spaces_count // spaces_to_insert_between_words
                  ]
                  SCREAMING_SNAKE_CASE_      		=     (
                      overall_spaces_count % spaces_to_insert_between_words
                  )
                  # distribute spaces via round robin to the left words
                  for i in range(__UpperCAmelCase				):
                        num_spaces_between_words_list[i] += 1
                  SCREAMING_SNAKE_CASE_      		=     []
                  for i in range(__UpperCAmelCase				):
                        # add the word
                        aligned_words_list.append(line[i]				)
                        # add the spaces to insert
                        aligned_words_list.append(num_spaces_between_words_list[i] * ' '				)
                  # just add the last word to the sentence
                  aligned_words_list.append(line[-1]				)
                  # join the aligned words list to form a justified line
                  return "".join(__UpperCAmelCase				)

      SCREAMING_SNAKE_CASE_      		=     []
      SCREAMING_SNAKE_CASE_      		=     []
      SCREAMING_SNAKE_CASE_      		=     0
      for word in words:
            if width + len(__UpperCAmelCase				) + len(__UpperCAmelCase				) <= max_width:
                  # keep adding words until we can fill out max_width
                  # width = sum of length of all words (without overall_spaces_count)
                  # len(word) = length of current word
                  # len(line) = number of overall_spaces_count to insert between words
                  line.append(__UpperCAmelCase				)
                  width += len(__UpperCAmelCase				)
            else:
                  # justify the line and add it to result
                  answer.append(justify(__UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase				)				)
                  # reset new line and new width
                  SCREAMING_SNAKE_CASE_		,					SCREAMING_SNAKE_CASE_      		=     [word], len(__UpperCAmelCase				)
      SCREAMING_SNAKE_CASE_      		=     max_width - width - len(__UpperCAmelCase				)
      answer.append(' '.join(__UpperCAmelCase				) + (remaining_spaces + 1) * ' '				)
      return answer


if __name__ == "__main__":
   from doctest import testmod

   testmod()





from __future__ import annotations

from typing import TypedDict





class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE   ):


 '''simple docstring'''







 lowercase_							       =       42
 lowercase_							       =       42


def    UpperCAmelCase_				( __UpperCAmelCase		:      str				)   ->					list[str]:
      if not isinstance(__UpperCAmelCase     ,     __UpperCAmelCase				):
            raise TypeError('The parameter s type must be str.'				)

      return [s[i:] + s[:i] for i in range(len(__UpperCAmelCase				)				)]

def    UpperCAmelCase_				( __UpperCAmelCase		:      str				)   ->					BWTTransformDict:
      if not isinstance(__UpperCAmelCase     ,     __UpperCAmelCase				):
            raise TypeError('The parameter s type must be str.'				)
      if not s:
            raise ValueError('The parameter s must not be empty.'				)

      SCREAMING_SNAKE_CASE_      		=     all_rotations(__UpperCAmelCase				)
      rotations.sort()  # sort the list of rotations in alphabetically order
      # make a string composed of the last char of each rotation
      SCREAMING_SNAKE_CASE_      		=     {
          "bwt_string": "".join([word[-1] for word in rotations]				),
          "idx_original_string": rotations.index(__UpperCAmelCase				),
      }
      return response

def    UpperCAmelCase_				( __UpperCAmelCase		:      str     ,     __UpperCAmelCase		:      int				)   ->					str:
      if not isinstance(__UpperCAmelCase     ,     __UpperCAmelCase				):
            raise TypeError('The parameter bwt_string type must be str.'				)
      if not bwt_string:
            raise ValueError('The parameter bwt_string must not be empty.'				)
      try:
            SCREAMING_SNAKE_CASE_      		=     int(__UpperCAmelCase				)
      except ValueError:
            raise TypeError(
                'The parameter idx_original_string type must be int or passive'
                ' of cast to int.'				)
      if idx_original_string < 0:
            raise ValueError('The parameter idx_original_string must not be lower than 0.'				)
      if idx_original_string >= len(__UpperCAmelCase				):
            raise ValueError(
                'The parameter idx_original_string must be lower than' ' len(bwt_string).'				)

      SCREAMING_SNAKE_CASE_      		=     [''] * len(__UpperCAmelCase				)
      for _ in range(len(__UpperCAmelCase				)				):
            for i in range(len(__UpperCAmelCase				)				):
                  SCREAMING_SNAKE_CASE_      		=     bwt_string[i] + ordered_rotations[i]
            ordered_rotations.sort()
      return ordered_rotations[idx_original_string]


if __name__ == "__main__":
   lowerCamelCase__					:  Optional[int]      							=				'Provide a string that I will generate its BWT transform: '
   lowerCamelCase__					:  List[str]      							=				input(entry_msg).strip()
   lowerCamelCase__					:  int      							=				bwt_transform(s)
   print(
       f'''Burrows Wheeler transform for string \'{s}\' results '''
       f'''in \'{result['bwt_string']}\''''
   )
   lowerCamelCase__					:  Dict      							=				reverse_bwt(result['bwt_string'], result['idx_original_string'])
   print(
       f'''Reversing Burrows Wheeler transform for entry \'{result['bwt_string']}\' '''
       f'''we get original string \'{original_string}\''''
   )