#arc136e. [arc136_e]Non-coprime DAG
[arc136_e]Non-coprime DAG
Problem Statement
We have a directed graph with vertices numbered to .
Between two vertices (, ), there is an edge if and only if both of the following conditions are satisfied.
Additionally, each vertex has an associated value: the value of Vertex is .
Consider choosing a set of vertices so that the following condition is satisfied.
- For every pair () of different vertices in , is unreachable from in .
Find the maximum possible total value of vertices in .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
6
1 1 1 1 1 1
Sample Output 1
4
We should choose .
Sample Input 2
6
1 2 1 3 1 6
Sample Output 2
8
We should choose .
Sample Input 3
20
40 39 31 54 27 31 80 3 62 66 15 72 21 38 74 49 15 24 44 3
Sample Output 3
343