/*
                 1
              6     2
          11     7     3                11 24  7 20  3
       16    12     8     4              4 12 25  8 16
    21    17    13     9     5   -->    17  5 13 21  9
       22    18    14    10             10 18  1 14 22
          23    19    15                23  6 19  2 15
             24    20
                25
*/

class MagicSquare {

    public static final int dim=3;  /* Dimension of matrix */
    public static double[][] a = new double[dim][dim];
    public static int iter;

    public static void main (String args[])
        {
        for (int ipr = 0; ipr < 5; ipr++)
        {
        long start = System.currentTimeMillis();

        iter = 100000;

        test();

        long end = System.currentTimeMillis();
        System.out.println("Total time = "+ (end-start)*0.001);
/*
        for (int i = 0; i < dim; i++)
            {
            for (int j = 0; j < dim; j++)
            System.out.print(a[i][j] + " " );
            System.out.println(" ");
            };
*/
        System.out.println(" " );
        } 
        }

    public static void test () {
      final double[] da6 = new double[3] ;
      final double d10 = 1D / 15D;
      final double d17 = 2D / 15D;
      final double d24 = 3D / 15D;
      final double d39 = 4D / 15D;
      final double d46 = 5D / 15D;
      final double d53 = 6D / 15D;
      final double d68 = 7D / 15D;
      final double d75 = 8D / 15D;
      final double d82 = 9D / 15D;
      da6[0] = d39;
      da6[1] = d24;
      da6[2] = d75;
      for (int iiii_187 = 0; iiii_187 < MagicSquare.iter; iiii_187++) {
        final double d230 = da6[0] * d24 + da6[1] * d46 + da6[2] * d68;
        final double d252 = da6[0] * d75 + da6[1] * d10 + da6[2] * d53;
        da6[0] = da6[0] * d39 + da6[1] * d82 + da6[2] * d17;
        da6[1] = d230;
        da6[2] = d252;
        continue;}
      MagicSquare.a[0][0] = da6[0];
      MagicSquare.a[0][1] = da6[1];
      MagicSquare.a[0][2] = da6[2];
      da6[0] = d82;
      da6[1] = d46;
      da6[2] = d10;
      for (int iiii_389 = 0; iiii_389 < MagicSquare.iter; iiii_389++) {
        final double d432 = da6[0] * d24 + da6[1] * d46 + da6[2] * d68;
        final double d454 = da6[0] * d75 + da6[1] * d10 + da6[2] * d53;
        da6[0] = da6[0] * d39 + da6[1] * d82 + da6[2] * d17;
        da6[1] = d432;
        da6[2] = d454;
        continue;}
      MagicSquare.a[1][0] = da6[0];
      MagicSquare.a[1][1] = da6[1];
      MagicSquare.a[1][2] = da6[2];
      da6[0] = d17;
      da6[1] = d68;
      da6[2] = d53;
      for (int iiii_591 = 0; iiii_591 < MagicSquare.iter; iiii_591++) {
        final double d634 = da6[0] * d24 + da6[1] * d46 + da6[2] * d68;
        final double d656 = da6[0] * d75 + da6[1] * d10 + da6[2] * d53;
        da6[0] = da6[0] * d39 + da6[1] * d82 + da6[2] * d17;
        da6[1] = d634;
        da6[2] = d656;
        continue;}
      MagicSquare.a[2][0] = da6[0];
      MagicSquare.a[2][1] = da6[1];
      MagicSquare.a[2][2] = da6[2];
      return;
    }
//------------------------------------------------   8 sec

/*

    public static void test()
        {
        double[][] magic = new double[dim][dim];
        double[] rr = new double[dim];
        double[] rr1 = new double[dim];
        
        int x = (dim - 1)/2 + (dim + 1);
        int y = -(dim - 1)/2 + (dim - 1);

        double summa = dim * (dim*dim + 1) /2;
        int n = 1;
        
        for (int i = 0; i < dim; i++)
            {
            x = x - (dim + 1);
            y = y - (dim - 1);
            for (int j = 0; j < dim; j++)
                {
                if (x >= dim) magic[x-dim][y] = n/summa; else
                if (x <  0  ) magic[x+dim][y] = n/summa; else
                if (y >= dim) magic[x][y-dim] = n/summa; else
                if (y <  0  ) magic[x][y+dim] = n/summa; else
                    magic[x][y] = n/summa;
                n++;
                x++;
                y++;
                }
            }

        for (int i = 0; i < dim; i++)
            {
            for (int k = 0; k < dim; k++)
                    rr[k] = magic[i][k];
            for (int iiii = 0; iiii < iter; iiii++)
                {
                for (int j = 0; j < dim; j++)
                    {
                    rr1[j] = 0.0;
                    for (int k = 0; k < dim; k++)
                        rr1[j] = rr1[j] + rr[k]*magic[k][j];
                    };
                for (int k = 0; k < dim; k++)
                    rr[k] = rr1[k];
                }
            for (int k = 0; k < dim; k++)
                 a[i][k] = rr[k];
            };
        }

*/
}