Jaap (and many others) already solved the problem by calculus (and other kinds of maths), but this geometry based solution had such a nice symmetry to it that I wanted to post it anyway. First, let's start by figuring out the general colour pattern. Given a single blue and N reds, where should we put the blue? Let's put **a** reds before the blue, and **b** reds after. Since our score is going to be "a times b", we can turn this into a geometry problem: >! **Maximize the area of this rectangle** >! >! [![enter image description here][1]][2] The maximum is "obviously" >! a square, with **a = b**. A longer rectangle would be thinner, and therefore have smaller area than the square. Or as the old multiplication rule says: "deviating from a square shape by 1 unit decreases the area by 1 unit". >! $$ (x+1)(x-1) = x^2-1$$ So the best spot for the blue lamp, and by extension, all the blue lamps is >! smack in the middle of all the reds. Then, we need to decide the number of blues we should add. Let's call it **c**. Each blue gives us "a times b" points, for a total of "a times b times c", so next we get to solve the exact same problem as before, except *Now in 3D!* >! **Maximize the volume of this rectangular box** >! >! [![enter image description here][3]][4] As before, the intuitive answer is the correct one, and we get the maximum points with >! a cube, that is, **a = b = c**. If a box has a non-square side, we can always make a bigger box by turning that side into a square with the same perimeter, while leaving the other dimension untouched -> the maximal box cannot have any non-square sides. So we should put >! 50 blue lamps in the middle, with 50 red lamps both before and after them for a total of >! $50^3$ grams (125 kg) of gold which, if turned into a sphere of solid gold, would be just about the size of a standard bowling ball (diameter difference < 5%), and easily heavy enough to completely crush us. Maybe that was the genie's ulterior plan? Maybe we should figure out a less effective colouring, this deal seems suspiciously good for us.. [1]: https://i.sstatic.net/crNwGm.png [2]: https://i.sstatic.net/crNwG.png [3]: https://i.sstatic.net/zU5IIm.png [4]: https://i.sstatic.net/zU5II.png