2nd Balkan Olympiad in Informatics
Thessaloniki, Greece, 1-6 October 1994

Day 1 - Problem 3 (35 points)



Recycling glass requires that the glass be separated by color into one of three categories: brown, green, and clear glass. You are given three recycling bins, each containing a specified number of brown, green and clear bottles. In order to be recycled, the bottles will need to be moved so that each bin contains unicolored bottles. The problem is to minimize the number of bottle movements assuming that the bin capacity is infinite.

The first line of the input is a single integer denoting the number of successive lines. Each successive line consists of 9 integers separated by space. The first three integers on a line represent the number of brown, green and clear bottles respectively in the bin #1, the second three integers represent the number of brown, green and clear bottles respectively in the bin #2, whereas the third three integers represent the number of brown, green and clear bottles respectively in the bin #3.

For each line of input there will be one line of output containing:

  1. a string consisting of three characters: B, G, and C (standing for the three colors), representing the content of three numbered bins, and
  2. an integer denoting the minimum number of bottle movements. If more than one order of B, G, and C yields the minimum number of movements, then you should give the first string in alphabetical order.
Example:
Input:
2
1 2 3 4 5 6 7 8 9
5 10 5 20 10 5 10 20 10
Output:
BCG 30
CBG 50