#!/bin/python3

import math
import os
import random
import re
import sys

class SinglyLinkedListNode:
    def __init__(self, node_data):
        self.data = node_data
        self.next = None

class SinglyLinkedList:
    def __init__(self):
        self.head = None
        self.tail = None

    def insert_node(self, node_data):
        node = SinglyLinkedListNode(node_data)

        if not self.head:
            self.head = node
        else:
            self.tail.next = node

        self.tail = node

def print_singly_linked_list(node, sep, fptr):
    while node:
        fptr.write(str(node.data))

        node = node.next

        if node:
            fptr.write(sep)

def print_singly_linked_list_1(node):
    output = ''
    while node:
        output += str(node.data)
        node = node.next
        if node:
            output += " "
    print(output)

def node2list(node):
    output = []
    while node:
        output.append(node.data)
        node = node.next
    return output

#
# Complete the 'oddEvenList' function below.
#
# The function is expected to return an INTEGER_SINGLY_LINKED_LIST.
# The function accepts INTEGER_SINGLY_LINKED_LIST head as parameter.
#
#
# For your reference:
#
# SinglyLinkedListNode:
#     int data
#     SinglyLinkedListNode next
#
#

def oddEvenList(l):
    if not l or not l.next:
        return l
    odd = l
    even = even_h = l.next
    while odd.next and even.next:
        odd.next = even.next
        if odd.next:
            even.next = odd.next.next
        odd = odd.next
        even = even.next
    odd.next = even_h
    return l

list1 = SinglyLinkedList()
nums = [1, 2, 3, 4, 5]
for v in nums:
    list1.insert_node(v)

result = oddEvenList(list1.head)
print(node2list(result))

