import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; /** * Solution to Balanced Animals * * @author vanb */ public class animals_vanb { /** Input. */ private static Scanner sc; /** Output. */ private static PrintStream ps; /** * Do it! */ private void doit() { // Read in the data. // We don't need the individual animals, just the count of each weight. int n = sc.nextInt(); long counts[] = new long[200001]; Arrays.fill( counts, 0L ); // We're looking for a breakpoint t. // Keep track of the sum of weights of all smaller animals, and all larger animals, around that breakpoint. // At first, the breakpoint is 0, so "smaller" is 0 and "larger" is to total sum of weights long smaller = 0L; long larger = 0L; for( int i=0; i0L ) { // Total weight of all animals with this individual weight long weight = answer*counts[answer]; // If we split these animals up, then they contribute equally to smaller & larger. // So they cancel each other out. larger -= weight; if( smaller==larger ) break; // OK, if we move these animals to the smaller side, is there a balance at the next t? smaller += weight; if( smaller==larger ) { answer++; break; } } ps.println( answer ); } /** * Main. * * @param args unused * @throws Exception */ public static void main( String[] args ) throws Exception { sc = new Scanner( System.in ); ps = System.out; new animals_vanb().doit(); } }