def check_matrix(mat):
    """ Assert that each line has a constant number of ratings
        @param mat The matrix checked
        @return The number of ratings
        @throws AssertionError If lines contain different number of ratings """
    n = sum(mat[0])
    
    msg = "Line count != %d (n value)." % n

    assert all(sum(line) == n for line in mat[1:]), msg
    return n