1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem: Box of Bricks (591)
* @author Christian Mitterreiter
* @author Rolf Luigs
* @version 1.0, 04/08/2009
* Status : Accepted
* Runtime: 0.200
*/


import java.io.*;
import java.util.*;

public class Main {

public static void main (String... arg)
{
int hohe=0,puffer=0,j=0, position=0,zahl;
Scanner scanner=null;
scanner = new Scanner(System.in);
int[] input = new int [55000];
int k=-1;

do
{ k++;
input[k]=scanner.nextInt();

}while(input[k]!=0);

do
{
j=0;hohe=0;zahl=0;
puffer++;

for (int i=position+1;i<=input[position]+position;i++)
{ hohe+=input[i];}
hohe /= input[position];

for ( j=position+1;j<=input[position]+position;j++)
{
while(input[j]!=hohe)
{if (input[j]>hohe)
input[j]--;

else
input[j]++;
zahl++;
}

}
System.out.println("Set #"+puffer);
System.out.println("The minimum number of moves is "+zahl+".");

position += input[position]+1;
if (input[position]!=0)
System.out.println();
}while(input[position]!=0);

System.out.println();
}
}