E - MUL Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700

問題文

宝石が N 個あり,それぞれ 1, 2, ..., N と数が書かれています。

あなたは,以下の操作を好きなだけ行うことが出来ます(一度も行わなくてもよいです)。

  • 正整数 x を選ぶ。x の倍数が書かれた宝石を全て叩き割る。

そして,i が書かれていた宝石が割られずに残っていた場合,a_i 円貰います。 ただし,この a_i は負の場合もあり,その場合はお金を払わなくてはいけません。

うまく操作を行った時,あなたは最大で何円お金を貰えるでしょうか?

制約

  • 入力は全て整数
  • 1 \leq N \leq 100
  • |a_i| \leq 10^9

入力

入力は以下の形式で標準入力から与えられる。

N
a_1 a_2 ... a_N

出力

貰えるお金の最大値を出力してください。


入力例 1

6
1 2 -6 4 5 3

出力例 1

12

宝石 3, 6 を叩き割るのが最適です。


入力例 2

6
100 -100 -100 -100 100 -100

出力例 2

200

入力例 3

5
-1 -2 -3 -4 -5

出力例 3

0

全ての宝石を叩き割るのが最適です。


入力例 4

2
-1000 100000

出力例 4

99000

Score : 700 points

Problem Statement

We have N gemstones labeled 1 through N.

You can perform the following operation any number of times (possibly zero).

  • Select a positive integer x, and smash all the gems labeled with multiples of x.

Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money.

By optimally performing the operation, how much yen can you earn?

Constraints

  • All input values are integers.
  • 1 \leq N \leq 100
  • |a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the maximum amount of money that can be earned.


Sample Input 1

6
1 2 -6 4 5 3

Sample Output 1

12

It is optimal to smash Gem 3 and 6.


Sample Input 2

6
100 -100 -100 -100 100 -100

Sample Output 2

200

Sample Input 3

5
-1 -2 -3 -4 -5

Sample Output 3

0

It is optimal to smash all the gems.


Sample Input 4

2
-1000 100000

Sample Output 4

99000