# the given matrix
M = [
    [0.05, 0, 0.70, 0.60],
    [0.45, 0.50, 0.20, 0.25],
    [0.20, 0.35, 0.10, 0],
    [0.30, 0.15, 0, 0.15]
]

# 
# you may enumarate the columns and rows by the strings '00', '01', '10', and '11'
# int('011',2) returns the decimal value of the binary string '011'
#

#
# your solution is here
#
# the given matrix
M = [
    [0.05, 0, 0.70, 0.60],
    [0.45, 0.50, 0.20, 0.25],
    [0.20, 0.35, 0.10, 0],
    [0.30, 0.15, 0, 0.15]
]
print("Matrix M is")
for row in M:
    print(row)
print()

# the target matrix is K
# we create it and filled with zeros
K = []
for i in range(8):
    K.append([])
    for j in range(8):
        K[i].append(0)

# for each transition in M, we create four transitions in K, two of which are always zeros  
for col in ['00','01','10','11']:
    for row in ['00','01','10','11']:
        prob = M[int(col,2)][int(row,2)]
        # second bit is 0
        newcol = col[0]+'0'+col[1]
        newrow = row[0]+'0'+row[1]
        K[int(newcol,2)][int(newrow,2)] = prob
        # second bit is 1
        newcol = col[0]+'1'+col[1]
        newrow = row[0]+'1'+row[1]
        K[int(newcol,2)][int(newrow,2)] = prob
print("Matrix K is")
for row in K:
    print(row)        