import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=print.f.map(fst.fromJust.B.readInt).B.words=<<B.getContents
f(_:as)=g 0 0.reverse.zip as.scanl' (\i a->min(maxBound`div`2)$(i-a)*2) 1$as
g j k((a,i):ais)=if a+(j+1)`div`2>i then -1 else g m(k+m)ais where m=min i$a+j
g _ k _=k