# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def rotateRight(self, head, k):
        """
        :type head: ListNode
        :type k: int
        :rtype: ListNode
        """
        xs = []
        p = head
        while p:
        	xs.append(p.val)
        	p = p.next
        if not xs:
        	return None 
        k = k % len(xs)
        xs = xs[-k:] + xs[:-k]
        p = None
        while xs:
        	np = ListNode(xs.pop())
        	np.next = p
        	p = np
        return p

