@n = gets.to_i
@m = @n ** 2
pp = gets.split.map(&:to_i)

@a = Array.new(@m) do |i|
    x, y = i.divmod(@n)
    x = @n - x - 1 if x > @n - x - 1
    y = @n - y - 1 if y > @n - y - 1
    x < y ? x : y
end
@b = Array.new(@m, 1)
@c = [-@n, -1, 1, @n]

def dfs(pos)
    s = @a[pos] + @b[pos]

    @c.each do |e|
        e += pos
        if 0 <= e && e < @m && @a[e] > s
            @a[e] = s
            dfs(e)
        end
    end
end

ans = 0
pp.each do |pos|
    pos -= 1
    ans += @a[pos]
    @b[pos] = 0
    s = @a[pos]
    dfs(pos)
end

p ans