(mat: list, n: int)
Calculates mat^n by repeated squaring
    Time Complexity: O(d^3 log(n))
                     d: dimension of the square matrix mat
                     n: power the matrix is raised to
Calculates mat^n by repeated squaring
    Time Complexity: O(d^3 log(n))
                     d: dimension of the square matrix mat
                     n: power the matrix is raised to
Calculates mat^n by repeated squaring Time Complexity : O ( d^3 log ( n )) d : dimension of the square matrix mat n : power the matrix is raised to
def matrix_exponentiation(mat: list, n: int) -> list:
    """
    Calculates mat^n by repeated squaring
    Time Complexity: O(d^3 log(n))
                     d: dimension of the square matrix mat
                     n: power the matrix is raised to
    """
    if n == 0:
        return identity(len(mat))
    elif n % 2 == 1:
        return multiply(matrix_exponentiation(mat, n - 1), mat)
    else:
        tmp = matrix_exponentiation(mat, n // 2)
        return multiply(tmp, tmp)
def matrix_exponentiation ( mat : list , n : int ) -> list : if n == 0 : return identity ( len ( mat ) ) elif n % 2 == 1 : return multiply ( matrix_exponentiation ( mat , n - 1 ) , mat ) else : tmp = matrix_exponentiation ( mat , n // 2 ) return multiply ( tmp , tmp )