"""simple docstring"""
from typing import Any




class        __snake_case	:



      def __init__(						self   ,      lowercase)     ->      List[Any]:





        '''simple docstring'''





        a__:					Tuple      							=     data
        a__:					Optional[int]      							=     None



      def __repr__(						self)     ->      str:





        '''simple docstring'''





        return f'Node({self.data})'







class        __snake_case	:



      def __init__(						self)     ->      List[str]:





        '''simple docstring'''





        a__:					List[Any]      							=     None



      def __iter__(						self)     ->      Any:





        '''simple docstring'''





        a__:					Any      							=     self.head
        while node:
          yield node.data
          a__:					Optional[Any]      							=     node.next



      def __len__(						self)     ->      int:





        '''simple docstring'''





        return sum(1 for _ in self)



      def __repr__(						self)     ->      str:





        '''simple docstring'''





        return "->".join([str(lowercase) for item in self])



      def __getitem__(						self   ,      lowercase)     ->      Any:





        '''simple docstring'''





        if not 0 <= index < len(self):
          raise ValueError('list index out of range.')
        for i, node in enumerate(self):
          if i == index:
            return node
        return None



      def __setitem__(						self   ,      lowercase   ,      lowercase)     ->      None:





        '''simple docstring'''





        if not 0 <= index < len(self):
          raise ValueError('list index out of range.')
        a__:					Union[str, Any]      							=     self.head
        for _ in range(lowercase):
          a__:					Optional[int]      							=     current.next
        a__:					int      							=     data



      def   lowerCamelCase_       (						self   ,      lowercase)     ->      None:





        '''simple docstring'''





        self.insert_nth(len(self)   ,      lowercase)



      def   lowerCamelCase_       (						self   ,      lowercase)     ->      None:





        '''simple docstring'''





        self.insert_nth(0   ,      lowercase)



      def   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase)     ->      None:





        '''simple docstring'''





        if not 0 <= index <= len(self):
          raise IndexError('list index out of range')
        a__:					Optional[int]      							=     Node(lowercase)
        if self.head is None:
          a__:					str      							=     new_node
        elif index == 0:
          a__:					Dict      							=     self.head  # link new_node to head
          a__:					Union[str, Any]      							=     new_node
        else:
          a__:					Dict      							=     self.head
          for _ in range(index - 1):
            a__:					str      							=     temp.next
          a__:					Tuple      							=     temp.next
          a__:					Optional[int]      							=     new_node



      def   lowerCamelCase_       (						self)     ->      None:  # print every node data





        '''simple docstring'''





        print(self)



      def   lowerCamelCase_       (						self)     ->      Any:





        '''simple docstring'''





        return self.delete_nth(0)



      def   lowerCamelCase_       (						self)     ->      Any:  # delete from tail





        '''simple docstring'''





        return self.delete_nth(len(self) - 1)



      def   lowerCamelCase_       (						self   ,      lowercase = 0)     ->      Any:





        '''simple docstring'''





        if not 0 <= index <= len(self) - 1:  # test if index is valid
          raise IndexError('List index out of range.')
        a__:					str      							=     self.head  # default first node
        if index == 0:
          a__:					Optional[Any]      							=     self.head.next
        else:
          a__:					Optional[Any]      							=     self.head
          for _ in range(index - 1):
            a__:					int      							=     temp.next
          a__:					Union[str, Any]      							=     temp.next
          a__:					Optional[int]      							=     temp.next.next
        return delete_node.data



      def   lowerCamelCase_       (						self)     ->      bool:





        '''simple docstring'''





        return self.head is None



      def   lowerCamelCase_       (						self)     ->      None:





        '''simple docstring'''





        a__:					Optional[int]      							=     None
        a__:					List[Any]      							=     self.head

        while current:
          # Store the current node's next node.
          a__:					Tuple      							=     current.next
          # Make the current node's next point backwards
          a__:					Union[str, Any]      							=     prev
          # Make the previous node be the current node
          a__:					Any      							=     current
          # Make the current node the next node (to progress iteration)
          a__:					List[str]      							=     next_node
        # Return prev in order to put the head at the end
        a__:					Any      							=     prev







def 						__a       (     )     ->None:
  a__:					Optional[int]      							=     LinkedList()
  assert linked_list.is_empty() is True
  assert str(_SCREAMING_SNAKE_CASE       ) == ""

  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(_SCREAMING_SNAKE_CASE       ) == i
    linked_list.insert_nth(_SCREAMING_SNAKE_CASE		,					i + 1       )
  assert str(_SCREAMING_SNAKE_CASE       ) == "->".join(str(_SCREAMING_SNAKE_CASE       ) for i in range(1		,					11       )       )

  linked_list.insert_head(0       )
  linked_list.insert_tail(11       )
  assert str(_SCREAMING_SNAKE_CASE       ) == "->".join(str(_SCREAMING_SNAKE_CASE       ) for i in range(0		,					12       )       )

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

  assert all(linked_list[i] == i + 1 for i in range(0		,					9       )       ) is True

  for i in range(0		,					9       ):
    a__:					Dict      							=     -i
  assert all(linked_list[i] == -i for i in range(0		,					9       )       ) is True

  linked_list.reverse()
  assert str(_SCREAMING_SNAKE_CASE       ) == "->".join(str(_SCREAMING_SNAKE_CASE       ) for i in range(-8		,					1       )       )







def 						__a       (     )     ->None:
  a__:					int      							=     [
      -9,
      100,
      Node(77345112       ),
      'dlrow olleH',
      7,
      5555,
      0,
      -192.55_555,
      'Hello, world!',
      77.9,
      Node(10       ),
      None,
      None,
      12.20,
  ]
  a__:					List[Any]      							=     LinkedList()

  for i in test_input:
    linked_list.insert_tail(_SCREAMING_SNAKE_CASE       )

  # Check if it's empty or not
  assert linked_list.is_empty() is False
  assert (
      str(_SCREAMING_SNAKE_CASE       ) == "-9->100->Node(77345112)->dlrow olleH->7->5555->0->"
      "-192.55555->Hello, world!->77.9->Node(10)->None->None->12.2"
  )

  # Delete the head
  a__:					Union[str, Any]      							=     linked_list.delete_head()
  assert result == -9
  assert (
      str(_SCREAMING_SNAKE_CASE       ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
      "Hello, world!->77.9->Node(10)->None->None->12.2"
  )

  # Delete the tail
  a__:					List[str]      							=     linked_list.delete_tail()
  assert result == 12.2
  assert (
      str(_SCREAMING_SNAKE_CASE       ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
      "Hello, world!->77.9->Node(10)->None->None"
  )

  # Delete a node in specific location in linked list
  a__:					Optional[Any]      							=     linked_list.delete_nth(10       )
  assert result is None
  assert (
      str(_SCREAMING_SNAKE_CASE       ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
      "Hello, world!->77.9->Node(10)->None"
  )

  # Add a Node instance to its head
  linked_list.insert_head(Node('Hello again, world!'       )       )
  assert (
      str(_SCREAMING_SNAKE_CASE       )
      == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
      "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None"
  )

  # Add None to its tail
  linked_list.insert_tail(_SCREAMING_SNAKE_CASE       )
  assert (
      str(_SCREAMING_SNAKE_CASE       )
      == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
      "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None->None"
  )

  # Reverse the linked list
  linked_list.reverse()
  assert (
      str(_SCREAMING_SNAKE_CASE       )
      == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
      "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
  )







def 						__a       (     )     ->Union[str, Any]:
  from doctest import testmod

  testmod()

  a__:					Dict      							=     LinkedList()
  linked_list.insert_head(input('Inserting 1st at head '       ).strip()       )
  linked_list.insert_head(input('Inserting 2nd at head '       ).strip()       )
  print('\nPrint list:'       )
  linked_list.print_list()
  linked_list.insert_tail(input('\nInserting 1st at tail '       ).strip()       )
  linked_list.insert_tail(input('Inserting 2nd at tail '       ).strip()       )
  print('\nPrint list:'       )
  linked_list.print_list()
  print('\nDelete head'       )
  linked_list.delete_head()
  print('Delete tail'       )
  linked_list.delete_tail()
  print('\nPrint list:'       )
  linked_list.print_list()
  print('\nReverse linked list'       )
  linked_list.reverse()
  print('\nPrint list:'       )
  linked_list.print_list()
  print('\nString representation of linked list:'       )
  print(_SCREAMING_SNAKE_CASE       )
  print('\nReading/changing Node data using indexing:'       )
  print(F'Element at Position 1: {linked_list[1]}'       )
  a__:					Any      							=     input('Enter New Value: '       ).strip()
  print('New list:'       )
  print(_SCREAMING_SNAKE_CASE       )
  print(F'length of linked_list is : {len(_SCREAMING_SNAKE_CASE       )}'       )


if __name__ == "__main__":
 main()



"""simple docstring"""
def 						__a       (     _SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )     ->Tuple:
  _enforce_args(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )
  if n == 0:
    return 0
  a__:					List[Any]      							=     float('-inf'       )
  for i in range(1		,					n + 1       ):
    a__:					Optional[Any]      							=     max(
        _SCREAMING_SNAKE_CASE		,					prices[i - 1] + naive_cut_rod_recursive(n - i		,					_SCREAMING_SNAKE_CASE       )       )

  return max_revue







def 						__a       (     _SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )     ->str:
  _enforce_args(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )
  a__:					str      							=     [float('-inf'       ) for _ in range(n + 1       )]
  return _top_down_cut_rod_recursive(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )







def 						__a       (     _SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )     ->Optional[Any]:
  if max_rev[n] >= 0:
    return max_rev[n]
  elif n == 0:
    return 0
  else:
    a__:					Dict      							=     float('-inf'       )
    for i in range(1		,					n + 1       ):
      a__:					Optional[Any]      							=     max(
          _SCREAMING_SNAKE_CASE		,					prices[i - 1] + _top_down_cut_rod_recursive(n - i		,					_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )		,					)

    a__:					Optional[int]      							=     max_revenue

  return max_rev[n]







def 						__a       (     _SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )     ->Dict:
  _enforce_args(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )

  # length(max_rev) = n + 1, to accommodate for the revenue obtainable from a rod of
  # length 0.
  a__:					str      							=     [float('-inf'       ) for _ in range(n + 1       )]
  a__:					Tuple      							=     0

  for i in range(1		,					n + 1       ):
    a__:					List[str]      							=     max_rev[i]
    for j in range(1		,					i + 1       ):
      a__:					Tuple      							=     max(_SCREAMING_SNAKE_CASE		,					prices[j - 1] + max_rev[i - j]       )

    a__:					Union[str, Any]      							=     max_revenue_i

  return max_rev[n]







def 						__a       (     _SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )     ->Any:
  if n < 0:
    a__:					Optional[int]      							=     F'n must be greater than or equal to 0. Got n = {n}'
    raise ValueError(_SCREAMING_SNAKE_CASE       )

  if n > len(_SCREAMING_SNAKE_CASE       ):
    a__:					List[str]      							=     (
        'Each integral piece of rod must have a corresponding price. '
        F'Got n = {n} but length of prices = {len(_SCREAMING_SNAKE_CASE       )}'
    )
    raise ValueError(_SCREAMING_SNAKE_CASE       )







def 						__a       (     )     ->str:
  a__:					int      							=     [6, 10, 12, 15, 20, 23]
  a__:					Union[str, Any]      							=     len(_SCREAMING_SNAKE_CASE       )

  # the best revenue comes from cutting the rod into 6 pieces, each
  # of length 1 resulting in a revenue of 6 * 6 = 36.
  a__:					Any      							=     36

  a__:					Optional[int]      							=     top_down_cut_rod(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )
  a__:					List[Any]      							=     bottom_up_cut_rod(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )
  a__:					int      							=     naive_cut_rod_recursive(_SCREAMING_SNAKE_CASE		,					_SCREAMING_SNAKE_CASE       )

  assert expected_max_revenue == max_rev_top_down
  assert max_rev_top_down == max_rev_bottom_up
  assert max_rev_bottom_up == max_rev_naive


if __name__ == "__main__":
 main()


