#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int id;
struct node *next;
} node;
int main(int argc, char const *argv[])
{
int n, i;
scanf("%d", &n);
node *p, *s, *r;
//head node
p = (node *)malloc(sizeof(node));
p->id = 1;
p->next = NULL;
r = p;
for (i = 2; i <= n; ++i)
//generate a list
{
s = (node *)malloc(sizeof(node));
s->id = i;
r->next = s;
r = r->next;
}
r->next = p;
int num = 0;
while (n > 1)
//when the number of man is 1, then exit
{
if (p->id != 0)
{
++num;
if (num % 3 == 0)
{
n -= 1;
p->id = 0;
}
p = p->next;
}
else
p = p->next;
}
while (!p->id)
p = p->next;
printf("the survivor is: %d", p->id);
return 0;
}