using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Change "17" for more games! :)
Console.WriteLine("The No.{0} player won the {1}-player-game!", game.runGame(17), 17);
Console.ReadLine();
}
class person
{
public person prev, next;
public int num;
public bool isOut;
public person(int Num)
{
this.num = Num;
}
public int play(int seed)
{
if (this.prev == this && this.next == this)
{
// Won.
return this.num;
}
// Add the seed by one.
seed++;
if (seed % 3 == 0) {
// Out.
this.isOut = true;
this.prev.next = this.next;
this.next.prev = this.prev;
}
// Call next.
return this.next.play(seed % 3);
}
}
class game
{
public static int runGame(int pN)
{
if (pN <= 0) return -1;
// Init.
person[] persons = new person[pN];
for (int i = 0; i < pN; i++)
persons[i] = new person(i+1);
for (int i = 0; i < pN; i++)
{
// Queue.
if (i == 0) { persons[0].prev = persons[pN - 1]; }
else{persons[i].prev = persons[i-1];}
if (i == pN-1) { persons[pN-1].next = persons[0]; }
else{persons[i].next = persons[i+1];}
}
// Game Start.
return persons[0].play(0);
}
}
}
}