#include<stdio.h>
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
void ListDelete(LinkList &L,LNode *p,int &e)
{
LinkList q;
if(p==L)
L=p->next;
else
{
q=L;
while(q->next!=p)
q=q->next;
q->next=p->next;
}
e=p->data;
delete p;
}
int main()
{
int n,i;
scanf("%d",&n);
LinkList p=new LNode;
LinkList L=p;
for(i=0;i<n;i++)
{
LinkList s=new LNode;
s->data=i;
p->next=s;
p=s;
}
p->next=NULL;
LinkList t = L->next->next;
int e ;
ListDelete(L,t,e);
printf("%d\n",e);
p = L->next ;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
return 0;
}