Input_data with open Users oleksandr shubenkov Desktop Input txt as fo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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:]
array = [[0]*N for i in range(N)]
for row_param, column_param in Input_data:
for row_index, row in enumerate(array):
for column_index, elem in enumerate(row):
if row_index == row_param or column_index == column_param:
array[row_index][column_index] += 1
with open('/Users/oleksandr.shubenkov/Desktop/Output.txt', 'a') as f:
for res_row in array:
for res_elem in res_row:
f.writelines(str(res_elem) + ' ')
f.writelines('\n')