#!/usr/bin/perl -w

use v5.16;
use strict;

my %lights;

$; = ',';

while (<>) {
	my ($what, $xmin, $ymin, $xmax, $ymax) = /^(.*) (\d+),(\d+) through (\d+),(\d+)/;
	($xmax, $xmin) = ($xmin, $xmax) if $xmin > $xmax;
	($ymax, $ymin) = ($ymin, $ymax) if $ymin > $ymax;
	for my $x ($xmin .. $xmax) {
	for my $y ($ymin .. $ymax) {
		if ($what eq 'toggle') {
			$lights{$x,$y} += 2;
		} elsif ($what eq 'turn on') {
			$lights{$x,$y}++;
		} elsif ($what eq 'turn off') {
			$lights{$x,$y}-- if $lights{$x,$y};
		}
	} }
}

use List::Util qw(sum);
say sum values %lights;

