#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#define LL long long
#define inf 0x3f3f3f3f
#define mod 1e9+7
using namespace std;
int N=0,num=0,Arr[105][105],p[105];
struct Node{
int left,right,weight;
}Q[10005];
int find(int x){ return p[x]==x? x: p[x]=find(p[x]);}
bool cmp(Node x, Node y)
{
return x.weight<y.weight;
}
int Krusckal()
{
int ans=0,x=0,y=0;
int i=0;
for(i=0;i<N;i++) p[i]=i;
sort(Q,Q+num,cmp);
for(i=0;i<num;i++){
x=find(Q[i].left);//一定要find找到根节点,刚弄错的
y=find(Q[i].right);
if(x!=y){
ans+=Q[i].weight;
p[x]=y;
}
}
return ans;
}
int main()
{
int i=0,j=0;
scanf("%d",&N);
memset(Arr, inf, sizeof(Arr));
for(i=0;i<N;i++){
for(j=0;j<N;j++){
scanf("%d",&Arr[i][j]);
if(i<j){
Q[num].left=i;
Q[num].right=j;
Q[num].weight= Arr[i][j];
num++;
}
}
}
cout<<Krusckal()<<endl;
return 0;
}