import sys
n=int(sys.stdin.readline())
inf=int(1e9)
w=[[inf for _ in range(n)]for _ in range(n)]
for i in range(n):
tmp=list(map(int,sys.stdin.readline().split()))
for idx,item in enumerate(tmp):
if(item==0 and not(idx==i)):
w[i][idx]=inf
else:
w[i][idx]=item
visited=[0]*n
visited[0]=1
min_profit=inf
def bound(start,cur_score):
global n,w,min_profit,visited
bound=cur_score
bound+=min(w[start][1:start]+w[start][start+1:])
for i in range(1,len(visited)):
if(visited[i]==0):
tmp=inf
for j in range(len(w[i])):
if(j!=start and j!=i):
tmp=min(tmp,w[i][j])
bound+=tmp
if(bound<min_profit):
return True
else:
return False
def TSP(start,rad,cur_score):
global n,w,min_profit,visited
if(not(cur_score) or bound(start,cur_score)):
if(rad==(n-1)):
tmp=cur_score
for i in range(len(visited)):
if(visited[i]==0):
tmp+=w[start][i]
tmp+=w[i][0]
min_profit=min(min_profit,tmp)
return
for idx,weight in enumerate(w[start]):
if(weight!=0 and weight!=inf and visited[idx]==0):
visited[idx]=1
TSP(idx,rad+1,cur_score+weight)
visited[idx]=0
TSP(0,1,0)
print(min_profit)
aW1wb3J0IHN5cwpuPWludChzeXMuc3RkaW4ucmVhZGxpbmUoKSkKaW5mPWludCgxZTkpCnc9W1tpbmYgZm9yIF8gaW4gcmFuZ2UobildZm9yIF8gaW4gcmFuZ2UobildCmZvciBpIGluIHJhbmdlKG4pOgogICAgdG1wPWxpc3QobWFwKGludCxzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpKSkKICAgIGZvciBpZHgsaXRlbSBpbiBlbnVtZXJhdGUodG1wKToKICAgICAgICBpZihpdGVtPT0wIGFuZCBub3QoaWR4PT1pKSk6CiAgICAgICAgICAgIHdbaV1baWR4XT1pbmYKICAgICAgICBlbHNlOgogICAgICAgICAgICB3W2ldW2lkeF09aXRlbQoKdmlzaXRlZD1bMF0qbgp2aXNpdGVkWzBdPTEKbWluX3Byb2ZpdD1pbmYKCmRlZiBib3VuZChzdGFydCxjdXJfc2NvcmUpOgogICAgZ2xvYmFsIG4sdyxtaW5fcHJvZml0LHZpc2l0ZWQKICAgIGJvdW5kPWN1cl9zY29yZQogICAgYm91bmQrPW1pbih3W3N0YXJ0XVsxOnN0YXJ0XSt3W3N0YXJ0XVtzdGFydCsxOl0pCiAgICBmb3IgaSBpbiByYW5nZSgxLGxlbih2aXNpdGVkKSk6CiAgICAgICAgaWYodmlzaXRlZFtpXT09MCk6CiAgICAgICAgICAgIHRtcD1pbmYKICAgICAgICAgICAgZm9yIGogaW4gcmFuZ2UobGVuKHdbaV0pKToKICAgICAgICAgICAgICAgIGlmKGohPXN0YXJ0IGFuZCBqIT1pKToKICAgICAgICAgICAgICAgICAgICB0bXA9bWluKHRtcCx3W2ldW2pdKQogICAgICAgICAgICBib3VuZCs9dG1wCiAgICBpZihib3VuZDxtaW5fcHJvZml0KToKICAgICAgICByZXR1cm4gVHJ1ZQogICAgZWxzZToKICAgICAgICByZXR1cm4gRmFsc2UKCmRlZiBUU1Aoc3RhcnQscmFkLGN1cl9zY29yZSk6CiAgICBnbG9iYWwgbix3LG1pbl9wcm9maXQsdmlzaXRlZAogICAgaWYobm90KGN1cl9zY29yZSkgb3IgYm91bmQoc3RhcnQsY3VyX3Njb3JlKSk6CiAgICAgICAgaWYocmFkPT0obi0xKSk6CiAgICAgICAgICAgIHRtcD1jdXJfc2NvcmUKICAgICAgICAgICAgZm9yIGkgaW4gcmFuZ2UobGVuKHZpc2l0ZWQpKToKICAgICAgICAgICAgICAgIGlmKHZpc2l0ZWRbaV09PTApOgogICAgICAgICAgICAgICAgICAgIHRtcCs9d1tzdGFydF1baV0KICAgICAgICAgICAgICAgICAgICB0bXArPXdbaV1bMF0KICAgICAgICAgICAgbWluX3Byb2ZpdD1taW4obWluX3Byb2ZpdCx0bXApCiAgICAgICAgICAgIHJldHVybgogICAgICAgIGZvciBpZHgsd2VpZ2h0IGluIGVudW1lcmF0ZSh3W3N0YXJ0XSk6CiAgICAgICAgICAgIGlmKHdlaW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