




def      __lowerCAmelCase			(					UpperCamelCase      )     ->	int:
  if not head:
    return True
  # split the list to two parts
  lowerCAmelCase__				:  Dict		       =     head.next, head
  while fast and fast.next:
    lowerCAmelCase__				:  Union[str, Any]		       =     fast.next.next
    lowerCAmelCase__				:  Dict		       =     slow.next
  lowerCAmelCase__				:  Optional[Any]		       =     slow.next
  lowerCAmelCase__				:  str		       =     None  # Don't forget here! But forget still works!
  # reverse the second part
  lowerCAmelCase__				:  Optional[Any]		       =     None
  while second:
    lowerCAmelCase__				:  Dict		       =     second.next
    lowerCAmelCase__				:  List[str]		       =     node
    lowerCAmelCase__				:  List[Any]		       =     second
    lowerCAmelCase__				:  int		       =     nxt
  # compare two parts
  # second part has the same or one less node
  while node:
    if node.val != head.val:
      return False
    lowerCAmelCase__				:  List[str]		       =     node.next
    lowerCAmelCase__				:  str		       =     head.next
  return True



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	Dict:
  if not head or not head.next:
    return True

  # 1. Get the midpoint (slow)
  lowerCAmelCase__				:  Optional[int]		       =     head
  while fast and fast.next:
    lowerCAmelCase__				:  Optional[Any]		       =     fast.next.next, slow.next

  # 2. Push the second half into the stack
  lowerCAmelCase__				:  Optional[int]		       =     [slow.val]
  while slow.next:
    lowerCAmelCase__				:  int		       =     slow.next
    stack.append(slow.val      )

  # 3. Comparison
  while stack:
    if stack.pop() != cur.val:
      return False
    lowerCAmelCase__				:  Union[str, Any]		       =     cur.next

  return True



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	Any:
  if not head or not head.next:
    return True
  lowerCAmelCase__				:  List[Any]		       =     {}
  lowerCAmelCase__				:  Any		       =     0
  while head:
    if head.val in d:
      d[head.val].append(_lowerCAmelCase      )
    else:
      lowerCAmelCase__				:  Optional[int]		       =     [pos]
    lowerCAmelCase__				:  Optional[int]		       =     head.next
    pos += 1
  lowerCAmelCase__				:  Any		       =     pos - 1
  lowerCAmelCase__				:  Dict		       =     0
  for v in d.values():
    if len(_lowerCAmelCase      ) % 2 != 0:
      middle += 1
    else:
      lowerCAmelCase__				:  str		       =     0
      for i in range(0	,      len(_lowerCAmelCase      )      ):
        if v[i] + v[len(_lowerCAmelCase      ) - 1 - step] != checksum:
          return False
        step += 1
    if middle > 1:
      return False
  return True







from __future__ import annotations



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	list[int]:  # This function is recursive
  lowerCAmelCase__				:  Tuple		       =     len(UpperCamelCase      )
  # If the array contains only one element, we return it (it's the stop condition of
  # recursion)
  if array_length <= 1:
    return array
    # Else
  lowerCAmelCase__				:  Optional[int]		       =     array[0]
  lowerCAmelCase__				:  Union[str, Any]		       =     False
  lowerCAmelCase__				:  List[str]		       =     1
  lowerCAmelCase__				:  list[int]		       =     []
  while not is_found and i < array_length:
    if array[i] < pivot:
      lowerCAmelCase__				:  List[Any]		       =     True
      lowerCAmelCase__				:  Optional[int]		       =     [element for element in array[i:] if element >= array[i]]
      lowerCAmelCase__				:  Any		       =     longest_subsequence(UpperCamelCase      )
      if len(UpperCamelCase      ) > len(UpperCamelCase      ):
        lowerCAmelCase__				:  Optional[int]		       =     temp_array
    else:
      i += 1

  lowerCAmelCase__				:  Optional[Any]		       =     [element for element in array[1:] if element >= pivot]
  lowerCAmelCase__				:  List[Any]		       =     [pivot, *longest_subsequence(UpperCamelCase      )]
  if len(UpperCamelCase      ) > len(UpperCamelCase      ):
    return temp_array
  else:
    return longest_subseq


if __name__ == "__main__":
     import doctest

     doctest.testmod()

