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

def remove_elements(head: ListNode, key: int) -> ListNode:
    dummy = ListNode(0)  # Create a dummy node to simplify edge cases
    dummy.next = head
    current = dummy  # Start with the dummy node

    while current.next:
        if current.next.value == key:
            current.next = current.next.next  # Skip the node with the key
        else:
            current = current.next  # Move to the next node

    return dummy.next  # Return the new head, skipping the dummy node

def create_linked_list(elements):
    head = None
    current = None
    for element in elements:
        new_node = ListNode(element)
        if head is None:
            head = new_node
            current = head
        else:
            current.next = new_node
            current = new_node
    return head

def print_linked_list(head):
    elements = []
    current = head
    while current:
        elements.append(current.value)
        current = current.next
    print(elements)

# User input
user_input = input("Enter the list in the format [1,2,6,3,4,5,6]: ")
key_input = int(input("Enter the key to remove: "))

# Extracting the list from the input string
try:
    elements = eval(user_input.strip())
    if not isinstance(elements, list):
        raise ValueError("Input should be a list.")
except Exception as e:
    print(f"Error: {e}")
    exit(1)

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

# Remove elements and print the result
updated_head = remove_elements(head, key_input)
print("Updated linked list:", end=" ")
print_linked_list(updated_head)