#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'multidimensional';

my $row = 2000000;

my @ints;
my %corr;

while (<>) {
	my ($sx, $sy, $cx, $cy) = /(-?\d+)/g;
	my $r = abs($sx - $cx) + abs($sy - $cy);
	my $dist = abs($sy - $row);
	next if $dist >= $r;

	push @ints, [ $sx - ($r - $dist), $sx + ($r - $dist) ];
	$corr{$cx} = 1 if $cy == $row;
}

@ints = sort { $a->[0] <=> $b->[0] } @ints;
my $sum = $ints[0][1] - $ints[0][0] + 1;
my $prev = (shift @ints)->[1];

for my $int (@ints) {
	if ($int->[0] > $prev) {
		$sum += $int->[1] - $int->[0] + 1;
		$prev = $int->[1];
	} elsif ($int->[1] > $prev) {
		$sum += $int->[1] - $prev;
		$prev = $int->[1];
	}
}

say $sum - keys %corr;
		

