#!/usr/bin/perl -w

use strict;

my @start = map { chomp; $_ } split /,/, <>;

my $turn = 0;
my %nums;
my $num;

while ($turn < 2020) {
	$turn++;
	if (@start) {
		$num = shift @start;
	}
	my $next;
	if (defined $nums{$num}) {
		$next = $turn - $nums{$num};
	} else {
		$next = 0;
	}
	$nums{$num} = $turn;
	print "turn $turn, num=$num\n";
	$num = $next;
}



