Determine whether a player can always guess x within a_x comparison questions given a monotone budget array, and list all valid first questions q.
Hard8Binary searchGreedyDynamic programmingNo attempts yetTime limit2sMemory limit64 MBJihak built the following game to teach binary search.
Students were learning binary search from this game until Jaehyun told them the optimal strategy in advance, which made the game too easy. Jihak then changed the rule. The computer prints success only when v=x and the number of "Is x at most q?" questions asked so far is at most ax, and prints failure otherwise. The final confirmation question is not counted. Jihak likes sorted sequences, so the sequence a satisfies a1≤a2≤⋯≤an.
Jaehyun could not find a way to always succeed in the changed game and claimed that no such way exists. Jihak could not prove otherwise and asked you for help.
Decide whether there is a way of asking that always succeeds no matter which x the computer picked, and if there is, find every q that may be asked as the first question. A value q may be asked as the first question when there is a way to start with "Is x at most q?", then choose every later question from the answers received, and succeed for every x.
The first line contains n (1≤n≤106).
The second line contains n integers a1,a2,…,an (1≤a1≤a2≤⋯≤an≤109) separated by spaces.
On the first line, print how many values of q may be asked as the first question. If infinitely many such q exist, print inf instead of a count.
On the second line, print those values of q in increasing order, separated by spaces. If no such q exists, or if infinitely many exist, print nothing on the second line.