#!/usr/bin/perl use strict; use warnings; my $n = <>; my @arraya; my @arrayb; my @count; for(my $i = 0; $i < $n; $i++) { ($arraya[$i], $arrayb[$i] )= split / /, <>; $count[$i] = $arraya[$i] + 4 * $arrayb[$i]; } @count = reverse sort {$a <=> $b} @count; my $ans = 0; for(my $i = 1; $i < $n; $i++) { if(($count[0] - $count[$i]) % 2 == 0) { my $c = $count[0] - $count[$i]; $ans += $c / 2; } else { $ans = -1; } } if($ans == -1) { print "-1\n"; } else { print "$ans\n"; } exit;