587A.md (2013B)
1 Source: https://codeforces.com/problemset/problem/587/A 2 3 A. Duff and Weight Lifting 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. 22 23  24 25 Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1, ..., 2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1 + 2*a*2 + ... + 2*a**k* = 2*x*, i. e. the sum of those numbers is a power of two. 26 27 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. 28 29 Input 30 31 The first line of input contains integer *n* (1 ≤ *n* ≤ 106), the number of weights. 32 33 The second line contains *n* integers *w*1, ..., *w**n* separated by spaces (0 ≤ *w**i* ≤ 106 for each 1 ≤ *i* ≤ *n*), the powers of two forming the weights values. 34 35 Output 36 37 Print the minimum number of steps in a single line. 38 39 Examples 40 41 Input 42 43 ``` 44 5 45 1 1 2 3 3 46 ``` 47 48 Output 49 50 ``` 51 2 52 ``` 53 54 Input 55 56 ``` 57 4 58 0 1 2 3 59 ``` 60 61 Output 62 63 ``` 64 4 65 ``` 66 67 Note 68 69 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. 70 71 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.