def add2(head1,head2):

    # get each lenght and makup 0 nodes for the shorter one
    l1 = ll.get_length(head1)
    l2 = ll.get_length(head2)
    #print "%d,%d" % (l1,l2)

    if l1>=l2:
        while l1 > l2:
            zero = ll.ListNode(0)
            zero.next = head2
            head2 = zero
            l2 += 1
    else: 
        while l1 < l2:
            zero = ll.ListNode(0)
            zero.next = head1
            head1 = zero
            l1 += 1
    #print "%d,%d" % (l1,l2)
    ll.print_list(head1)
    ll.print_list(head2)
    res,flag = rec(head1,head2,l1-1)
    if flag == 1:
        return res+10**l1
    else:
        return res
def return_kth(head, k):
    size = ll.get_length(head)
    if not head or k > size:
        print "invalid input"
        return 0
    # far = size-k+1
    start = head
    end = head
    for i in range(k):
        end = end.next
    while end:
        start = start.next
        end = end.next
    return start.val
def isPalidrome(head):
    if not head or not head.next:
        return True
    size = ll.get_length(head)
    return rec(head,size-1)