// JS 实现
function ListNode(x){
this.next = null;this.val = x;
}
let list = new ListNode();
let head = list;
let data = readline().split(' ').map(value => parseInt(value));
let k = parseInt(readline());
for(let i = 0;i<data.length;i++){
head.next = new ListNode(data[i]);
head = head.next;
}
let head1 = list.next;
var reverseLink = function(head,k){
let prev = null,cur = head;
let p = head;
let i = 0;
while(i<k){
if(p == null){
return head;
}
p = p.next;
i++;
}
for(let i = 0;i<k;i++){
let next = cur.next;
cur.next = prev;
prev = cur;
cur = next;
}
head.next = reverseLink(cur,k);
return prev;
}
let result = reverseLink(head1,k);
let res = []
while(result){
res.push(result.val);
result = result.next;
}
console.log(res.join(' '));