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: def main():
      import sys
  
      input = sys.stdin.readline
  
      # Dinic's algorithm
      from collections import deque
  
      class Dinic:
          def __init__(self, N):
              self.N = N
              self.G = [[] for i in range(N)]
  
          def add_edge(self, fr, to, cap):
              forward = [to, cap, None]
              forward[2] = backward = [fr, 0, forward]
              self.G[fr].append(forward)
              self.G[to].append(backward)
  
          def add_multi_edge(self, v1, v2, cap1, cap2):
              edge1 = [v2, cap1, None]
              edge1[2] = edge2 = [v1, cap2, edge1]
              self.G[v1].append(edge1)
              self.G[v2].append(edge2)
  
          def bfs(self, s, t):
              self.level = level = [None] * self.N
              deq = deque([s])
              level[s] = 0
              G = self.G
              while deq:
                  v = deq.popleft()
                  lv = level[v] + 1
                  for w, cap, _ in G[v]:
                      if cap and level[w] is None:
                          level[w] = lv
                          deq.append(w)
              return level[t] is not None
  
          def dfs(self, v, t, f):
              if v == t:
                  return f
              level = self.level
              for e in self.it[v]:
                  w, cap, rev = e
                  if cap and level[v] < level[w]:
                      d = self.dfs(w, t, min(f, cap))
                      if d:
                          e[1] -= d
                          rev[1] += d
                          return d
              return 0
  
          def flow(self, s, t):
              flow = 0
              INF = 10**9 + 7
              G = self.G
              while self.bfs(s, t):
                  (*self.it,) = map(iter, self.G)
                  f = INF
                  while f:
                      f = self.dfs(s, t, INF)
                      flow += f
              return flow
  
      inf = 1 << 40
      N = int(input())
      A = list(map(int, input().split()))
      dinic = Dinic(N + 2)
      ans = 0
      for i, a in enumerate(A):
          if a > 0:
              ans += a
              # dinic.add_edge(0, i+1, 0)
              dinic.add_edge(i + 1, N + 1, a)
          else:
              dinic.add_edge(0, i + 1, -a)
              # dinic.add_edge(i+1, N+1, 0)
      for i in range(1, N + 1):
          for k in range(1, N + 1):
              if i * k > N:
                  break
              dinic.add_edge(i, i * k, inf)
  
      print(ans - dinic.flow(0, N + 1))
  
  
  if __name__ == "__main__":
      main()
  
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"}]