using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoderMake.AGC044
{
    class AGC044B
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var pnn = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();

            var map = new int[n, n];
            int ans = 0;
            foreach (int p in pnn)
            {
                int x = (p - 1) % n;
                int y = (p - 1) / n;
                map[x, y] = 1;
                if (x != 0 && x != n - 1 && y != 0 && y != n - 1)
                {
                    List<int[]> root = new List<int[]>();
                    root.Add(new int[] { x, y });
                    var rootmap = new int[n, n];
                    if (map[x - 1, y] == 1)
                    {
                        List<int[]> pos = new List<int[]>();
                        pos.Add(new int[] { x - 1, y });
                        root.AddRange(makeNoMemberMap(map, pos, pos));
                    }
                    if (map[x, y - 1] == 1)
                    {
                        List<int[]> pos = new List<int[]>();
                        pos.Add(new int[] { x, y - 1 });
                        root.AddRange(makeNoMemberMap(map, pos, pos));
                    }
                    if (map[x + 1, y] == 1)
                    {
                        List<int[]> pos = new List<int[]>();
                        pos.Add(new int[] { x + 1, y });
                        root.AddRange(makeNoMemberMap(map, pos, pos));
                    }
                    if (map[x, y + 1] == 1)
                    {
                        List<int[]> pos = new List<int[]>();
                        pos.Add(new int[] { x, y + 1 });
                        root.AddRange(makeNoMemberMap(map, pos, pos));
                    }
                    root.Distinct().ToList();
                    foreach (int[] did in root)
                    {
                        rootmap[did[0], did[1]] = 1;
                    }
                    ans += countHate(map, rootmap, root, 0);
                }

                Console.WriteLine(ans);
            }
        }

        static int countHate(int[,] map, int[,] rootmap, List<int[]> pos, int hate)
        {
            int n = map.GetLength(0);
            List<int[]> next = new List<int[]>();
            var nextMap = rootmap;
            foreach (int[] exp in pos)
            {
                if (exp[0] == 0 || exp[0] == n - 1 || exp[1] == 0 || exp[1] == n - 1)
                {
                    return hate;
                }
                if (rootmap[exp[0] - 1, exp[1]] == 0)
                {
                    next.Add(new int[] { exp[0] - 1, exp[1] });
                    if (map[exp[0] - 1, exp[1]] > 0)
                    {
                        List<int[]> nomem = new List<int[]>();
                        nomem.Add(new int[] { exp[0] - 1, exp[1] });
                        next.AddRange(makeNoMemberMap(map, nomem, nomem));
                    }
                }
                if (rootmap[exp[0] + 1, exp[1]] == 0)
                {
                    next.Add(new int[] { exp[0] + 1, exp[1] });
                    if (map[exp[0] + 1, exp[1]] > 0)
                    {
                        List<int[]> nomem = new List<int[]>();
                        nomem.Add(new int[] { exp[0] + 1, exp[1] });
                        next.AddRange(makeNoMemberMap(map, nomem, nomem));
                    }
                }
                if (rootmap[exp[0], exp[1] - 1] == 0)
                {
                    next.Add(new int[] { exp[0], exp[1] - 1 });
                    if (map[exp[0], exp[1] - 1] > 0)
                    {
                        List<int[]> nomem = new List<int[]>();
                        nomem.Add(new int[] { exp[0], exp[1] - 1 });
                        next.AddRange(makeNoMemberMap(map, nomem, nomem));
                    }
                }
                if (rootmap[exp[0], exp[1] + 1] == 0)
                {
                    next.Add(new int[] { exp[0], exp[1] + 1 });
                    if (map[exp[0], exp[1] + 1] > 0)
                    {
                        List<int[]> nomem = new List<int[]>();
                        nomem.Add(new int[] { exp[0], exp[1] + 1 });
                        next.AddRange(makeNoMemberMap(map, nomem, nomem));
                    }
                }
            }
            next.Distinct().ToList();
            foreach (int[] did in next)
            {
                rootmap[did[0], did[1]] = 1;
            }
            return countHate(map, nextMap, next, hate + 1);
        }

        static List<int[]> makeNoMemberMap(int[,] map, List<int[]> pos, List<int[]> nomem)
        {
            var NoMemberMap = nomem;
            List<int[]> next = new List<int[]>();
            int n = map.GetLength(0);
            foreach (int[] exp in pos)
            {
                if (exp[0] > 0 && map[exp[0] - 1, exp[1]] > 0 && !pos.Contains(new int[] { exp[0] - 1, exp[1] }))
                {
                    next.Add(new int[] { exp[0] - 1, exp[1] });
                }
                if (exp[1] > 0 && map[exp[0], exp[1] - 1] > 0 && !pos.Contains(new int[] { exp[0], exp[1] - 1 }))
                {
                    next.Add(new int[] { exp[0], exp[1] - 1 });
                }
                if (exp[0] < n - 1 && map[exp[0] + 1, exp[1]] > 0 && !pos.Contains(new int[] { exp[0] + 1, exp[1] }))
                {
                    next.Add(new int[] { exp[0] + 1, exp[1] });
                }
                if (exp[1] < n - 1 && map[exp[0], exp[1] + 1] > 0 && !pos.Contains(new int[] { exp[0], exp[1] + 1 }))
                {
                    next.Add(new int[] { exp[0], exp[1] + 1 });
                }
            }
            if (next.Count > 0)
            {
                NoMemberMap.AddRange(next);
                NoMemberMap = makeNoMemberMap(map, next, NoMemberMap);
            }
            return NoMemberMap;
        }
    }
}
