Given a square matrix, calculate the absolute difference between the sums of its diagonals.  

For example, the square matrix $\textbf{arr}$ is shown below:  

1 2 3
4 5 6
9 8 9  

The left-to-right diagonal = $1+5+9=15$.  The right to left diagonal = $3+5+9=17$.  Their absolute difference is $|15-17|=2$.  

Function description

Complete the $\textit{diagonalDifference}$ function in the editor below.  

diagonalDifference takes the following parameter:  

int arr[n][m]: an array of integers 

Return  

int: the absolute diagonal difference  

Input Format

The first line contains a single integer, $n$,  the number of rows and columns in the square matrix $\textbf{arr}$. 

Each of the next $n$ lines describes a row, $arr\left[i\right]$, and consists of $n$ space-separated integers $ar r[i][j]$.

Constraints

$-100\leq arr[i][j]\leq100$

Output Format

Return the absolute difference between the sums of the matrix's two diagonals as a single integer.

Sample Input
3
11 2 4
4 5 6
10 8 -12

Sample Output
15

Explanation

The primary diagonal is:  

11
   5
     -12

Sum across the primary diagonal: 11 + 5 - 12 = 4 

The secondary diagonal is:

     4
   5
10

Sum across the secondary diagonal: 4 + 5 + 10 = 19 

Difference: |4 - 19| = 15

Note: |x| is the absolute value of x

Difficulty: EASY

Solutions:
N = int(input())
grid = []
for i in range(0, N):
	lists = [int(i) for i in input().split()]
	grid.append(lists)
count = 0
sum1 = 0
sum2 = 0
j1 = 0
j2 = N - 1
while count < N:
	sum1 = sum1 + grid[count][j1]
	sum2 = sum2 + grid[count][j2]
	count += 1
	j1 += 1
	j2 -= 1
print(abs(sum1 - sum2))


size = int(input())
thematrix = []
firstdiag = []
seconddiag = []
for i in range(size):
	line = input().strip().split(' ')
	line = [int(j) for j in line]
	thematrix.append(line)
for i in range(size):
	firstdiag.append(thematrix[i][i])
	seconddiag.append(thematrix[i][size - 1 - i])
print(abs(sum(firstdiag) - sum(seconddiag)))


matrix_size = int(input())
difference = 0
for i in range(matrix_size):
	row = input().split()
	for j in range(matrix_size):
		if j == i:
			pos_diag = int(row[j])
		if j == matrix_size - i - 1:
			neg_diag = int(row[j])
	difference += pos_diag
	difference -= neg_diag
print(abs(difference))


def matrix(n):
	a = 0
	b = 0
	i = 0
	for j in range(n):
		k = input().split()
		a += int(k[i])
		b += int(k[n - 1 - i])
		i += 1
	return abs(a - b)
n = int(input())
res = matrix(n)
print(res)


t = int(input())
matrix = [[] for i in range(t)]
for j in range(t):
	matrix[j] = list(map(int, input().split()))
i = 0
j = 0
k = t - 1
sum1 = 0
sum2 = 0
for j in range(t):
	sum1 += matrix[i][j]
	sum2 += matrix[i][k]
	i += 1
	j += 1
	k -= 1
if sum1 > sum2:
	print(sum1 - sum2)
else:
	print(sum2 - sum1)


a = int(input())
sum1 = 0
sum2 = 0
for i in range(a):
	x = list(map(int, input().split()))
	sum1 += x[i]
	sum2 += x[a - 1 - i]
print(abs(sum1 - sum2))


n = int(input())
matrix = []
for i in range(0, n):
	matrix.append([int(x) for x in input().split()])
(row1, col1) = (0, 0)
(row2, col2) = (n - 1, 0)
(sum1, sum2) = (0, 0)
for i in range(0, n):
	sum1 += matrix[row1 + i][col1 + i]
	sum2 += matrix[row2 - i][col2 + i]
print(abs(sum1 - sum2))


n = int(input())
b = n
a = []
while n > 0:
	a.append(list(map(int, input().split())))
	n -= 1
x = 0
y = 0
for i in range(0, b):
	x += a[i][i]
	y += a[i][b - i - 1]
if x > y:
	print(x - y)
else:
	print(y - x)


n = int(input())
mat = []
for _ in range(n):
	row = [int(i) for i in input().split()]
	mat.append(row)
s1 = 0
s2 = 0
for i in range(n):
	s1 += mat[i][i]
	s2 += mat[i][n - 1 - i]
print(abs(s1 - s2))


N = int(input())
diff = 0
(a, b) = (0, N - 1)
for i in range(N):
	numbers = list(map(int, input().split()))
	diff += numbers[b] - numbers[a]
	a += 1
	b -= 1
print(abs(diff))


num1 = num2 = 0
a = int(input())
for x in range(0, a):
	b = input().split()
	if True:
		num1 = num1 + int(b[x])
		num2 = num2 + int(b[a - 1])
		a = a - 1
sum = num1 - num2
print(abs(sum))


N = int(input())
nMinsOne = N - 1
sumDiag1 = 0
sumDiag2 = 0
for i in range(N):
	line = input().split()
	sumDiag1 += int(line[i])
	sumDiag2 += int(line[nMinsOne - i])
print(abs(sumDiag1 - sumDiag2))


size = int(input())
thematrix = []
firstdiag = []
seconddiag = []
for i in range(size):
	line = input().strip().split(' ')
	line = [int(j) for j in line]
	thematrix.append(line)
for i in range(size):
	firstdiag.append(thematrix[i][i])
	seconddiag.append(thematrix[i][size - 1 - i])
print(abs(sum(firstdiag) - sum(seconddiag)))


def diag_diff(matrix, size):
	sum_first_diag = 0
	sum_second_diag = 0
	for i in range(size):
		for j in range(size):
			if i == j:
				sum_first_diag += int(matrix[i][j])
				sum_second_diag += int(matrix[i][-(j + 1)])
	result = abs(sum_first_diag - sum_second_diag)
	return result
N = int(input())
input_matrix = list()
for _ in range(N):
	input_matrix.append(list(input().split()))
print(diag_diff(input_matrix, N))


n = int(input())
i = 0
list = []
sum1 = []
sum2 = []
for i in range(n):
	list.append(input())
i = 0
for i in range(n):
	j = 0
	for j in range(n):
		if j == i:
			sum1.append(int(list[i].split()[j]))
		j += 1
	i += 1
i = 0
j = n - 1
for i in range(n):
	if j >= 0:
		sum2.append(int(list[i].split()[j]))
	j -= 1
	i += 1
(i, first, sec) = (0, 0, 0)
for i in range(n):
	first += sum1[i]
	sec += sum2[i]
if first - sec >= 0:
	print(first - sec)
else:
	print(sec - first)


t = int(input())
n = []
for x in range(t):
	n = n + ''.join(input()).split()
answer1 = 0
answer2 = 0
for y in range(t):
	answer1 = answer1 + int(n[y * (t + 1)])
for z in range(t):
	answer2 = answer2 + int(n[(z + 1) * t - (z + 1)])
print(abs(answer1 - answer2))


import math
import fileinput
input_list = []
for line in fileinput.input():
	L = [int(i) for i in line.split()]
	input_list.append(L)
N = input_list[0][0]
p = 1
diagonal_one = 0
diagonal_two = 0
for x in range(1, N + 1):
	diagonal_one += input_list[x][x - 1]
for y in range(1, N + 1):
	diagonal_two += input_list[N + 1 - y][y - 1]
res = abs(diagonal_one - diagonal_two)
print(res)


n = int(input())

def matrix():
	m = []
	for _ in range(n):
		m.append(list(map(int, list(input().split(' ')))))
	return m

def sum_diagonals(matrix=matrix()):
	d1 = 0
	d2 = 0
	c = 0
	for row in matrix:
		d1 += row[c]
		c += 1
	c -= 1
	for row in matrix:
		d2 += row[c]
		c -= 1
	return abs(d1 - d2)
print(sum_diagonals())


def read_line(_):
	return [int(x) for x in input().split()]
num_lines = int(input())
mat = [read_line(i) for i in range(num_lines)]
first_diag = sum((mat[i][i] for i in range(num_lines)))
second_diag = sum((mat[i][num_lines - 1 - i] for i in range(num_lines)))
abs_diff = abs(first_diag - second_diag)
print(abs_diff)


import math
n = int(input())
square = []
difference = 0
leftdi = 0
rightdi = 0
for i in range(n):
	square.append(input().split())
	leftdi += int(square[i][i])
	rightdi += int(square[i][-i - 1])
print(abs(leftdi - rightdi))


import math

def diagonalDif(a, b):
	return abs(a - b)
n = int(input())
matrix = []
for i in range(0, n):
	matrix += [[]]
	line = input().split()
	for j in range(n):
		matrix[i] += [int(line[j])]
aIndex = 0
a = 0
bIndex = n - 1
b = 0
for i in range(n):
	a += matrix[i][aIndex]
	b += matrix[i][bIndex]
	aIndex += 1
	bIndex -= 1
res = diagonalDif(a, b)
print(res)


n = int(input())
a = 0
b = n - 1
s1 = 0
s2 = 0
for _ in range(n):
	row = input().split()
	s1 += int(row[a])
	s2 += int(row[b])
	a += 1
	b -= 1
print(abs(s1 - s2))


n = int(input())
sumForward = 0
sumBackward = 0
for i in range(n):
	s = [int(j) for j in input().split(' ')]
	sumForward += int(s[i])
	sumBackward += int(s[n - 1 - i])
print(abs(sumForward - sumBackward))


n = int(input())
sub = []
main = []
for i in range(n):
	sub = input().split(' ')
	main.append(sub)
sum1 = 0
sum2 = 0
for i in range(n):
	sum1 = sum1 + int(main[i][i])
	sum2 = sum2 + int(main[i][n - 1 - i])
print(abs(sum1 - sum2))


tc = int(input())
matrix = list()
for i in range(0, tc):
	matrix.append(list())
	for j in input().split(' '):
		matrix[i].append(int(j))
dg1 = 0
dg2 = 0
for i in range(0, tc):
	dg1 = dg1 + matrix[i][i]
	dg2 = dg2 + matrix[i][tc - i - 1]
print(abs(dg1 - dg2))


N = int(input())
m = [[] for _ in range(N)]
for i in range(N):
	m[i] = [int(x) for x in input().split()]
sum1 = sum2 = 0
for i in range(N):
	sum1 += m[i][i]
	sum2 += m[N - 1 - i][i]
print(abs(sum1 - sum2))


N = int(input())
listahan = []
for i in range(N):
	listahan.append(input().split())
firstDiag = 0
for i in range(N):
	firstDiag += int(listahan[i][i])
secondDiag = 0
for j in range(N):
	secondDiag += int(listahan[j][N - j - 1])
print(abs(firstDiag - secondDiag))


def AbsDiff(a, b):
	return abs(a - b)
n = int(input())
d1 = 0
d2 = 0
for i in range(1, n + 1):
	counter = 0
	row = input().split()
	for j in row:
		val = int(j)
		counter += 1
		if i == counter:
			d1 += val
		if i == n - counter + 1:
			d2 += val
res = AbsDiff(d1, d2)
print(res)


def sumf(list):
	sumf = 0
	for i in range(0, len(list)):
		sumf += int(list[i][i])
	return sumf

def sumb(list):
	sumb = 0
	for i in range(0, len(list)):
		sumb += int(list[len(list) - 1 - i][i])
	return sumb

def dif(a, b):
	if a > b:
		print(a - b)
	else:
		print(b - a)
N = int(input())
m = []
l = []
for i in range(0, N):
	l.append(input())
	x = l[i].split(' ')
	m.append(x)
dif(sumf(m), sumb(m))


n = int(input())
firstd = 0
secondd = 0
for i in range(0, n):
	data = input().split()
	firstd = firstd + int(data[i])
	secondd = secondd + int(data[n - 1 - i])
res = firstd - secondd
if res < 1:
	res = -res
print(res)


n = int(input())
T = []
for _ in range(n):
	lis = list(map(int, input().split()))
	T.append(lis)
a = 0
b = 0
for i in range(n):
	a += T[i][i]
	b += T[i][n - i - 1]
print(abs(a - b))


size = int(input())
matrix = []
d1 = 0
d2 = 0
for i in range(size):
	matrix.append([int(x) for x in input().split(' ')])
	d1 += matrix[i][i]
	d2 += matrix[i][size - 1 - i]
print(abs(d1 - d2))


n = int(input())
a = []
for i in range(0, n):
	r = input()
	a.append(list(r.split()))
sum1 = 0
for i in range(0, n):
	sum1 += int(a[i][i])
sum2 = 0
for i in range(0, n):
	sum2 += int(a[i][n - i - 1])
print(abs(sum1 - sum2))


a = []
b = int(input())
for i in range(b):
	a += [list(map(int, input().split()))]
print(abs(sum((a[i][i] - a[i][b - i - 1] for i in range(b)))))


n = int(input())
a = []
for x in range(n):
	a.append(input().split())
	for i in range(n):
		a[x][i] = int(a[x][i])
sum1 = 0
sum2 = 0
for i in range(n):
	sum1 = sum1 + a[i][i]
a.reverse()
for i in range(n):
	sum2 = sum2 + a[i][i]
print(abs(sum1 - sum2))


n = int(input())
(f, b) = (0, 0)
for ii in range(n):
	line = list(map(int, input().split()))
	f += line[ii]
	b += line[n - 1 - ii]
print(abs(f - b))


n = int(input())
d1 = 0
d2 = 0
for i in range(0, n):
	a = input().split()
	d1 += int(a[i])
	d2 += int(a[n - i - 1])
print(abs(d1 - d2))


n = int(input())
matrix = [[] for i in range(0, n)]
for i in range(0, n):
	line = input()
	row = map(lambda num: int(num), line.split())
	matrix[i] = list(row)
sum1 = 0
sum2 = 0
for i in range(0, n):
	sum1 += matrix[i][i]
	sum2 += matrix[i][n - 1 - i]
print(abs(sum1 - sum2))


N = int(input())
firstDiagonal = 0
secondDiagonal = 0
firstColumn = 0
secondColumn = N - 1
for row in range(N):
	row = [int(x) for x in input().split()]
	firstDiagonal += row[firstColumn]
	secondDiagonal += row[secondColumn]
	firstColumn += 1
	secondColumn -= 1
print(abs(firstDiagonal - secondDiagonal))


import sys
line = sys.stdin.readline()
n = int(line)
firstDiagonalSum = 0
secondDiagonalSum = 0
for x in range(0, n):
	line = sys.stdin.readline()
	row = line.strip('\n').split(' ')
	firstDiagonalSum += int(row[x])
	secondDiagonalSum += int(row[n - x - 1])
print(abs(firstDiagonalSum - secondDiagonalSum))


n = int(input())
m = []
for ln in range(0, n):
	r = input()
	m.append(r.split())
res1 = 0
res2 = 0
for i in range(0, n):
	res1 += int(m[i][i])
	res2 += int(m[i][n - i - 1])
diff = abs(res1 - res2)
print(diff)


line = []
numList = []
lrDiag = 0
rlDiag = 0
dimensions = int(input())
for i in range(dimensions):
	j = dimensions - (i + 1)
	line = list(map(int, input().split()))
	numList.append(line)
	lrDiag = lrDiag + numList[i][i]
	rlDiag = rlDiag + numList[i][j]
print(abs(lrDiag - rlDiag))


def diag_diff(nums):
	diag1 = sum((nums[i][i] for (i, _) in enumerate(nums)))
	diag2 = 0
	(i, j) = (0, len(nums) - 1)
	while j >= 0:
		diag2 += nums[i][j]
		(i, j) = (i + 1, j - 1)
	return abs(diag1 - diag2)
nums = []
n = int(input())
for _ in range(n):
	line = [int(el) for el in input().split()]
	nums.append(line)
print(diag_diff(nums))


n = int(input())
(diag1, diag2) = (0, 0)
for i in range(n):
	row = [int(x) for x in input().split(' ')]
	diag1 += row[i]
	diag2 += row[-i - 1]
print(abs(diag2 - diag1))


n = int(input())
(sum_1, sum_2) = (0, 0)
for i in range(n):
	temp = [int(j) for j in input().split()]
	sum_1 += temp[i]
	sum_2 += temp[n - 1 - i]
print(abs(sum_1 - sum_2))


N = int(input())
matrix = [[int(j) for j in input().split()] for i in range(N)]
sum1 = 0
sum2 = 0
for i in range(N):
	sum1 += matrix[i][i]
	sum2 += matrix[i][N - i - 1]
print(abs(sum1 - sum2))


l = int(input())
mat = []
for i in range(l):
	mat.append([int(j) for j in input().split()])
soma = 0
for i in range(l):
	soma += mat[i][i]
	soma -= mat[i][l - i - 1]
if soma < 0:
	soma *= -1
print(soma)


count = int(input())
first_diag = 0
second_diag = 0
for i in range(count):
	list_numbers = list(map(int, input().split()))
	first_diag += list_numbers[i]
	second_diag += list_numbers[count - 1 - i]
print(abs(first_diag - second_diag))


n = int(input())
matrix = []
sum1 = 0
sum2 = 0
for i in range(n):
	row = list(map(int, input().split(' ')))
	matrix.append(row)
for i in range(n):
	num1 = matrix[i][i]
	num2 = matrix[i][n - i - 1]
	sum1 = sum1 + num1
	sum2 = sum2 + num2
print(abs(sum1 - sum2))


N = int(input())
Nlist = []
a = 0
b = 0
for i in range(N):
	Nlist.append(input().split())
for i in range(N):
	a += int(Nlist[i][i])
	b += int(Nlist[i][-1 - i])
print(abs(a - b))


def separatenumbers(line):
	raw = str(line).split(' ')
	return list(map(int, raw))

def main(matrix):
	sum1 = 0
	for i in range(N):
		sum1 += matrix[i][i]
	sum2 = 0
	counter = N
	for x in range(N):
		counter -= 1
		sum2 += matrix[x][counter]
	print(abs(sum1 - sum2))
N = int(input())
matrix = [separatenumbers(input()) for i in range(N)]
main(matrix)


def calc_diag1(matrix):
	return sum([row[idx] for (idx, row) in enumerate(matrix)])

def calc_diag2(matrix):
	return sum([row[idx] for (idx, row) in enumerate(reversed(matrix))])
n = int(input())
matrix = []
for i in range(0, n):
	row = [int(x) for x in input().split()]
	matrix.append(row)
res1 = calc_diag1(matrix)
res2 = calc_diag2(matrix)
res = abs(res2 - res1)
print(res)


mat = []
major = 0
minor = 0
N = int(input())
for ii in range(N):
	row = list(map(int, input().split(' ')))
	major += row[ii]
	minor += row[N - 1 - ii]
print(abs(major - minor))


def arrayToInt(numberArray):
	numberIntArray = []
	for i in range(0, len(numberArray)):
		numberIntArray.append(int(numberArray[i]))
	return numberIntArray
n = int(input())
matrix = [[0 for x in range(n)] for x in range(n)]
firstdiag = 0
seconddiag = 0
for i in range(0, n):
	numberArray = input().split()
	numberIntArray = arrayToInt(numberArray)
	for j in range(0, n):
		matrix[i][j] = numberIntArray[j]
	firstdiag += matrix[i][i]
	seconddiag += matrix[i][n - i - 1]
print(abs(firstdiag - seconddiag))


N = int(input())
matr = []
for _ in range(N):
	matr.append([int(x) for x in input().split()])
sum1 = 0
sum2 = 0
for i in range(N):
	sum1 += matr[i][i]
	sum2 += matr[i][-i - 1]
print(abs(sum1 - sum2))


n = int(input())
l = ()
sum1 = 0
sum2 = 0
i1 = 0
i2 = n - 1
for row in range(n):
	l = list(map(int, input().split()))
	sum1 = sum1 + l[i1]
	sum2 = sum2 + l[i2]
	i1 = i1 + 1
	i2 = i2 - 1
print(abs(sum1 - sum2))


nSize = int(input())
listArray = list()
for i in range(0, nSize):
	listInput = list(map(int, input().split()))
	listArray.append(listInput)
nSumLeft = 0
for i in range(0, nSize):
	nSumLeft += listArray[i][i]
nSumRight = 0
nIndex = nSize - 1
for i in range(0, nSize):
	nSumRight += listArray[i][nIndex]
	nIndex = nIndex - 1
print(abs(nSumLeft - nSumRight))


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
print(abs(sum([a[i][i] - a[i][n - i - 1] for i in range(n)])))


N = int(input())
counter = 0
diag1 = 0
diag2 = 0
for x in range(0, N):
	numbers = input().split()
	diag1 = diag1 + int(numbers[counter])
	diag2 = diag2 + int(numbers[N - (counter + 1)])
	counter += 1
print(abs(diag1 - diag2))


n = int(input())
matrix = []
for _ in range(n):
	row = [int(x) for x in input().split()]
	matrix.append(row)
first_sum = 0
for i in range(n):
	first_sum += matrix[i][i]
second_sum = 0
for i in range(n):
	second_sum += matrix[n - 1 - i][i]
abs_diff = abs(first_sum - second_sum)
print(abs_diff)


n = int(input())
ar = []
for i in range(n):
	ar.append(input().split(' '))
d1 = 0
d2 = 0
for i in range(n):
	d1 += int(ar[i][i])
	d2 += int(ar[i][-i - 1])
print(abs(d1 - d2))


N = int(input())
d1 = 0
d2 = 0
for i in range(N):
	s = list(map(int, input().split()))
	d1 += s[i]
	d2 += s[N - i - 1]
print(abs(d1 - d2))


def diagonal_difference(matrix):
	n = len(matrix)
	diagonal1 = 0
	diagonal2 = 0
	for i in range(n):
		diagonal1 += matrix[i][i]
		diagonal2 += matrix[i][-i - 1]
	return abs(diagonal1 - diagonal2)
n = int(input())
matrix = []
for i in range(n):
	numbers = input().split(' ')
	numbers = [int(number) for number in numbers]
	matrix.append(numbers)
print(diagonal_difference(matrix))


n = int(input())
d1 = 0
d2 = 0
i = 0
for i in range(n):
	iLine = [int(x) for x in input().split(' ')]
	d1 += iLine[0 + i]
	d2 += iLine[n - 1 - i]
print(abs(d1 - d2))


num_lines = int(input())
matrix = []
for row in range(num_lines):
	new_row = []
	row_input = input().split()
	for num in row_input:
		new_row.append(int(num))
	matrix.append(new_row)
diag1 = 0
diag2 = 0
for (row, col) in enumerate(range(num_lines), 0):
	diag1 += matrix[row][col]
	diag2 += matrix[-row][col - 1]
print(abs(diag1 - diag2))


n = int(input())
matrix = []
for _ in range(n):
	line = list(map(int, input().split(' ')))
	matrix.append(line)
(diag_a, diag_b) = ([], [])
for (a, b) in enumerate(range(len(matrix), 0, -1)):
	row = matrix[a]
	b = b - 1
	diag_a.append(row[a])
	diag_b.append(row[b])
print(abs(sum(diag_a) - sum(diag_b)))


import sys
tokens = sys.stdin.read().split('\n')
n = int(tokens.pop(0))
v = []
for line in tokens:
	v.append([int(t) for t in line.split()])
mjs = mns = 0
for i in range(0, n):
	mjs = mjs + v[i][i]
	mns = mns + v[n - i - 1][i]
diff = mjs - mns
if diff < 0:
	diff = -1 * diff
print(diff)


t = int(input())
arr = []
l = 0
r = t - 1
d1 = 0
d2 = 0
for a in range(t):
	arr = list(map(int, input().split()))
	d1 += arr[l]
	d2 += arr[r]
	l += 1
	r -= 1
print(abs(d1 - d2))


ans = 0
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	b = a[i][i] - a[i][n - i - 1]
	ans += b
print(abs(ans))


n = int(input())
matrix = []
for i in range(n):
	row = list(map(int, input().split(' ')))
	matrix.append(row)
adjDiagonalOne = 0
sumDiagonalOne = 0
for j in range(len(matrix)):
	value = matrix[j][adjDiagonalOne]
	adjDiagonalOne += 1
	sumDiagonalOne += value
adjDiagonalTwo = len(matrix[0]) - 1
sumDiagonalTwo = 0
for j in range(len(matrix)):
	value = matrix[j][adjDiagonalTwo]
	adjDiagonalTwo -= 1
	sumDiagonalTwo += value
print(abs(sumDiagonalOne - sumDiagonalTwo))


matrixSize = int(input())
numMatrix = []
for i in range(1, matrixSize + 1):
	numMatrix.append(input().split())

def sumDiagonals(size, matrix):
	diagonal1 = 0
	diagonal2 = 0
	for i in range(size):
		diagonal1 += int(matrix[i][i])
		diagonal2 += int(matrix[i][len(matrix[i]) - 1 - i])
	return abs(diagonal1 - diagonal2)
print(sumDiagonals(matrixSize, numMatrix))


def matrixify(N):
	matrix = [[0 for x in range(N)] for x in range(N)]
	for n in range(N):
		matrix[n] = input().split()
	return matrix

def diag(N, s, matrix):
	sum = 0
	for n in range(N):
		if s:
			sum += int(matrix[n][n])
		else:
			sum += int(matrix[n][N - 1 - n])
	return sum
N = int(input())
A = matrixify(N)
dif = abs(diag(N, 1, A) - diag(N, 0, A))
print(dif)


n = int(input())
(d1, d2) = (0, 0)
for i in range(n):
	arr = list(map(int, input().split()))
	d1 += arr[i]
	d2 += arr[n - i - 1]
print(abs(d2 - d1))


n = int(input())
m = list()
s1 = 0
s2 = 0
for i in range(0, n):
	l = [int(el) for el in input().split()]
	s1 += l[i]
	s2 += l[n - 1 - i]
d = s1 - s2
if d < 0:
	d = -d
print(d)


matrixSize = int(input())
matrix = []
for ix in range(matrixSize):
	matrix.append(list(map(int, input().split(' '))))
d1 = 0
d2 = 0
for ix in range(matrixSize):
	d1 += matrix[ix][ix]
	d2 += matrix[ix][matrixSize - 1 - ix]
print(abs(d1 - d2))


import math
N = input()
N = int(N)
matrix = []
for i in range(0, N):
	mat = []
	k = input()
	k = k.split()
	for j in range(0, N):
		mat.append(int(k[j]))
	matrix.append(mat)
sum1 = 0
for i in range(0, N):
	sum1 = sum1 + matrix[i][i]
row = 0
col = N - 1
sum2 = 0
while row < N and col > -1:
	sum2 = sum2 + matrix[row][col]
	row = row + 1
	col = col - 1
print(abs(sum1 - sum2))


N = int(input())
sum1 = 0
sum2 = 0
for i in range(0, N):
	a = input().split(' ')
	sum1 = sum1 + int(a[i])
	sum2 = sum2 + int(a[N - i - 1])
print(abs(sum1 - sum2))


n = int(input())
(diag1, diag2) = (0, 0)
for i in range(n):
	x = list(map(int, input().split(' ')))
	diag1 = diag1 + x[i]
	diag2 = diag2 + x[n - 1 - i]
x = diag1 - diag2
if x < 0:
	x = -x
print(x)


N = int(input())
m = []
a = b = 0
for i in range(N):
	m.append(input().split())
	a += int(m[i][i])
	b += int(m[i][-i - 1])
print(abs(a - b))


n = int(input())
a = []
for i in range(n):
	a.append([int(i) for i in input().split(' ')])
(d1, d2) = (0, 0)
for i in range(n):
	d1 += a[i][i]
	d2 += a[i][n - i - 1]
print(abs(d1 - d2))


inp = int(input())
inpp = []
for i in range(0, inp):
	m = input().rstrip().split(' ')
	inpp.append(m)
one = 0
two = 0
for i in range(0, inp):
	one += int(inpp[i][i])
	two += int(inpp[i][inp - i - 1])
k = one - two
if k > 0:
	print(k)
else:
	print(k * -1)


N = int(input())
list2 = []
for i in range(0, N):
	list1 = []
	numbers = input().split()
	for j in range(0, N):
		list1.append(int(numbers[j]))
	list2.append(list1)
diagonal_1 = 0
diagonal_2 = 0
for k in range(0, N):
	diagonal_1 += list2[k][k]
row = N - 1
for l in range(0, N):
	diagonal_2 += list2[l][row]
	row -= 1
print(abs(diagonal_1 - diagonal_2))


dimension = int(input())
array = [[0 for i in range(dimension)] for j in range(dimension)]
for i in range(dimension):
	row = input().split()
	for y in range(dimension):
		array[i][y] = int(row[y])
left = 0
for i in range(dimension):
	left = left + array[i][i]
right = 0
for i in range(dimension):
	right = right + array[i][dimension - i - 1]
print(abs(left - right))


import sys
n = int(sys.stdin.readline())
left_sum = 0
right_sum = 0
for i in range(0, n):
	row = sys.stdin.readline()
	row_parts = row.strip().split()
	left_sum += int(row_parts[i])
	right_sum += int(row_parts[n - i - 1])
print(abs(left_sum - right_sum))


def diag_diff(matrix):
	(left_diag, right_diag) = (0, 0)
	for (i, row) in enumerate(matrix):
		left_diag += matrix[i][i]
		right_diag += matrix[i][len(row) - i - 1]
	abs_diff = abs(left_diag - right_diag)
	return abs_diff

def main():
	N = int(input())
	matrix = []
	for i in range(N):
		matrix.append([int(item) for item in input().split(' ')])
	print(diag_diff(matrix))
main()


n = int(input())
m = []
(a, b) = (0, 0)
for _ in range(n):
	m.append([int(x) for x in input().split()])
for i in range(n):
	a += m[i][i]
	b += m[i][n - i - 1]
print(abs(a - b))


n = int(input())
tl_br = 0
bl_tr = 0
for j in range(n):
	row = list(map(int, input().split()))
	tl_br += row[j]
	bl_tr += row[n - j - 1]
diff = abs(tl_br - bl_tr)
print(diff)


(left_right, right_left) = (0, 0)
matrix = []
matrix_s = int(input().strip())
while matrix_s > 0:
	matrix.append(list(map(int, input().strip().split(' '))))
	matrix_s -= 1
for i in range(0, len(matrix)):
	left_right += matrix[i][i]
for i in range(len(matrix) - 1, -1, -1):
	right_left += matrix[i][len(matrix) - 1 - i]
print(abs(right_left - left_right))


n = int(input())
a = []
diag1 = 0
diag2 = 0
for i in range(0, n):
	a.append(input().split())
	diag1 += int(a[i][i])
	diag2 += int(a[i][n - i - 1])
print(abs(diag1 - diag2))


import sys
n = int(input())
mat = []
mainDiagSum = 0
oppDiagSum = 0
for P in range(n):
	temp = []
	temp = list(map(int, sys.stdin.readline().split()))
	mainDiagSum = mainDiagSum + temp[P]
	oppDiagSum = oppDiagSum + temp[n - 1 - P]
	mat.append(temp)
print(abs(oppDiagSum - mainDiagSum))


n = int(input())
matrixList = []
leftDiagnalSum = 0
rightDiagnalSum = 0
for i in range(0, n):
	listOfInput = []
	listOfInput = input().split(' ')
	matrixList.append(listOfInput)
for i in range(0, n):
	leftDiagnalSum = leftDiagnalSum + int(matrixList[i][i])
for i in range(0, n):
	rightDiagnalSum = rightDiagnalSum + int(matrixList[i][n - 1 - i])
diagnalDifference = abs(leftDiagnalSum - rightDiagnalSum)
print(diagnalDifference)


mat = [[int(j) for j in input().split()] for i in range(int(input()))]
print(abs(sum((mat[i][i] for i in range(len(mat)))) - sum((mat[i][len(mat) - i - 1] for i in range(len(mat))))))


n = int(input())
d1 = d2 = 0
for i in range(n):
	m = map(int, input().split())
	for (j, x) in enumerate(m):
		if i == j:
			d1 += x
		if n - j - 1 == i:
			d2 += x
print(abs(d1 - d2))


n = int(input())
mat = []

def result(x, y):
	res1 = 0
	res2 = 0
	for i in range(len(x)):
		res1 += int(x[i])
	for x in range(len(y)):
		res2 += int(y[x])
	return abs(res1 - res2)
for i in range(n):
	wrkmat = []
	wrkmat = input().split()
	mat.append(wrkmat)
diag = [row[i] for (i, row) in enumerate(mat)]
invdiag = [row[-i - 1] for (i, row) in enumerate(mat)]
print(result(diag, invdiag))


import math
size = int(input())
matrix = [list(map(int, input().split())) for _ in range(size)]
(sum1, sum2) = (0, 0)
for row in range(size):
	for col in range(size):
		if row == col:
			sum1 += matrix[row][col]
		if row == size - col - 1:
			sum2 += matrix[row][col]
print(abs(sum1 - sum2))


matrixSize = int(input())
left = 0
right = matrixSize - 1
leftOut = 0
rightOut = 0
tokens = [1, 2, 3, 4]
for x in range(0, matrixSize):
	currLine = input()
	tokens = currLine.split(' ')
	leftOut += int(tokens[left])
	left += 1
	rightOut += int(tokens[right])
	right -= 1
print(abs(leftOut - rightOut))


import sys
n = int(sys.stdin.readline())
sum1 = 0
sum2 = 0
for i in range(n):
	row = [int(elem) for elem in sys.stdin.readline().split()]
	sum1 = sum1 + row[i]
	sum2 = sum2 + row[n - i - 1]
print(abs(sum1 - sum2))


num_rows = int(input())
j = 0
list1 = []
for i in range(0, num_rows):
	list1.append(input().split())
sum1 = 0
sum2 = 0
for i in range(0, num_rows):
	sum1 += int(list1[i][i])
for i in range(num_rows - 1, -1, -1):
	sum2 += int(list1[num_rows - 1 - i][i])
print(abs(sum1 - sum2))


n = int(input())
m = [list(map(int, input().split())) for _ in range(n)]
a = b = j = 0
for i in range(n):
	a += m[i][j]
	b += m[i][-(j + 1)]
	j += 1
print(abs(a - b))


firstTotal = 0
secondTotal = 0
n = int(input())
for x in range(n):
	line = input()
	firstTotal += int(line.split(' ')[x])
	secondTotal += int(line.split(' ')[n - x - 1])
print(abs(firstTotal - secondTotal))