100 atcoder#ABC171D. [ABC171D] Replacing
[ABC171D] Replacing
Score : points
Problem Statement
You have a sequence composed of positive integers: .
You will now successively do the following operations:
- In the -th operation, you replace every element whose value is with .
For each , find : the sum of all elements in just after the -th operation.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print integers to Standard Output in the following format:
Note that may not fit into a -bit integer.
4
1 2 3 4
3
1 2
3 4
2 4
11
12
16
Initially, the sequence is .
After each operation, it becomes the following:
4
1 1 1 1
3
1 2
2 1
3 5
8
4
4
Note that the sequence may not contain an element whose value is .
2
1 2
3
1 100
2 100
100 1000
102
200
2000