def    a__       (						__UpperCamelCase ):
      SCREAMING_SNAKE_CASE_      =     len(__UpperCamelCase )
      SCREAMING_SNAKE_CASE_      =     len(matrix[0] )
      SCREAMING_SNAKE_CASE_      =     min(__UpperCamelCase   ,					__UpperCamelCase )

      for row in range(__UpperCamelCase ):
            # Check if diagonal element is not zero
            if matrix[row][row] != 0:
                  # Eliminate all the elements below the diagonal
                  for col in range(row + 1   ,					__UpperCamelCase ):
                        SCREAMING_SNAKE_CASE_      =     matrix[col][row] / matrix[row][row]
                        for i in range(__UpperCamelCase   ,					__UpperCamelCase ):
                              matrix[col][i] -= multiplier * matrix[row][i]
            else:
                  # Find a non-zero diagonal element to swap rows
                  SCREAMING_SNAKE_CASE_      =     True
                  for i in range(row + 1   ,					__UpperCamelCase ):
                        if matrix[i][row] != 0:
                              SCREAMING_SNAKE_CASE_   ,       SCREAMING_SNAKE_CASE_      =     matrix[i], matrix[row]
                              SCREAMING_SNAKE_CASE_      =     False
                              break
                  if reduce:
                        rank -= 1
                        for i in range(__UpperCamelCase ):
                              SCREAMING_SNAKE_CASE_      =     matrix[i][rank]

            # Reduce the row pointer by one to stay on the same row
                  row -= 1

      return rank


if __name__ == "__main__":
      import doctest

      doctest.testmod()



def    a__       (						__UpperCamelCase ):
      if not head:
            return True
      # split the list to two parts
      SCREAMING_SNAKE_CASE_   ,       SCREAMING_SNAKE_CASE_      =     head.next, head
      while fast and fast.next:
            SCREAMING_SNAKE_CASE_      =     fast.next.next
            SCREAMING_SNAKE_CASE_      =     slow.next
      SCREAMING_SNAKE_CASE_      =     slow.next
      SCREAMING_SNAKE_CASE_      =     None  # Don't forget here! But forget still works!
      # reverse the second part
      SCREAMING_SNAKE_CASE_      =     None
      while second:
            SCREAMING_SNAKE_CASE_      =     second.next
            SCREAMING_SNAKE_CASE_      =     node
            SCREAMING_SNAKE_CASE_      =     second
            SCREAMING_SNAKE_CASE_      =     nxt
      # compare two parts
      # second part has the same or one less node
      while node:
            if node.val != head.val:
                  return False
            SCREAMING_SNAKE_CASE_      =     node.next
            SCREAMING_SNAKE_CASE_      =     head.next
      return True


def    a__       (						__UpperCamelCase ):
      if not head or not head.next:
            return True

      # 1. Get the midpoint (slow)
      SCREAMING_SNAKE_CASE_      =     SCREAMING_SNAKE_CASE_      =     SCREAMING_SNAKE_CASE_      =     head
      while fast and fast.next:
            SCREAMING_SNAKE_CASE_   ,       SCREAMING_SNAKE_CASE_      =     fast.next.next, slow.next

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

      # 3. Comparison
      while stack:
            if stack.pop() != cur.val:
                  return False
            SCREAMING_SNAKE_CASE_      =     cur.next

      return True





def    a__       (						__UpperCamelCase ):
      if not head or not head.next:
            return True
      SCREAMING_SNAKE_CASE_      =     {}
      SCREAMING_SNAKE_CASE_      =     0
      while head:
            if head.val in d:
                  d[head.val].append(__UpperCamelCase )
            else:
                  SCREAMING_SNAKE_CASE_      =     [pos]
            SCREAMING_SNAKE_CASE_      =     head.next
            pos += 1
      SCREAMING_SNAKE_CASE_      =     pos - 1
      SCREAMING_SNAKE_CASE_      =     0
      for v in d.values():
            if len(__UpperCamelCase ) % 2 != 0:
                  middle += 1
            else:
                  SCREAMING_SNAKE_CASE_      =     0
                  for i in range(0   ,					len(__UpperCamelCase ) ):
                        if v[i] + v[len(__UpperCamelCase ) - 1 - step] != checksum:
                              return False
                        step += 1
            if middle > 1:
                  return False
      return True


