#!/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);
	say "dist =$dist";
	if ($dist < $r) {
		my $l = abs($dist-$r);
		push @ints, [ $sx - ($r - $dist), $sx + ($r - $dist) ];
		say "$ints[-1][0] $ints[-1][1]";
		$corr{$cx} = 1 if $cy == $row;
	}
}

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

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

say $sum - keys %corr;
		

