<jupyter_start><jupyter_text><jupyter_code># doubly linked list
class Node:
    def __init__(self, data):
        self.data = data
        self.next = None
        self.prev = None

class LinkedList:
    def __init__(self):
        self.head = None

    def push_front(self, newElement):
        newNode = Node(newElement)
        if self.head == None:
            self.head = newNode
        else:
            self.head.prev = newNode
            newNode.next = self.head
            self.head = newNode

    def push_back(self, newElement):
        newNode = Node(newElement)
        if self.head == None:
            self.head = newNode
        else:
            temp = self.head
            while temp.next != None:
                temp = temp.next
            temp.next = newNode
            newNode.prev = temp

    def insert_at(self, position, newElement):
        newNode = Node(newElement)
        if position < 1:
            print("Position should be >= 1.")
        elif position == 1:
            newNode.next = self.head
            self.head.prev = newNode
            self.head = newNode
        else:
            temp = self.head
            for i in range(1, position-1):
                if temp != None:
                    temp = temp.next
            if temp != None:
                newNode.next = temp.next
                newNode.prev = temp
                temp.next = newNode
                if newNode.next != None:
                    newNode.next.prev = newNode
                else:
                    print("The previous node is null.") 

    def delete_at(self, position):
        if position < 1:
            print("Position should be >= 1.")
        elif position == 1 and self.head != None:
            self.head = self.head.next
            if self.head != None:
                self.head.prev = None
        else:
            temp = self.head
            for i in range(1, position-1):
                if temp != None:
                    temp = temp.next
            if temp != None and temp.next != None:
                temp.next = temp.next.next
                if temp.next.next != None:
                    temp.next.next.prev = temp
            else:
                print("The node is already null.")

    def PrintList(self):
        temp = self.head
        if temp != None:
            print("The list contains:", end=" ")
            while temp != None:
                print(temp.data, end=" ")
                temp = temp.next
        else:
            print("The list is empty.")

#27
print("27. symmetrical insertion")
MyList = LinkedList()
MyList.head = Node(1)
n = int(input())
for i in range(2,n+1):
    MyList.push_front(i)
    MyList.push_back(i)
MyList.PrintList()

#28
print("\n\n28. insert_at")
k, x = map(int, input().split())
MyList.insert_at(k, x)
MyList.PrintList()

#29
print("\n\n29. delete_at")
MyList.delete_at(k)
MyList.PrintList()
# Circular Linked List
class CLinkedList:
    def __init__(self):
        self.head = None

    def push_back(self, newElement):
        newNode = Node(newElement)
        if self.head == None:
            self.head = newNode
            newNode.next = self.head
        else:
            temp = self.head
            while temp.next != self.head:
                temp = temp.next
            temp.next = newNode
            newNode.next = self.head

    def Print_from(self, position):     

        temp = self.head

        if position < 1:
            print("Position should be >= 1.")
    
        elif position == 1:
            print(temp.data, end=" ")
            while(temp.next != self.head):
                print(temp.next.data, end=" ")
                temp = temp.next

        else:
            for i in range(1, position):
                temp = temp.next
            self.head = temp
            print(temp.data, end=" ")
            while temp.next != self.head:
                print(temp.next.data, end=" ")
                temp = temp.next

 
MyCList = CLinkedList()

a = [int(x) for x in input().split()]
for i in a:
    MyCList.push_back(i)

l = int(input())
MyCList.Print_from(l)<jupyter_output>30 20 10 5 2
2
20 10 5 2 30
{'fraction_non_alphanumeric': 0.10792580101180438, 'fraction_numerical': 0.011081667068176343, 'mean_word_length': 1.4224037339556592, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '559514', 'license': 'Unlicense', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1182, 'n_words': 326, 'path': 'Lab6_2_2.ipynb', 'repo_name': 'hocthucv/bt', 'size': '4151'}