'''simple docstring'''






def    __UpperCAmelCase			(  a_:       str							):
   _UpperCAmelCase							:	Optional[Any]							=   0
   _UpperCAmelCase							:	List[Any]							=   len(snake_case_							)

   for i in range(n - 1							):
      for j in range(i + 1,					snake_case_							):
         if arr[i] > arr[j]:
            num_inversions += 1

   return num_inversions






def    __UpperCAmelCase			(  a_:       str							):




   if len(snake_case_							) <= 1:
      return arr, 0
   _UpperCAmelCase							:	str							=   len(snake_case_							) // 2
   _UpperCAmelCase							:	Dict							=   arr[0:mid]
   _UpperCAmelCase							:	Dict							=   arr[mid:]

   _UpperCAmelCase							,       _UpperCAmelCase							:	str							=   count_inversions_recursive(snake_case_							)
   _UpperCAmelCase							,       _UpperCAmelCase							:	Union[str, Any]							=   count_inversions_recursive(snake_case_							)
   _UpperCAmelCase							,       _UpperCAmelCase							:	Tuple							=   _count_cross_inversions(snake_case_,					snake_case_							)

   _UpperCAmelCase							:	int							=   inversion_p + inversions_q + cross_inversions
   return c, num_inversions






def    __UpperCAmelCase			(  a_:       Any,					a_:       Tuple							):
   _UpperCAmelCase							:	int							=   []
   _UpperCAmelCase							:	Tuple							=   0
   while i < len(snake_case_							) and j < len(snake_case_							):
      if p[i] > q[j]:
         # if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
         # These are all inversions. The claim emerges from the
         # property that P is sorted.
         num_inversion += len(snake_case_							) - i
         r.append(q[j]							)
         j += 1
      else:
         r.append(p[i]							)
         i += 1

   if i < len(snake_case_							):
      r.extend(p[i:]							)
   else:
      r.extend(q[j:]							)

   return r, num_inversion






def    __UpperCAmelCase			(  ):
   _UpperCAmelCase							:	Optional[int]							=   [10, 2, 1, 5, 5, 2, 11]

   # this arr has 8 inversions:
   # (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

   _UpperCAmelCase							:	Tuple							=   count_inversions_bf(snake_case_							)
   _UpperCAmelCase							,       _UpperCAmelCase							:	List[str]							=   count_inversions_recursive(snake_case_							)

   assert num_inversions_bf == num_inversions_recursive == 8

   print("number of inversions = ",					snake_case_							)

   # testing an array with zero inversion (a sorted arr_1)

   arr_a.sort()
   _UpperCAmelCase							:	int							=   count_inversions_bf(snake_case_							)
   _UpperCAmelCase							,       _UpperCAmelCase							:	Dict							=   count_inversions_recursive(snake_case_							)

   assert num_inversions_bf == num_inversions_recursive == 0
   print("number of inversions = ",					snake_case_							)

   # an empty list should also have zero inversions
   _UpperCAmelCase							:	Optional[Any]							=   []
   _UpperCAmelCase							:	List[Any]							=   count_inversions_bf(snake_case_							)
   _UpperCAmelCase							,       _UpperCAmelCase							:	Dict							=   count_inversions_recursive(snake_case_							)

   assert num_inversions_bf == num_inversions_recursive == 0
   print("number of inversions = ",					snake_case_							)


if __name__ == "__main__":
     main()
'''simple docstring'''





import math





def 	lowerCAmelCase_				(					)    ->      None:


     '''simple docstring'''




     UpperCAmelCase_           =   input("Enter message: "			)
     UpperCAmelCase_           =   int(input(f"""Enter key [2-{len(snake_case_			) - 1}]: """			)			)
     UpperCAmelCase_           =   input("Encryption/Decryption [e/d]: "			)

     if mode.lower().startswith("e"			):
          UpperCAmelCase_           =   encrypt_message(snake_case_					,    snake_case_			)
     elif mode.lower().startswith("d"			):
          UpperCAmelCase_           =   decrypt_message(snake_case_					,    snake_case_			)

     # Append pipe symbol (vertical bar) to identify spaces at the end.
     print(f"""Output:\n{text + "|"}"""			)





def 	lowerCAmelCase_				(					snake_case_       : int					,    snake_case_       : str			)    ->      str:


     '''simple docstring'''




     UpperCAmelCase_           =   [""] * key
     for col in range(snake_case_			):
          UpperCAmelCase_           =   col
          while pointer < len(snake_case_			):
               cipher_text[col] += message[pointer]
               pointer += key
     return "".join(snake_case_			)





def 	lowerCAmelCase_				(					snake_case_       : int					,    snake_case_       : str			)    ->      str:


     '''simple docstring'''




     UpperCAmelCase_           =   math.ceil(len(snake_case_			) / key			)
     UpperCAmelCase_           =   key
     UpperCAmelCase_           =   (num_cols * num_rows) - len(snake_case_			)
     UpperCAmelCase_           =   [""] * num_cols
     UpperCAmelCase_           =   0
     UpperCAmelCase_           =   0

     for symbol in message:
          plain_text[col] += symbol
          col += 1

          if (
              (col == num_cols)
              or (col == num_cols - 1)
              and (row >= num_rows - num_shaded_boxes)
          ):
               UpperCAmelCase_           =   0
               row += 1

     return "".join(snake_case_			)


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    main()




