• + 0 comments

    def min_operations(n, boxes): # Separate the balls in each box for i in range(1, n): for j in range(3): if boxes[i][j] != boxes[0][j]: boxes[i][j] = boxes[0][j]

    # Count the total number of operations
    operations = 0
    for i in range(n):
        for j in range(3):
            if boxes[i][j] != boxes[0][j]:
                operations += 1
    
    return operations
    

    Input reading

    n = int(input()) # Number of boxes boxes = [list(map(int, input().split())) for _ in range(n)] # List of boxes

    Get the result

    result = min_operations(n, boxes) Run this Python code and input the number of boxes along with the colors of balls in each box. It will output the minimal number of operations required to separate the balls. Moreover, for debugging apply update from adb and then run this python code.

    Print the result

    print(result)