#P13950. [EC Final 2019] Value

[EC Final 2019] Value

题目描述

Pang\textit{Pang} believes that one cannot make an omelet without breaking eggs.

For a subset AA of {1,2,,n}\{1,2,\ldots,n\}, we calculate the score of AA as follows:

  • Initialize the score as 00.
  • For any iAi\in A, add aia_i to the score.
  • For any pair of integers (i,j)(i, j) satisfying i2i\ge 2, j2j\ge 2, iAi\in A and jAj\in A, if there exists positive integer k>1k > 1 such that ik=ji^k=j, subtract bjb_j from the score.

Find the maximum possible score over the choice of AA.

输入格式

The first line contains a single integer nn (1n100000)(1\le n\le 100000).

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1000000000)(1\le a_i\le 1000000000).

The third line contains nn integers b1,b2,,bnb_1,b_2,\ldots,b_n (1bi1000000000)(1\le b_i\le 1000000000).

输出格式

Print a single integer xx --- the maximum possible score.

4
1 1 1 2
1 1 1 1
4
4
1 1 1 1
1 1 1 2
3