# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param head ListNode类 
# @return ListNode类
#
class Solution:
    def oddEvenList(self , head ):
        # write code here
        if not head or not head.next or not head.next.next:
            return head
        left_head = ListNode(-1)
        left_tail = left_head
        right_head = ListNode(-1)
        right_tail = right_head
        temp = head
        while temp:
            new_temp = temp.next
            left_tail.next = temp
            left_tail = left_tail.next
            temp = new_temp
            if not temp :
                break
            new_temp = temp.next
            right_tail.next = temp
            right_tail = right_tail.next
            temp = new_temp
        left_tail.next = right_head.next
        right_tail.next = None
        return left_head.next