with open INPUT TXT as inf int for in inf readline strip split if for

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
with open('INPUT.TXT') as inf:
n, m = [int(i) for i in inf.readline().strip().split()]
if m > n:
n, m = m, n
d = []
for i in range(2 ** n):
d.append([0] * (2 ** n))
for i in range(2 ** n - 1):
for j in range(i, 2 ** n - 1):
i_bin = bin(i)[2:]
while len(i_bin) < n:
i_bin = '0' + i_bin
j_bin = bin(j)[2:]
while len(j_bin) < n:
j_bin = '0' + j_bin
for k in range(n - 1):
if i_bin[k] == j_bin[k] and i_bin[k + 1] == j_bin[k + 1]:
d[i][j] = 1
break
with open('OUTPUT.TXT', 'w') as outf:
outf.write(str(d))
outf.close()