
"""simple docstring"""





class A_      :




  '''simple docstring'''







  def __init__(						self							,  lowercase_    ):

     """simple docstring"""
     UpperCAmelCase_   :   str     	=       data
     UpperCAmelCase_   :   str     	=       None
     UpperCAmelCase_   :   List[Any]     	=       None







  def __str__(						self    ):

     """simple docstring"""
     return F"""{self.data}"""




class A_      :




  '''simple docstring'''







  def __init__(						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Tuple     	=       None
     UpperCAmelCase_   :   List[str]     	=       None







  def __iter__(						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Optional[int]     	=       self.head
     while node:
        yield node.data
        UpperCAmelCase_   :   Optional[Any]     	=       node.next







  def __str__(						self    ):

     """simple docstring"""
     return "->".join([str(lowercase_    ) for item in self]    )







  def __len__(						self    ):

     """simple docstring"""
     return sum(1 for _ in self    )







  def 			UpperCamelCase__   (						self							,  lowercase_    ):

     """simple docstring"""
     self.insert_at_nth(0							,  lowercase_    )







  def 			UpperCamelCase__   (						self							,  lowercase_    ):

     """simple docstring"""
     self.insert_at_nth(len(self    )							,  lowercase_    )







  def 			UpperCamelCase__   (						self							,  lowercase_							,  lowercase_    ):

     """simple docstring"""
     UpperCAmelCase_   :   int     	=       len(self    )

     if not 0 <= index <= length:
        raise IndexError("list index out of range"    )
     UpperCAmelCase_   :   Tuple     	=       Node(lowercase_    )
     if self.head is None:
        UpperCAmelCase_   :   List[str]     	=       new_node
     elif index == 0:
        UpperCAmelCase_   :   int     	=       new_node
        UpperCAmelCase_   :   Optional[Any]     	=       self.head
        UpperCAmelCase_   :   Optional[int]     	=       new_node
     elif index == length:
        UpperCAmelCase_   :   Union[str, Any]     	=       new_node
        UpperCAmelCase_   :   Optional[Any]     	=       self.tail
        UpperCAmelCase_   :   Tuple     	=       new_node
     else:
        UpperCAmelCase_   :   Dict     	=       self.head
        for _ in range(0							,  lowercase_    ):
           UpperCAmelCase_   :   str     	=       temp.next
        UpperCAmelCase_   :   int     	=       new_node
        UpperCAmelCase_   :   Tuple     	=       temp.previous
        UpperCAmelCase_   :   Union[str, Any]     	=       temp
        UpperCAmelCase_   :   int     	=       new_node







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return self.delete_at_nth(0    )







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return self.delete_at_nth(len(self    ) - 1    )







  def 			UpperCamelCase__   (						self							,  lowercase_    ):

     """simple docstring"""
     UpperCAmelCase_   :   int     	=       len(self    )

     if not 0 <= index <= length - 1:
        raise IndexError("list index out of range"    )
     UpperCAmelCase_   :   Optional[int]     	=       self.head  # default first node
     if length == 1:
        UpperCAmelCase_   :   Union[str, Any]     	=       None
     elif index == 0:
        UpperCAmelCase_   :   List[Any]     	=       self.head.next
        UpperCAmelCase_   :   str     	=       None
     elif index == length - 1:
        UpperCAmelCase_   :   str     	=       self.tail
        UpperCAmelCase_   :   Optional[Any]     	=       self.tail.previous
        UpperCAmelCase_   :   Any     	=       None
     else:
        UpperCAmelCase_   :   List[Any]     	=       self.head
        for _ in range(0							,  lowercase_    ):
           UpperCAmelCase_   :   str     	=       temp.next
        UpperCAmelCase_   :   Dict     	=       temp
        UpperCAmelCase_   :   Optional[Any]     	=       temp.previous
        UpperCAmelCase_   :   int     	=       temp.next
     return delete_node.data







  def 			UpperCamelCase__   (						self							,  lowercase_    ):

     """simple docstring"""
     UpperCAmelCase_   :   Tuple     	=       self.head

     while current.data != data:  # Find the position to delete
        if current.next:
           UpperCAmelCase_   :   List[str]     	=       current.next
        else:  # We have reached the end an no value matches
           raise ValueError("No data matching given value"    )

     if current == self.head:
        self.delete_head()

     elif current == self.tail:
        self.delete_tail()

     else:  # Before: 1 <--> 2(current) <--> 3
        UpperCAmelCase_   :   str     	=       current.next  # 1 --> 3
        UpperCAmelCase_   :   Optional[Any]     	=       current.previous  # 1 <--> 3
     return data







  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return len(self    ) == 0







def       __a	(						):
   UpperCAmelCase_   :   Dict     	=       DoublyLinkedList()
   assert linked_list.is_empty() is True
   assert str(__lowerCamelCase    ) == ""

   try:
      linked_list.delete_head()
      raise AssertionError  # This should not happen.
   except IndexError:
      assert True  # This should happen.

   try:
      linked_list.delete_tail()
      raise AssertionError  # This should not happen.
   except IndexError:
      assert True  # This should happen.

   for i in range(10    ):
      assert len(__lowerCamelCase    ) == i
      linked_list.insert_at_nth(__lowerCamelCase,						i + 1    )
   assert str(__lowerCamelCase    ) == "->".join(str(__lowerCamelCase    ) for i in range(1,						11    )    )

   linked_list.insert_at_head(0    )
   linked_list.insert_at_tail(11    )
   assert str(__lowerCamelCase    ) == "->".join(str(__lowerCamelCase    ) for i in range(0,						12    )    )

   assert linked_list.delete_head() == 0
   assert linked_list.delete_at_nth(9    ) == 10
   assert linked_list.delete_tail() == 11
   assert len(__lowerCamelCase    ) == 9
   assert str(__lowerCamelCase    ) == "->".join(str(__lowerCamelCase    ) for i in range(1,						10    )    )


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

    testmod()






"""simple docstring"""






def    A_ ( _lowerCAmelCase  :       list[list[int]]							):






     """simple docstring"""

     _a     						=					[list(_lowerCAmelCase							) for row in matrix]
     if matrix and isinstance(_lowerCAmelCase,  _lowerCAmelCase							):
          if isinstance(matrix[0],  _lowerCAmelCase							):
               _a     						=					0
               for row in matrix:
                    if prev_len == 0:
                         _a     						=					len(_lowerCAmelCase							)
                         _a     						=					True
                    else:
                         _a     						=					prev_len == len(_lowerCAmelCase							)
          else:
               _a     						=					True
     else:
          _a     						=					False

     return result
def    A_ ( _lowerCAmelCase  :       list[list[int]]							):






     """simple docstring"""

     if check_matrix(_lowerCAmelCase							) and len(_lowerCAmelCase							) > 0:
          _a     						=					[list(_lowerCAmelCase							) for row in a]
          _a     						=					len(_lowerCAmelCase							)
          if isinstance(a[0],  _lowerCAmelCase							):
               _a     						=					len(a[0]							)
          else:
               for dat in a:
                    print(_lowerCAmelCase							)
               return

          # horizotal printing increasing
          for i in range(0,  _lowerCAmelCase							):
               print(a[0][i]							)
          # vertical printing down
          for i in range(1,  _lowerCAmelCase							):
               print(a[i][mat_col - 1]							)
          # horizotal printing decreasing
          if mat_row > 1:
               for i in range(mat_col - 2,  -1,  -1							):
                    print(a[mat_row - 1][i]							)
        # vertical printing up
          for i in range(mat_row - 2,  0,  -1							):
               print(a[i][0]							)
          _a     						=					[row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
          if len(_lowerCAmelCase							) > 0:
               spiral_print_clockwise(_lowerCAmelCase							)
          else:
               return
     else:
          print('''Not a valid matrix'''							)
          return
def    A_ ( _lowerCAmelCase  :       list[list]							):






     """simple docstring"""

     if matrix:
          return list(matrix.pop(0							)							) + spiral_traversal(list(zip(*_lowerCAmelCase							)							)[::-1]							)
     else:
          return []


# driver code
if __name__ == "__main__":
   import doctest

   doctest.testmod()

   __snake_case												=							[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
   spiral_print_clockwise(a)