n = gets.to_i
pp = gets.split.map{|e| e.to_i - 1}

a = Array.new(n) {Array.new(n, true)}

ans = 0
pp.each do |e|
    x, y = e.divmod(n)
    z = x * n
    sum = n + 1

    s = 0
    n.times do |i|
        if z + i == e
            sum = s if sum > s
            s = 0
        elsif a[x][i]
            s += 1
        end
    end
    sum = s if sum > s

    s = 0
    n.times do |i|
        if y + n * i == e
            sum = s if sum > s
            s = 0
        elsif a[i][y]
            s += 1
        end
    end
    sum = s if sum > s
    ans += sum
    a[x][y] = false
end

p ans