import java.io.*;
import java.math.*;

public class PascalT
{
    public static BigInteger[][] negPascal(BigInteger A[][], int Ai)
    {
	BigInteger[][] PowerMatrix = new BigInteger[Ai][Ai];

        for (int row=0; row<Ai; row++)
	    for (int col=0; col<Ai; col++)
		if ( 1 == (( row + col ) % 2 )) {
		    PowerMatrix[row][col] = A[row][col].multiply(BigInteger.valueOf(-1));
		} else {
		    PowerMatrix[row][col] = A[row][col];
		}
	return PowerMatrix;
    }

    public static BigInteger[][] initMat(int depth)
    {
	BigInteger[][] PasTri = new BigInteger[depth][depth];

	//Initialize Matrix
        for (int row=0; row<depth; row++)
	    for (int col=0; col<depth; col++)
		PasTri[row][col] = BigInteger.ZERO;

	//Set root
        PasTri[depth-1][depth-1] = BigInteger.ONE;

	for (int row=depth-2; row>-1; row--)
	    {
		PasTri[row][depth-1] = BigInteger.ONE;
		for (int col=depth-2; col>row; col--)
		    PasTri[row][col] = 
			PasTri[row+1][col].add(PasTri[row+1][col+1]);
		PasTri[row][row] = BigInteger.ONE;
	    }

        return (PasTri);
    }

    public static int printMat(BigInteger PasTri[][], int rows, int cols)
    {
        for (int row=0; row<rows; row++)
	    {
		for (int col=0; col<cols; col++)
		    System.out.print(PasTri[row][col] + "\t");
		if (row < rows-1)
		    System.out.println("");
	    }
	return (0);
    }

    public static BigInteger[][] multMat(BigInteger A[][], BigInteger B[][],
                                 int Ai, int Aj, int Bi, int Bj )
    {
	BigInteger[][] ResultMat = new BigInteger[Aj][Bi];

	if ( Aj != Bi ) {
	    System.err.println("Bad stuff.  Exiting");
	    return (ResultMat);
	}

	for (int row=0; row<Bi; row++)
	    for (int col=0; col<Aj; col++)
		ResultMat[row][col] = BigInteger.ZERO;

	for (int oli=0; oli<Ai; oli++) // outer loop index
	    for (int mli=0; mli<Aj; mli++ ) // middle loop index
		for (int ili=0; ili<Bi; ili++ ) // inner loop index
			ResultMat[oli][mli] = ResultMat[oli][mli].add(A[oli][ili].multiply(B[ili][mli]));

	return (ResultMat);
    }
}


