module matrix;

import std.conv, std.stdio;

void main(char[][] args)
{
  int NUM = args.length > 1 ? toInt(args[1]) : 1;
  TMatrix M1, M2, MM;

  mkmatrix(SIZE, SIZE, &M1);
  mkmatrix(SIZE, SIZE, &M2);
  for(int i = 0; i < NUM; i++)
    mmult(SIZE, SIZE, &M1, &M2, &MM);
  writefln(MM[0][0]," ",MM[2][3]," ",MM[3][2]," ",MM[4][4]);
}

const SIZE = 30;

typedef int[SIZE][SIZE] TMatrix;

void mkmatrix(int rows, int cols, TMatrix* mx)
{
  int count = 1;
  for(int R = 0; R < rows; R++)
    for(int C = 0; C < cols; C++)
    {
      (*mx)[R][C] = count;
      count++;
    }
}

void mmult(int rows, int cols, TMatrix* m1, TMatrix* m2, TMatrix* mm)
{
  for(int i = 0; i < rows; i++)
    for(int j = 0; j < cols; j++)
    {
      int val = 0;
      for(int k = 0; k < cols; k++)
        val += (*m1)[i][k] * (*m2)[k][j];
      (*mm)[i][j] = val;
    }
}

