def main():
    table:list = []
    # get the number of rows and columns 
    rows, columns = list(map(int, input().split()))
    # get cost list 
    costList = list(map(int, input().split()))
    for i in range(rows):
        vec = list(map(int, input().split()))
        table.append(vec)
    # elements that have been covered already 
    coveredList = set()
    xValues:list = [0] * rows
    yValues:list = [0] * columns
    for i in range(rows):
        if i not in coveredList:
            minValue = float("INF")
            index = 0
            for j in range(columns):
                if table[i][j] == 1 and costList[j] < minValue:
                    minValue = costList[j]
                    index = j
            # update the x and y values 
            xValues[i] = minValue
            yValues[index] = 1
        # decrement the costValues
        for j in range(columns):
            if table[i][j] == 1:
                costList[j] -= xValues[i]
        # get the covered set
        for j in range(rows):
            if table[j][index] == 1:
                coveredList.add(j)
    print(*yValues)
    print(*xValues)
main()