from numpy import array Input_data with open Users oleksandr shubenkov

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from numpy import array
Input_data = []
with open('/Users/oleksandr.shubenkov/Desktop/Input.txt', 'r') as f:
for line in f:
Input_data.append([int(x) for x in line.split()])
N, M = Input_data[0]
Input_data = Input_data[1:]
data = array([[0]*N for i in range(N)])
for row_index, column_index in Input_data:
data[row_index]+=1
data[:, column_index]+=1
data[row_index, column_index] -=1
with open('/Users/oleksandr.shubenkov/Desktop/Output.txt', 'a') as f:
for res_row in data:
for res_elem in res_row:
f.writelines(str(res_elem) + ' ')
f.writelines('\n')