// $Id: matrix.ici,v 1.0 2003/01/03 11:58:00 dada Exp $
// http://dada.perl.it/shootout
//
// contributed by Tim Long

static
mkmatrix(rows, cols)
{
    m = build(rows, cols);
    count = 0;
    forall (col in m)
    {
        forall (val, i in col)
            col[i] = ++count;
    }
    return m;
}

static
mmult(rows, cols, m1, m2, m3)
{
    forall (col, i in m3)
    {
        m1i = m1[i];
        forall (val, j in col)
        {
            val = 0;
            forall (m1ik, k in m1i)
                val += m1ik * m2[k][j];
            col[j] = val;
        }
    }
}

SIZE := 30;
n := argv[1] ? int(argv[1]) : 1;
m1 := mkmatrix(SIZE, SIZE);
m2 := mkmatrix(SIZE, SIZE);
mm := build(SIZE, SIZE);
for (i = 0; i < n; ++i)
    mmult(SIZE, SIZE, m1, m2, mm);
printf("%d %d %d %d\n", mm[0][0], mm[2][3], mm[3][2], mm[4][4]);