A1 Paper
Time limit1sMemory limit256 MB
Combine the given smaller sheets into one A1 sheet with the least tape, or report impossible.
Problem
Björn likes the square root of two, , so much that he decided to write its first 10000 digits on a single sheet of paper. He started on an A4 sheet and ran out of room after 1250 digits. He worked out that all the digits fit on an A1 sheet. Björn has no A1 sheet, but he has smaller sheets that he can tape together.
Taping two A2 sheets together along their long side makes an A1 sheet, and two A3 sheets make an A2 sheet. Every smaller size follows the same rule. The tape needed to join two sheets is as long as their long side. An A2 sheet is meters by meters, and each next size (A3, A4, ...) has the same shape with half the area of the previous one.
You are given how many sheets of each size Björn has. Find the smallest total length of tape that makes one A1 sheet.
Input
The first line contains the A-size of the smallest sheets Björn has ().
The second line contains integers: the number of sheets of size A2, A3, ..., A in that order. Each value is between 0 and .
Output
If Björn can make an A1 sheet, print on one line the smallest total length of tape in meters, rounded to exactly six decimal places. Otherwise print impossible.