def removeNthFromEnd(head, n):
    def f(x,i):
        head,m,n = x
        return ((head if m==n else new_node(i,head)),m+1,n)

    return foldr(
        f,
        (None, 1, n),
        list_node_to_iter(head))[0]
def reverseKGroup(head, k):
    return list_node_from_iter(reverse_by_n(list_node_to_iter(head), k))
def swapPairs(head):
    return list_node_from_iter(reverse_by_n(list_node_to_iter(head), 2))
def removeNthFromEnd(head, n):
    return foldr(
        lambda (head,m,n),i: ((head if m==n else new_node(i,head)),m+1,n),
        (None, 1, n),
        list_node_to_iter(head))[0]