import java.io.*; import java.util.*; import java.awt.geom.*; /** * Solution to Marbles * * @author vanb */ public class marbles_vanb { public Scanner sc; public PrintStream ps; /** * Driver. * @throws Exception */ public void doit() throws Exception { sc = new Scanner( System.in ); ps = System.out; // Read the data, compute the total number of marbles. int n = sc.nextInt(); // This is the number of marbles in each bin. int bins[] = new int[n]; // This is the total cost, from the start to i, if we decide to move the marbles in bin i int move[] = new int[n]; // This is the total cost, from the start to i, if we decide that the marbles in bin i should stay put. int stay[] = new int[n]; int total = 0; for( int i=0; i2 ) { // If n is at least 3, then we need to arrange the marbles // so that there's an empty bin on either side of a bin with marbles. // Then, every marble will count twice, and that's the best we can do. score = total+total; // In order to get the max score, there has to be an empty bin on both sides // of a bin with marbles. That means we have to move any marbles on the ends. moves = bins[0] + bins[n-1]; bins[1] += bins[0]; bins[n-2] += bins[n-1]; move[0] = 0; stay[0] = 0; for( int i=1; i