#!/usr/bin/perl -w

use v5.38;
use List::Util qw(max);

my $sum;
while (<>) {
	my ($id) = /(\d+): /;
	$sum += $id if
		max(/ (\d+) red/g) <= 12
		&& max(/ (\d+) green/g) <= 13
		&& max(/ (\d+) blue/g) <= 14;
}

say $sum;
