n = io.read('n')
a = {}
for i = 1, n do
  a[i] = io.read('n')
end

for i = n, 1, -1 do
  local sum = 0
  for j = i, n, i do
    sum = sum + a[j]
  end
  if sum < 0 then
    for j = i, n, i do
      a[j] = 0
    end
  end
end

total = 0
for i = 1, n do
  total = total + a[i]
end
io.write(total, '\n')
