#!/usr/bin/perl

use v5.30;
use strict;

use List::Util qw(max);

my %layers = map { /(\d+): (\d+)/ } <>;
my $max_l = max keys %layers;

my $severity = 0;
for my $pos (0 .. $max_l) {
	next if !defined $layers{$pos};
	next if $pos % (2 * $layers{$pos} - 2);
	say "caught at $pos";
	$severity += $pos * $layers{$pos};
}

say $severity;

