class MatrixMult {
    int[][] a, b, c;
    
    void multiply(){
    	int i, j, k;
	i = 0;
	while(i < a.length){
	    j = 0;
	    while(j < c[i].length){
	        c[i][j] = 0;
	        k = 0;
		while(k < a[i].length){
	            c[i][j] = c[i][j] + a[i][k] * b[k][j];
		    k = k + 1;
	        }
		j = j + 1;
	    }
	    i = i + 1;
	}
    }

    void initMatrix(int[][] m) {
	int i, j;
	i = 0;
	while(i < m.length){
	    j = 0;
	    while(j < m[i].length){
	    	m[i][j] = (i+1)*(j+1); //Library.random(m.length*2);
	        j = j + 1;
	    }
	    i = i + 1;
	}
    }

    void printMatrix(int[][] m) {
	int i, j;
	i = 0;
	while(i < m.length) {
	    j = 0;
	    while(j< m[i].length){
	        Library.printi(m[i][j]);
	        Library.print(" ");
	        j = j + 1;
	    }
	    Library.print("\n");
	    i = i + 1;
	}
	Library.print("\n");
    }

    void main(string[] args) {
	int m, n, p;
	int i;

	if (args.length != 3) {
	    Library.println("Invalid number of parameters.");
	    Library.exit(1);
	}

	m = Library.stoi(args[0], 0);
	n = Library.stoi(args[1], 0);
	p = Library.stoi(args[2], 0);
	if(m < 1){
	    Library.println("Invalid value for parameter `m'");
	    Library.exit(1);
	}
	if(n < 1){
	    Library.println("Invalid value for parameter `n'");
	    Library.exit(1);
	}
	if(p < 1){
	    Library.println("Invalid value for parameter `p'");
	    Library.exit(1);
	}

	a = new int[][m];
	i = 0;
	while(i < m){
	    a[i] = new int[n];
	    i = i + 1;
	}
	
	b = new int[][n];
	i = 0;
	while(i < n){
	    b[i] = new int[p];
	    i = i + 1;
	}
	
	c = new int[][m];
	i = 0;
	while(i < m){
	    c[i] = new int[p];
	    i = i + 1;
	}

	initMatrix(a);
	Library.println("Matrix A:");
	printMatrix(a);
	initMatrix(b);
	Library.println("Matrix B:");
	printMatrix(b);
	multiply();
	Library.println("Matrix C = A x B:");
	printMatrix(c);
    }
}
