#include <bits/stdc++.h>
using namespace std;
using ll = long long;

using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int ,int>;
using vpii = vector<pair<int, int>>;
using pipii = pair<int, pii>;

#define sz(x) (x.size())

const int M = 41;


const int INF = 1e9 + 7;

using ld = long double;
const ld PI = M_PIl;

template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x = 0, T y = 0) : x(x), y(y) {}
    bool operator==(P p) const { return x == p.x && y == p.y; }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator/(ld o) const { return P(x/o, y/o); }
    T cross(P p) const { return x * p.y - y * p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    ld dist() const { return sqrtl(dist2()); }
    ld dist2() const { return x*x+y*y; }
    P unit() const { return *this / dist(); }
    bool operator<(P p) const { return tie(x, y) < tie(p.x, p.y); }
};

using P = Point<ld>;

vector<P> convexHull(vector<P> pts) {
    if(sz(pts) <= 1) return pts;
    sort(pts.begin(), pts.end());
    vector<P> h(sz(pts) + 1);
    int s = 0, t = 0;
    for(int it = 2; it--; s = --t, reverse(pts.begin(), pts.end())) {
        for(P p : pts) {
            while(t >= s + 2 && h[t-2].cross(h[t-1], p) <= 0) t--;
            h[t++] = p;
        }
    }
    return {h.begin(), h.begin() + t - (t == 2 && h[0] == h[1])};
}

ld polygonArea2(vector<P> &v) {
    ld a = v.back().cross(v[0]);
    for(int i = 0; i < sz(v)-1; i++) {
        a += v[i].cross(v[i+1]);
    }
    return a;
}



void solve() {
    int n;
    cin >> n;
    vvi a(n, vi(n));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    int m = n * M;
    vvi b(m, vi(m));
    for(int i = 0; i < m; i++) {
        for(int j = 0; j < m; j++) {
            b[i][j] = a[i%n][j%n];
        }
    }
    
    // vvi right(n, vi(n));
    // vvi down(n, vi(n));
    vvi costs(M, vi(M, INF));

    for(int sx = 0; sx < n; sx++) {
        for(int sy = 0; sy < n; sy++) {
            priority_queue<pipii, vector<pipii>, greater<pipii>> q;
            vvi vis(m, vi(m));
            vvi dist(m, vi(m, INF));
            
            int X = sx + M/2 * n;
            int Y = sy + M/2 * n;
            dist[X][Y] = 0;
            q.push({0,{X, Y}});

            while(!q.empty()) {
                auto [x, y] = q.top().second;
                q.pop();
                if(vis[x][y]) continue;
                vis[x][y] = true;
                for(int dx = -1; dx <= 1; dx++) {
                    for(int dy = -1; dy <= 1; dy++) {
                        if(abs(dx) + abs(dy) != 1) continue;
                        int c = x + dx;
                        int d = y + dy;
                        if(c < 0 || d < 0 || c >= m || d >= m) continue;
                        if(vis[c][d]) continue;
                        int nd = dist[x][y] + 1 + abs(b[x][y] - b[c][d]);
                        // cerr << "nd = " << nd << endl;
                        if(dist[c][d] > nd) {
                            dist[c][d] = nd;
                            // vis[c][d] = true;
                            q.push({dist[c][d], {c, d}});
                        }
                    }
                }
            }

            for(int i = 0; i < M; i++) {
                for(int j = 0; j < M; j++) {
                    costs[i][j] = min(costs[i][j], dist[n*i+sx][n*j+sy]);                    
                }
            }
        }
    }

    int off = M/2;
    // vector<pair<double, double>> cost_per_unit;
    vector<P> pts;
    for(int i = 0; i < M; i++) {
        for(int j = 0; j < M; j++) {
            if(i == off && j == off) continue;
            int dx = i - off;
            int dy = j - off;
            // ld cost_per_unit = (double)costs[i][j] /(sqrt(dx*dx+dy*dy) * n);
            pts.push_back(P(dx, dy) / ((ld) costs[i][j] / n));
            // cost_per_unit.push_back({atan2(i-off, j-off), (double)costs[i][j] /(sqrt(dx*dx+dy*dy) * n)});
        }
    }
    // sort(cost_per_unit.begin(), cost_per_unit.end());
    // for(auto p : cost_per_unit) {
    //     cerr << p.first << ' ' << p.second << endl;
    // }

    vector<P> hull = convexHull(pts);

    ld area = polygonArea2(hull) / 2;
    cout << fixed << setprecision(0) << area * 1e40 << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}