# 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
"""
if head==None:return []
cnt=1
last=head
while(last.next!=None):
last=last.next
cnt+=1
k%=cnt
if k==0:return head
curHead=head
last.next=head
print last.val
while(cnt>k+1):
cnt-=1
curHead=curHead.next
ans=curHead.next
curHead.next=None
return ans