def matrix_totals(matrix):
    rows = len(matrix)
    cols = len(matrix[0]) if rows else 0
    row_totals, column_totals = [0] * rows, [0] * cols
    for r in range(rows):
        for c in range(cols):
            row_totals[r] += matrix[r][c]
            column_totals[c] += matrix[r][c]
    return row_totals, column_totals
