def score_n1(matrix, matrix_size):
    """\
    Implements the penalty score feature 1.

    ISO/IEC 18004:2015(E) -- 7.8.3 Evaluation of data masking results - Table 11 (page 54)

    ============================================   ========================    ======
    Feature                                        Evaluation condition        Points
    ============================================   ========================    ======
    Adjacent modules in row/column in same color   No. of modules = (5 + i)    N1 + i
    ============================================   ========================    ======

    N1 = 3

    :param matrix: The matrix to evaluate
    :param matrix_size: The width (or height) of the matrix.
    :return int: The penalty score (feature 1) of the matrix.
    """
    score = 0
    for i in range(matrix_size):
        prev_bit_row, prev_bit_col = -1, -1
        row_counter, col_counter = 0, 0
        for j in range(matrix_size):
            # Row-wise
            bit = matrix[i][j]
            if bit == prev_bit_row:
                row_counter += 1
            else:
                if row_counter >= 5:
                    score += row_counter - 2  # N1 == 3
                row_counter = 1
                prev_bit_row = bit
            # Col-wise
            bit = matrix[j][i]
            if bit == prev_bit_col:
                col_counter += 1
            else:
                if col_counter >= 5:
                    score += col_counter - 2  # N1 == 3
                col_counter = 1
                prev_bit_col = bit
        if row_counter >= 5:
            score += row_counter - 2  # N1 == 3
        if col_counter >= 5:
            score += col_counter - 2  # N1 == 3
    return score