#!/usr/bin/perl -w

use v5.38;

my $sum;
while (<>) {
	my @seq = /-?\d+/g;
	my @rest;
	while (grep $_, @seq) {
		push @rest, $seq[0];
		for my $i (0 .. $#seq-1) {
			$seq[$i] = $seq[$i+1]-$seq[$i];
		}
		pop @seq;
	}
	my $s = 0;
	for (reverse @rest) {
		$s = $_ - $s;
	}
	$sum += $s;
}

say $sum;

