import java.util.*;
import java.io.*;

public class ProbGen
{
   public static void main(String[] args) throws Exception
   {
      String     filename = args.length > 1 ? args[1] : "Asg.in";
      PrintWriter output   = new PrintWriter(new File(filename));
      int        size = args.length > 0 ? Integer.parseInt(args[0]) : 7;
      int      []work = new int[size*size];
      int        row, col, k;

      for ( k = 0; k < work.length; k++ )
         work[k] = k+1;
      shuffle(work, work.length);
      output.println(size);
      for (row = k = 0; row < size; row++)
      {  for (col = 0; col < size; col++)
            output.printf("%3d ", work[k++]);
         output.println();
      }
      output.close();
   }

   static void shuffle(int[] x, int n)
   {  int temp;
      Random gen = new Random();
      while ( n > 1 )
      {  int k = gen.nextInt(n--);
         temp = x[n];
         x[n] = x[k];
         x[k] = temp;
      }
   }
}