Skip to content

Instantly share code, notes, and snippets.

@dflima
Created November 7, 2017 18:06
Show Gist options
  • Save dflima/f5854c1e91bd0f769839d35d0a28581e to your computer and use it in GitHub Desktop.
Save dflima/f5854c1e91bd0f769839d35d0a28581e to your computer and use it in GitHub Desktop.
<?php
$handle = fopen('php://stdin', 'r');
fscanf($handle, '%d', $n);
$a = [];
for ($i = 0; $i < $n; $i++) {
$temp = fgets($handle);
$a[] = explode(' ', $temp);
array_walk($a[$i], 'invtal');
}
$d1 = $d2 = $j = 0;
$length = count($a);
for ($i = 0; $i < $length; $i++) {
$d1 += $a[$j++][$i];
$d2 += $a[$length-$j][$i];
}
print abs($d1 - $d2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment