class ListNode:
    def __init__(self, value=0, next=None):
        self.value = value
        self.next = next

def is_palindrome(head: ListNode) -> bool:
    if not head or not head.next:
        return True

    # Step 1: Find the middle of the linked list
    slow = fast = head
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
    
    # Step 2: Reverse the second half of the linked list
    prev = None
    while slow:
        next_node = slow.next
        slow.next = prev
        prev = slow
        slow = next_node

    # Step 3: Compare the first half and the reversed second half
    left, right = head, prev
    while right:  # Only need to compare until the end of the reversed half
        if left.value != right.value:
            return False
        left = left.next
        right = right.next
    
    return True

def create_linked_list(values):
    head = None
    current = None
    for value in values:
        new_node = ListNode(value)
        if not head:
            head = new_node
            current = head
        else:
            current.next = new_node
            current = current.next
    return head

# Get user input
input_values = input("Enter the values for the linked list (comma-separated): ")
values = list(map(int, input_values.split(',')))

# Create linked list from user input
head = create_linked_list(values)

# Check if the linked list is a palindrome
result = is_palindrome(head)
print("Is the linked list a palindrome?", result)
