http://codeforces.com/contest/1119/problem/B
Alyona has recently bought a miniature fridge that can be represented as a matrix with hh rows and 22 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but separates the inside of the fridge to the lower and upper part.
An example of a fridge with h=7h=7 and two shelves. The shelves are shown in black. The picture corresponds to the first example.
Alyona has nn bottles of milk that she wants to put in the fridge. The ii -th bottle is aiai cells tall and 11 cell wide. She can put a bottle on some shelf if the corresponding space above the she