#include<stdio.h>
#include<math.h>
#include<stdlib.h>

typedef struct{
    int now[2500];
    int hate;
    int front,back,left,right;

}zaseki;

void zaseki_set(zaseki *z,int n){
    int i;
    for(i=1;i<=n*n;i++){
        z->now[i] = 1;
    }
}

void arugo(int n,int p,zaseki *z){
    int i,mleft,mright,h;
    z->now[p] = 0; //riseki
    z->front = z->back = z->left = z->right = 0;
    //front
    i = p;
    i = i-n;
    while(i>0){
        if(z->now[i]==1)z->front++;
        i = i-n;   
    }
    
    //back
    i = p;
    i = i+n;
    while(i<=n*n){
        if(z->now[i]==1)z->back++;
        i = i+n;
    }
    
    
    //left
    i = p%n;
    mleft = p - i + 1;
    i = p-1;
    while (i>=mleft)
    {
        if(z->now[i]==1)z->left++;
        i--;
    }
        
    //right
    i = p%n;
    mright = p + n - i;
    i = p+1;
    while (i<=mright)
    {
        if(z->now[i]==1)z->right++;
        i++;
    }
    

    h = z->front;
    if(h>z->back)h = z->back;
    else if(h>z->left)h = z->left;
    else if(h>z->right)h = z->right;
    z->hate +=h;
}

int main(){
    int i,N,P,n;
    zaseki *z;
    z = (zaseki*)malloc(sizeof(zaseki));
    z->hate = 0;
    scanf("%d",&N);
    //z->now = malloc(N*N);
    zaseki_set(z,N);
    for(i=0;i<N*N-1;i++){
        scanf("%d ",&P);
        arugo(N,P,z);
        printf("%d ",z->hate);
        /*if(i==9){
            printf(" %d  %d  %d  %d   ",z->front,z->back,z->left,z->right);
        }*/
    }
        
        scanf("%d",&P);
        arugo(N,P,z);
        

    printf("%d\n",z->hate);
    return 0;
}