N,K=list(map(int,input().split()))

MAP=[list(map(int,input().split())) for i in range(N)]



start = 2*N+1

goal = 2*N+2

V=2*N+5



EDGE=[[[0,0] for j in range(V)] for i in range(V)]



# 0 ～ N : 縦

# N+1 ～　2*N : 横

# 2*N+1 : start

# 2*N+2 : goal







for i in range(N):

    EDGE[start][i]=[K,0]

    EDGE[N+i][goal]=[K,0]

    

for i in range(N):

    for j in range(N):

        EDGE[i][N+j]=[1,-MAP[i][j]]

        EDGE[N+j][i]=[0,MAP[i][j]]



EDGE[start][goal]=[float("inf"),0]





BACK=[-1]*V

LA=0



for flow in range(K*N):

    ANS=[float("inf")]*V

    ANS[start]=0



    for rep in range(V):

        flag=0

        for fr in range(V):

            for to in range(V):             

                c,d=EDGE[fr][to]

                if c>0 and ANS[to]>ANS[fr]+d:

                    ANS[to]=ANS[fr]+d

                    flag=1

                    BACK[to]=fr

        if flag==0:

            break



    if ANS[goal]==0:

        break

 

    LA+=ANS[goal]

 

    NOW=goal

    while NOW!=start:

        fr=BACK[NOW]

        EDGE[fr][NOW][0]-=1

        EDGE[NOW][fr][0]+=1



        NOW=fr

 

print((-LA))

ALIST=[["."]*N for i in range(N)]



for i in range(N):

    for j in range(N):

        if EDGE[i][N+j][0]==0:

            ALIST[i][j]="X"



for alist in ALIST:

    print(("".join(alist)))
N,K=list(map(int,input().split()))

MAP=[list(map(int,input().split())) for i in range(N)]



start = 2*N+1

goal = 2*N+2

V=2*N+5



EDGE=[[[0,0] for j in range(V)] for i in range(V)]



# 0 ～ N : 縦

# N+1 ～　2*N : 横

# 2*N+1 : start

# 2*N+2 : goal



for i in range(N):

    EDGE[start][i]=[K,0]

    EDGE[N+i][goal]=[K,0]

    

for i in range(N):

    for j in range(N):

        EDGE[i][N+j]=[1,10**9-MAP[i][j]]

        EDGE[N+j][i]=[0,-(10**9-MAP[i][j])]



EDGE[start][goal]=[float("inf"),10**9]



BACK=[-1]*V

LA=0

 

import heapq

 

for flow in range(K*N):

    ANS=[float("inf")]*V

    Q=[(0,start)]

    ANS[start]=0

 

    while Q:

        time,fr=heapq.heappop(Q)

        if time>ANS[fr]:

            continue



        for to in range(V):

            c,d = EDGE[fr][to]

            if c>0 and ANS[to]>ANS[fr]+d:

                ANS[to]=ANS[fr]+d

                BACK[to]=fr

                heapq.heappush(Q,(ANS[to],to))



    LA+=ANS[goal]

 

    NOW=goal

    while NOW!=start:

        fr=BACK[NOW]

        EDGE[fr][NOW][0]-=1

        EDGE[NOW][fr][0]+=1



        NOW=fr

 

print((K*N*10**9-LA))

ALIST=[["."]*N for i in range(N)]



for i in range(N):

    for j in range(N):

        if EDGE[i][N+j][0]==0:

            ALIST[i][j]="X"



for alist in ALIST:

    print(("".join(alist)))
N, K = list(map(int, input().split()))
MAP = [list(map(int, input().split())) for i in range(N)]
start = 2 * N + 1
goal = 2 * N + 2
V = 2 * N + 5
EDGE = [[[0, 0] for j in range(V)] for i in range(V)]
# 0 ～ N : 縦
# N+1 ～　2*N : 横
# 2*N+1 : start
# 2*N+2 : goal
for i in range(N):
    EDGE[start][i] = [K, 0]
    EDGE[N + i][goal] = [K, 0]
for i in range(N):
    for j in range(N):
        EDGE[i][N + j] = [1, -MAP[i][j]]
        EDGE[N + j][i] = [0, MAP[i][j]]
EDGE[start][goal] = [float("inf"), 0]
BACK = [-1] * V
LA = 0
for flow in range(K * N):
    ANS = [float("inf")] * V
    ANS[start] = 0
    for rep in range(V):
        flag = 0
        for fr in range(V):
            for to in range(V):
                c, d = EDGE[fr][to]
                if c > 0 and ANS[to] > ANS[fr] + d:
                    ANS[to] = ANS[fr] + d
                    flag = 1
                    BACK[to] = fr
        if flag == 0:
            break
    if ANS[goal] == 0:
        break
    LA += ANS[goal]
    NOW = goal
    while NOW != start:
        fr = BACK[NOW]
        EDGE[fr][NOW][0] -= 1
        EDGE[NOW][fr][0] += 1
        NOW = fr
print((-LA))
ALIST = [["."] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        if EDGE[i][N + j][0] == 0:
            ALIST[i][j] = "X"
for alist in ALIST:
    print(("".join(alist)))

N, K = list(map(int, input().split()))
MAP = [list(map(int, input().split())) for i in range(N)]
start = 2 * N + 1
goal = 2 * N + 2
V = 2 * N + 5
EDGE = [[[0, 0] for j in range(V)] for i in range(V)]
# 0 ～ N : 縦
# N+1 ～　2*N : 横
# 2*N+1 : start
# 2*N+2 : goal
for i in range(N):
    EDGE[start][i] = [K, 0]
    EDGE[N + i][goal] = [K, 0]
for i in range(N):
    for j in range(N):
        EDGE[i][N + j] = [1, 10**9 - MAP[i][j]]
        EDGE[N + j][i] = [0, -(10**9 - MAP[i][j])]
EDGE[start][goal] = [float("inf"), 10**9]
BACK = [-1] * V
LA = 0
import heapq

for flow in range(K * N):
    ANS = [float("inf")] * V
    Q = [(0, start)]
    ANS[start] = 0
    while Q:
        time, fr = heapq.heappop(Q)
        if time > ANS[fr]:
            continue
        for to in range(V):
            c, d = EDGE[fr][to]
            if c > 0 and ANS[to] > ANS[fr] + d:
                ANS[to] = ANS[fr] + d
                BACK[to] = fr
                heapq.heappush(Q, (ANS[to], to))
    LA += ANS[goal]
    NOW = goal
    while NOW != start:
        fr = BACK[NOW]
        EDGE[fr][NOW][0] -= 1
        EDGE[NOW][fr][0] += 1
        NOW = fr
print((K * N * 10**9 - LA))
ALIST = [["."] * N for i in range(N)]
for i in range(N):
    for j in range(N):
        if EDGE[i][N + j][0] == 0:
            ALIST[i][j] = "X"
for alist in ALIST:
    print(("".join(alist)))

-        EDGE[i][N + j] = [1, -MAP[i][j]] -        EDGE[N + j][i] = [0, MAP[i][j]] -EDGE[start][goal] = [float("inf"), 0] +        EDGE[i][N + j] = [1, 10**9 - MAP[i][j]] +        EDGE[N + j][i] = [0, -(10**9 - MAP[i][j])] +EDGE[start][goal] = [float("inf"), 10**9] +import heapq + +    Q = [(0, start)] -    for rep in range(V): -        flag = 0 -        for fr in range(V): -            for to in range(V): -                c, d = EDGE[fr][to] -                if c > 0 and ANS[to] > ANS[fr] + d: -                    ANS[to] = ANS[fr] + d -                    flag = 1 -                    BACK[to] = fr -        if flag == 0: -            break -    if ANS[goal] == 0: -        break +    while Q: +        time, fr = heapq.heappop(Q) +        if time > ANS[fr]: +            continue +        for to in range(V): +            c, d = EDGE[fr][to] +            if c > 0 and ANS[to] > ANS[fr] + d: +                ANS[to] = ANS[fr] + d +                BACK[to] = fr +                heapq.heappush(Q, (ANS[to], to)) -print((-LA)) +print((K * N * 10**9 - LA))