#!/usr/bin/perl -w

use v5.16;

$; = ',';
my %cubes;
while (<>) {
	my $state = /^on / ? 1 : 0;
	my ($xmin, $xmax, $ymin, $ymax, $zmin, $zmax) = /-?\d+/g;
	($xmin, $xmax) = ($xmax, $xmin) if $xmax < $xmin;
	($ymin, $ymax) = ($ymax, $ymin) if $ymax < $ymin;
	($zmin, $zmax) = ($zmax, $zmin) if $zmax < $zmin;
	say "cuboid ", join(',', $state, $xmin, $xmax, $ymin, $ymax, $zmin, $zmax);
	next if ($xmax < -50 || $ymax < -50 || $zmax < -50);
	next if ($xmin > 50 || $ymin > 50 || $zmin > 50);
	$xmin = -50 if ($xmin < -50);
	$ymin = -50 if ($ymin < -50);
	$zmin = -50 if ($zmin < -50);
	$xmax = 50 if $xmax > 50;
	$ymax = 50 if $zmax > 50;
	$zmax = 50 if $zmax > 50;
	for my $x ($xmin .. $xmax) {
	for my $y ($ymin .. $ymax) {
	for my $z ($zmin .. $zmax) {
		$cubes{$x,$y,$z} = $state;
		say "$x,$y,$z => $state";
	} } }
}

my $count;
for my $x (-50 .. 50) {
for my $y (-50 .. 50) {
for my $z (-50 .. 50) {
	$count++ if $cubes{$x,$y,$z};
} } }

say $count;

