#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
const ll maxV = 3e5;

struct Edge {
    ll to, cap, cost, rev;
};

vector< vector<Edge> > G;

void add_edge(ll from, ll to, ll cap, ll cost) {
    if (from < 0 || to < 0) return;
    G[from].push_back({to, cap, cost, (ll)G[to].size()});
    G[to].push_back({from, 0, -cost, (ll)G[from].size()-1});
}

ll dist[maxV], h[maxV] = {0}, prevV[maxV], prevE[maxV];
ll min_cost_flow(ll s, ll t, ll f, bool is_ford_first = false) {
    ll res = 0;
    while (f > 0) {
        fill(dist, dist+maxV, linf); dist[s] = 0;
        if (is_ford_first) {
            while (1) {
                bool is_update = false;
                rep(v, G.size()) {
                    if (dist[v] == linf) continue;
                    rep(i, G[v].size()) {
                        const Edge& e = G[v][i];
                        if (e.cap > 0 && dist[v] + e.cost < dist[e.to]) {
                            dist[e.to] = dist[v] + e.cost;
                            prevV[e.to] = v;
                            prevE[e.to] = i;
                            is_update = true;
                        }
                    }
                }
                if (!is_update) break;
            }
        }
        else {
            priority_queue<P, vector<P>, greater<P> > Q; Q.push({0, s});
            while ( !Q.empty() ) {
                P p = Q.top(); Q.pop();
                ll v = p.second;
                if (p.first > dist[v]) continue;
                for (ll i = 0; i < G[v].size(); ++i) {
                    Edge& e = G[v][i];
                    if (e.cap > 0 && dist[v]+e.cost+h[v]-h[e.to] < dist[e.to]) {
                        dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
                        prevV[e.to] = v;
                        prevE[e.to] = i;
                        Q.push({dist[e.to], e.to});
                    }
                }
            }
        }
        rep(i, G.size()) h[i] += dist[i];
        if (dist[t] == linf) {
            throw res;
        }
        ll d = f;
        for (ll v = t; v != s; v = prevV[v]) {
            d = min(d, G[prevV[v]][prevE[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (ll v = t; v != s; v = prevV[v]) {
            Edge& e = G[prevV[v]][prevE[v]];
            e.cap -= d;
            G[e.to][e.rev].cap += d;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<vector<ll>> A(n, vector<ll>(n)); cin >> A;
    ll sum = 0;
    vector<ll> cnt(n, 0);
    rep(i, n) rep(j, i+1, n) {
        sum += min(A[i][j], A[j][i]);
        if (A[i][j] < A[j][i]) {
            cnt[i]++;
        }
        else {
            cnt[j]++;
        }
    }

    ll pos = -1;
    rep(i, n) {
        if (cnt[i] == 0) {
            assert(pos < 0);
            pos = i;
        }
    }
    if (pos >= 0) {
        ll m = linf;
        rep(i, n) {
            if (i == pos) continue;
            chmin(m, A[pos][i] - A[i][pos]);
        }
        // sum += m;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3288