{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003ch1\u003e\u003cfont color\u003d\"#000\"\u003eProblem I: \u003c/font\u003e\u003c/h1\u003e\n\n\u003cp\u003e\nConsider a binary tree whose leaves are assigned integer weights. Such a tree is called \u003ci\u003ebalanced\u003c/i\u003e if, for every non-leaf node, the sum of the weights in its left subtree is equal to that in the right subtree. For instance, the tree in the following figure is balanced.\n\u003c/p\u003e\n\n\n\u003ccenter\u003e\n\u003cimg src\u003d\"CDN_BASE_URL/0b7da6c4eba156a8b0565bede7a4f6db?v\u003d1720320252\" style\u003d\"aling:center\"\u003e\u003cbr\u003e\n\u003cspan\u003e\nFigure I.1. A balanced tree\n\u003c/span\u003e\n\u003c/center\u003e\n\u003cbr\u003e\n\n\n\n\u003cp\u003e\nA balanced tree is said to be hidden in a sequence \u003cvar\u003eA\u003c/var\u003e, if the integers obtained by listing the weights of all leaves of the tree from left to right form a subsequence of \u003cvar\u003eA\u003c/var\u003e. Here, a subsequence is a sequence that can be derived by deleting zero or more elements from the original sequence without changing the order of the remaining elements.\n\u003c/p\u003e\n\n\u003cp\u003e\nFor instance, the balanced tree in the figure above is hidden in the sequence 3 4 1 3 1 2 4 4 6, because 4 1 1 2 4 4 is a subsequence of it.\n\u003c/p\u003e\n\n\u003cp\u003e\nNow, your task is to find, in a given sequence of integers, the balanced tree with the largest number of leaves hidden in it. In fact, the tree shown in Figure I.1 has the largest number of leaves among the balanced trees hidden in the sequence mentioned above.\n\u003c/p\u003e\n\n\n\n\u003ch2\u003eInput\u003c/h2\u003e\n\n\u003cp\u003e\nThe input consists of multiple datasets. Each dataset represents a sequence \u003cvar\u003eA\u003c/var\u003e of integers in the format\n\u003c/p\u003e\n\n\u003cpre\u003e\u003cvar\u003eN\u003c/var\u003e\n\u003cvar\u003eA\u003csub\u003e1\u003c/sub\u003e\u003c/var\u003e \u003cvar\u003eA\u003csub\u003e2\u003c/sub\u003e\u003c/var\u003e . . . \u003cvar\u003eA\u003csub\u003eN\u003c/sub\u003e\u003c/var\u003e\n\u003c/pre\u003e\n\n\u003cp\u003e\nwhere 1 ≤ \u003cvar\u003eN\u003c/var\u003e ≤ 1000 and 1 ≤ \u003cvar\u003eA\u003csub\u003ei\u003c/sub\u003e\u003c/var\u003e ≤ 500 for 1 ≤ \u003cvar\u003ei\u003c/var\u003e ≤ \u003cvar\u003eN\u003c/var\u003e. \u003cvar\u003eN\u003c/var\u003e is the length of the input sequence, and \u003cvar\u003eA\u003csub\u003ei\u003c/sub\u003e\u003c/var\u003e is the \u003cvar\u003ei\u003c/var\u003e-th element of the sequence.\n\u003c/p\u003e\n\n\u003cp\u003e\nThe input ends with a line consisting of a single zero. The number of datasets does not exceed 50.\n\u003c/p\u003e\n\n\n\u003ch2\u003eOutput\u003c/h2\u003e\n\n\u003cp\u003e\nFor each dataset, find the balanced tree with the largest number of leaves among those hidden in \u003cvar\u003eA\u003c/var\u003e, and output, in a line, the number of its leaves.\n\u003c/p\u003e\n\n\u003ch2\u003eSample Input\u003c/h2\u003e\n\u003cpre\u003e9\n3 4 1 3 1 2 4 4 6\n4\n3 12 6 3\n10\n10 9 8 7 6 5 4 3 2 1\n11\n10 9 8 7 6 5 4 3 2 1 1\n8\n1 1 1 1 1 1 1 1\n0\n\u003c/pre\u003e\n\n\u003ch2\u003eOutput for the Sample Input\u003c/h2\u003e\n\u003cpre\u003e6\n2\n1\n5\n8\n\u003c/pre\u003e"}}]}