We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Debugging
  4. Minimum Operations

Minimum Operations

Problem
Submissions
Leaderboard
Discussions
  1. Prepare
  2. Algorithms
  3. Debugging
  4. Minimum Operations
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions

In this challenge, the task is to debug the existing code to successfully execute all provided test files.


There are boxes in front of you. For each , box contains red balls, green balls, and blue balls.

You want to separate the balls by their color. In each operation, you can pick a single ball from some box and put it into another box. The balls are separated if no box contains balls of more than one color.

Debug the given function min_operations and compute the minimal number of operations required to separate the balls.

Note: In this problem you can modify at most six lines of code and you cannot add any new lines.

To restore the original code, click on the icon to the right of the language selector.

Input Format

The first line contains a single integer . The next lines contain three space-separated integers, , , and , respectively.

Constraints


Output Format

Print the minimal number of operations required to separate the balls. If this is impossible, return .

Sample Input

3
1 1 1
1 1 1
1 1 1

Sample Output

6

Explanation

Each box contains 1 ball of each color. In this explanation, the goal will be to let the first box contain only red balls, the second box only blue balls, and the third box only green balls.

  • Move 1 blue ball and 1 green ball from the first box to the second and third boxes.
  • Move 1 red ball and 1 green ball from the second box to the first and third boxes.
  • Move 1 red ball and 1 blue ball from the third box to the first and second boxes.

The number of operations is 6.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy