Given medals with depths in a pile, decide greedily and incrementally which can be placed on a perfect binary tree so that no placed node is an ancestor of another.
Hard8GreedyTreeImplementationNo attempts yetTime limit4sMemory limit512 MBYou have a chart of a perfect binary tree, like the one in Figure 1. The chart shows a finite part of the tree, but you can attach more nodes below the leaves and make the tree as deep as you need.

Figure 1. A chart of a perfect binary tree
Every node has a depth, defined recursively. The root has depth 0, and both children of a node of depth d have depth d+1.
You also have a pile of medals, each engraved with a number. You want to know whether the medals can be placed on the chart under all of the following conditions.
You place the medals one at a time, from the top of the pile down to the bottom. When no placement of the current medal satisfies the conditions, you throw that medal away and move on to the next one.
A medal can sometimes go on several different nodes, and you want the best placement. Between two placements that satisfy the conditions, the one that places a medal nearer the top of the pile is better. For example, with four medals, a placement that keeps only the first and the second medal is better than one that keeps the first, the third and the fourth.
Consider a pile of six medals engraved with 2, 3, 1, 1, 4 and 2, from top to bottom.

Figure 2. Medal placements
The input is a single test case in the format below.
n
x1
.
.
.
xn
The first line has the number of medals n (1≤n≤5×105). Each of the next n lines has one positive integer. The i-th of them, xi (1≤xi≤109), is engraved on the i-th medal from the top of the pile.
Choose the best placement. For each i from 1 through n, print Yes on its own line if the i-th medal is placed, and No otherwise.