#!/usr/bin/perl -w

use v5.16;

my $p;
my $count;
while (<>) {
	my ($x1, $y1, $x2, $y2) = /(\d+),(\d+) -> (\d+),(\d+)/;
	next if $x1 != $x2 && $y1 != $y2;
	if ($x1 != $x2) {
		if ($x1 > $x2) {
			($x1, $x2) = ($x2, $x1);
		}
		for my $x ($x1 .. $x2) {
			$count++ if ++$p->{$x}->{$y1} == 2;
		}
	} else {
		if ($y1 > $y2) {
			($y1, $y2) = ($y2, $y1);
		}
		for my $y ($y1 .. $y2) {
			$count++ if ++$p->{$x1}->{$y} == 2;
		}
	}
}

say $count;

