#!/usr/bin/perl -w

use v5.16;

my $p;
my $count;
while (<>) {
	my ($x1, $y1, $x2, $y2) = /(\d+),(\d+) -> (\d+),(\d+)/;
	# say "   $x1, $y1 -> $x2, $y2";
	my $xi = $x2 > $x1 ? 1 : $x2 == $x1 ? 0 : -1;
	my $yi = $y2 > $y1 ? 1 : $y2 == $y1 ? 0 : -1;
	# say "   $xi, $yi";
	
	my ($x, $y) = ($x1, $y1);
	do {
		# say "$x, $y";
		$count++ if ++$p->{$x}->{$y} == 2;
		$x += $xi; $y += $yi;
	} while ($x != $x2+$xi || $y != $y2+$yi);
}

say $count;

