-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path005_Diagonal_Difference.py
More file actions
50 lines (35 loc) · 942 Bytes
/
Copy path005_Diagonal_Difference.py
File metadata and controls
50 lines (35 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/python3
import math
import os
import random
import re
import sys
# The function is expected to return an INTEGER.
# The function accepts 2D_INTEGER_ARRAY arr as parameter.
#
def diagonalDifference(arr):
primal = list()
second = list()
sumpri = 0
sumsec = 0
for i in range(0, len(arr)):
x = arr[i][i]
primal.append(x)
for i in range(0, len(arr)):
y = arr[i][-(i + 1)]
second.append(y)
for i in primal:
sumpri += i
for i in second:
sumsec += i
absolute = abs(sumpri - (sumsec))
return absolute
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
arr = []
for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))
result = diagonalDifference(arr)
fptr.write(str(result) + '\n')
fptr.close()