#!/usr/bin/perl -w

use v5.16;

my (@p) = @ARGV;
my @s = (0, 0);
my $d = 1;
my $dc = 0;

sub roll() {
	$dc++;
	my $rv = $d++;
	$d = 1 if $d > 100;
	return $rv;
}

while (1) {
	for (0 .. 1) {
		$p[$_] += roll()+roll()+roll();
		$p[$_] -= 10 while $p[$_] > 10;
		$s[$_] += $p[$_];
		# say "$dc: $d, $_, $p[$_]";
		if ($s[$_] >= 1000) {	
			say $s[1-$_]*$dc;
			exit 0;
		}
	}
}
