达夫是一个举重运动员。作为一项艰苦的练习,教练给了他一项任务。教练给了她一系列重量。其中第i个的重量是2wi磅。在每一步中,达夫都可以举起一些剩余的重物并扔掉。她这样做,直到没有更多的重量。教练要求他尽量减少步数。
达夫也是一位极具竞争力的编程爱好者。这就是为什么在每一步中,她只能举起和扔掉一系列的权重2a1,…,2ak,当且仅当存在一个非负整数x,使得2a1+2a2+…+2ak
=2x,即这些数字的和是2的幂。
达夫是一个有竞争力的编程爱好者,但不是程序员。这就是她请求你帮助的原因。帮助她尽量减少步数。
有n个数w1,w2......wn−1,wn,若有k个w值满足存在一个数x使得2x为这k个2w的和,则这一组合是合法的,我们希望找到最小的组数m,使这n个w组成m个合法组合。
给出n和wi,输出最小的m。
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2�1,...,2��2a1,...,2ak if and only if there exists a non-negative integer �x such that 2�1+2�2+...+2��=2�2a1+2a2+...+2ak=2x , i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
The first line of input contains integer n (1 ≤ n ≤ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 ≤ wi ≤ 106 for each 1 ≤ i ≤ n), the powers of two forming the weights values.
Print the minimum number of steps in a single line.
Examples
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
第一行输入包含整数n(1≤n≤106)、权重的数量。
在单行中打印最小步数。
示例
input
5
2
input
4
在第一个示例中:一个最佳的方法是在第一步中丢弃前三个,在第二步中丢弃其余的。而且,不可能一步到位,因为它们的和不是二的幂。
5
1 1 2 3 3
2