output_description: Print the maximum amount of money that can be earned.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      a_1 a_2 ... a_N
attempt: import itertools
  import copy
  
  
  # 最大公約数
  def gcd(x, y):
      while y != 0:
          x, y = y, x % y
      return x
  
  
  # 宝石の数
  N = int(input())
  # 宝石の得点
  a = list(map(int, input().split()))
  
  # 宝石の得点に負があるか否か
  if min(a) >= 0:
      # 全てを計算して出力
      print(sum(a))
  else:
      # 宝石の得点が負であるインデックスを取得
      minus = [i for i, j in enumerate(a) if j < 0]
      # 宝石の得点が負であるインデックスの組み合わせ
      combination = []
      for i in range(len(minus)):
          combination.extend(list(itertools.combinations(minus, (i + 1))))
      # インデックスの組み合わせを全て計算
      summation = [sum(a)]
      for i in combination:
          # 元のリストは保持
          a_remove = copy.deepcopy(a)
          for index in i:
              # 削除する代わりに0で置換
              for j in range((len(a) + 1) // (index + 1)):
                  a_remove[(index + 1) * j - 1] = 0
              summation.append(sum(a_remove))
      print(max(summation))
  
problem_description: 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?
samples: [{"input": "6\n    1 2 -6 4 5 3", "output": "12\n    \n\nIt is optimal to smash Gem 3 and 6.\n\n* * *"}, {"input": "6\n    100 -100 -100 -100 100 -100", "output": "200\n    \n\n* * *"}, {"input": "5\n    -1 -2 -3 -4 -5", "output": "0\n    \n\nIt is optimal to smash all the gems.\n\n* * *"}, {"input": "2\n    -1000 100000", "output": "99000"}]