#include
using namespace std;
class Node{
public:
int data;
Nodenext;
Node(int d)
{
data=d;
next=NULL;
}
};
void insert(Node&head,int data)
{
if(head==NULL)
{
head=new Node(data);
return;
}
Node*temp1=head;
while(temp1->next!=NULL)
{
temp1=temp1->next;
}
temp1->next=new Node(data);
return;
}
void print(Nodehead)
{
while(head!=NULL)
{
cout<data<<" ";
head=head->next;
}
}
void linkedlist(Node&head,int n)
{
int data;
while(n–)
{
cin>>data;
insert(head,data);
}
return;
}
void reverse(Nodehead,int t)
{
t=3;
Nodetemp=head;
Node*temp1=head;
if(temp==NULL||temp->next==NULL)
{
return;
}
int a;
while(t>1)
{
temp=temp->next;
t–;
}
a=temp->data;
temp->data=temp1->data;
temp1->data=a;
reverse(temp->next,t);
}
int main() {
int n,t;
cin>>n;
cin>>t;
Node*head=NULL;
linkedlist(head,n);
reverse(head,t);
print(head);
return 0;
}