local mfl = math.floor
local n = io.read("*n")
local a = {}
local edge_to_child = {}
local edge_to_parent = {}
for i = 1, n do
  a[i] = io.read("*n")
  edge_to_child[i] = {}
  edge_to_parent[i] = {}
end
for i = 1, n - 1 do
  local lim = mfl(n / i)
  for j = 2, lim do
    edge_to_child[i][i * j] = true
    edge_to_parent[i * j][i] = true
  end
end

local cost = {}
for i = 1, n do cost[i] = a[i] end

local function recalcCost()
  for i = 1, n do cost[i] = a[i] end
  for child = n, 2, -1 do
    for parent, _u in pairs(edge_to_parent[child]) do
      cost[parent] = cost[parent] + a[child]
    end
  end
end

while true do
  recalcCost()
  local mincost, minpos = 0, 0
  for i = n, 1, -1 do
    if cost[i] < 0 then
      mincost = cost[i]
      minpos = i
      break
    end
  end
  if 0 <= mincost then
    break
  else
    local lim = mfl(n / minpos)
    for j = 1, lim do
      a[minpos * j] = 0
    end
  end
end
local ret = 0
for i = 1, n do
  ret = ret + a[i]
end
print(ret)
