using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
for (int I = 1; I < int.MaxValue; I++) {
if (IsAnswer(I)) {
Console.WriteLine("解={0}", I);
break;
}
}
}
//聖数を引数として、解かを判定
static bool IsAnswer(int pSeisuu)
{
var NumList = new List<int>();
NumList.AddRange(new int[] { 1, 10, 50, 100, 10, 50, 100, 10, 100, 50 });
NumList.AddRange(new int[] { 100, 10, 500, 50, 100, 50, 10, 100 });
int CurrInd = 0;
while (NumList.Count > 1) {
int CurrUB = NumList.Count - 1;
CurrInd += pSeisuu - 1;
if (CurrUB < CurrInd) CurrInd %= NumList.Count;
if (NumList[CurrInd] == 500) return false;
NumList.RemoveAt(CurrInd);
}
return true;
}
}