<jupyter_start><jupyter_text>Length of LL<jupyter_code>from sys import stdin

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None



def length(head) :
    count=0
    while head:
        count+=1
        head=head.next
    
    return count
    
    #Your code goes here



#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head



#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()



#main
t = int(stdin.readline().rstrip())

while t > 0 :

    head = takeInput()
    print(length(head))

    t -= 1<jupyter_output><empty_output><jupyter_text>Print ith node<jupyter_code>from sys import stdin

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None

def printIthNode(head, i):
    c=0
    while head:
        if c==i:
            print(head.data)
            return head.data
        
        head=head.next
        c=c+1
    

#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 :

    head = takeInput()
    i = int(stdin.readline().rstrip())
    printIthNode(head, i)

    t -= 1<jupyter_output><empty_output><jupyter_text>Delete node<jupyter_code>from sys import stdin
import sys

sys.setrecursionlimit(10**9)

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None


def deleteNode(head, pos) :
    #Your code goes here
    if pos<0:
        return head
    if head==None:
        return head
    
    if pos==0:
        head=head.next
        return head
    head.next=deleteNode(head.next,pos-1)
    return head



#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head



#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().strip())

while t > 0 :
    
    head = takeInput()
    pos = int(stdin.readline().rstrip())
    
    head = deleteNode(head, pos)
    printLinkedList(head)

    t -= 1<jupyter_output><empty_output><jupyter_text>Length of LL (recursive)<jupyter_code>class Node:
    def __init__(self,data):
        self.data=data
        self.next=None
def ll():
    linkedlist=[int(a) for a in input().split()]
    head =None
    tail=None
    for data in linkedlist:
        if data== -1:
            break
        newnode=Node(data)
        if head is None:
            head=newnode
            tail=newnode
        else:
            tail.next=newnode
            tail=newnode
    return head

def count(head):
    count=0
    while head is not None:
        count=count+1
        head=head.next
    return count

t=int(input())
while t>0:
    head=ll()
    a=count(head) 
    print(a)
    t=t-1<jupyter_output><empty_output><jupyter_text>Delete node (recursive)<jupyter_code>from sys import stdin
import sys

sys.setrecursionlimit(10**9)

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None


def deleteNode(head, pos) :
    #Your code goes here
    if pos<0:
        return head
    if head==None:
        return head
    
    if pos==0:
        head=head.next
        return head
    head.next=deleteNode(head.next,pos-1)
    return head



#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head



#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().strip())

while t > 0 :
    
    head = takeInput()
    pos = int(stdin.readline().rstrip())
    
    head = deleteNode(head, pos)
    printLinkedList(head)

    t -= 1<jupyter_output><empty_output><jupyter_text>Find a Node in Linked List<jupyter_code>from sys import stdin

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None


def findNode(head, n) :
    curr=head 
    count=0
    while curr is not None:
        if curr.data == n:
            return count
        count += 1
        curr = curr.next
    return -1


#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 : 
    
    head = takeInput()
    n = int(stdin.readline().rstrip())
    print(findNode(head, n))

    t -= 1<jupyter_output><empty_output><jupyter_text>AppendLastNToFirst<jupyter_code>from sys import stdin

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None




def appendLastNToFirst(head, n) :
    if n == 0 or head is None :
        return head
    fast = head
    slow = head 
    initialHead = head
    for i in range(n) :
        fast = fast.next
    while fast.next is not None : 
        slow = slow.next 
        fast = fast.next
    temp = slow.next 
    slow.next = None 
    fast.next = initialHead 
    head = temp 
    return head



























#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 :

    head = takeInput()
    n = int(stdin.readline().rstrip())

    head = appendLastNToFirst(head, n)
    printLinkedList(head)

    t -= 1<jupyter_output><empty_output><jupyter_text>Eliminate duplicates from LL<jupyter_code>from sys import stdin

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None




def removeDuplicates(head) :
    if head is None or head.next is None:
        return head
    
    curr = head
    new = curr.next
    
    while new is not None:
        if curr.data == new.data:
            curr.next = new.next
            new = curr.next
        else:
            curr = curr.next
            new = new.next
            
    return head





















    



#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().strip())

while t > 0 :
    head = takeInput()

    head = removeDuplicates(head)
    printLinkedList(head)

    t -= 1<jupyter_output><empty_output><jupyter_text>Print Reverse LinkedList<jupyter_code>from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 6)

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None




def printReverse(head) :
    if head is None or head.next is None:
        return head
    smallhead=printReverse(head.next)
    tail=head.next
    tail.next=head
    head.next=None
    return smallhead

def  takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 :

    head = takeInput()
    a=printReverse(head)
    printLinkedList(a)   


    t -= 1<jupyter_output><empty_output><jupyter_text>Palindrome LinkedList<jupyter_code>from sys import stdin, setrecursionlimit
setrecursionlimit(10**5)

#Following is the Node class already written for the Linked List
class Node :
    def __init__(self, data) :
        self.data = data
        self.next = None
def printll(head):
  list = []
  while head is not None:
    list.append(head.data)
    head = head.next
  return list
  
def reverseLL(head):
  list = []
  while head is not None:
    list.insert(0, head.data) 
    head = head.next
  return list


def isPalindrome(head) :
    if printll(head)  == reverseLL(head):
        return True
    else:
        return False   

































#Taking Input Using Fast I/O
def takeInput() :
    head = None
    tail = None

    datas = list(map(int, stdin.readline().rstrip().split(" ")))

    i = 0
    while (i < len(datas)) and (datas[i] != -1) :
        data = datas[i]
        newNode = Node(data)

        if head is None :
            head = newNode
            tail = newNode

        else :
            tail.next = newNode
            tail = newNode

        i += 1

    return head


#to print the linked list 
def printLinkedList(head) :

    while head is not None :
        print(head.data, end = " ")
        head = head.next

    print()


#main
t = int(stdin.readline().rstrip())

while t > 0 :
    
    head = takeInput()
    
    if isPalindrome(head) :
        print('true')
    else :
        print('false')
        
    t -= 1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10439039797852179, 'fraction_numerical': 0.006080227416298168, 'mean_word_length': 1.9008245533669264, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '297687', 'license': 'MIT', 'n_tokens_mistral': 4273, 'n_tokens_neox': 4025, 'n_words': 1182, 'path': 'Coding-Ninjas-Data-Structure-and-Algorithm-in-Python-main/linkedlist-1/all codes in one.ipynb', 'repo_name': 'SaiPrasanth212/Coding-Ninjas-Data-Structures-and-Algorithms', 'size': '12664'}