import java.util.*

data class Edge(val from: Int, val to: Int, val weight: Long)

const val INF = Long.MAX_VALUE / 4

fun maxFlow(capacity: Array<LongArray>, s: Int, t: Int): Long {
  // Edmonds-Karp Algorithm
  val n = capacity.size
  val flow = Array(n, { LongArray(n) })
  fun residual(v1: Int, v2: Int): Long {
    return capacity[v1][v2] - flow[v1][v2]
  }
  fun getPath(prevs: IntArray): IntArray {
    val path = mutableListOf<Int>()
    var current = t
    path.add(current)
    while (current != s) {
      current = prevs[current]
      path.add(current)
    }
    path.reverse()
    return path.toIntArray()
  }
  var total = 0L
  while (true) {
    val queue = ArrayDeque<Int>()
    val prevs = IntArray(n, { -1 })
    queue.offer(s)
    while (queue.isNotEmpty()) {
      val v1 = queue.pop()
      for (v2 in 0 until n) {
        if (residual(v1, v2) == 0L || prevs[v2] >= 0) continue
        prevs[v2] = v1
        queue.offer(v2)
      }
    }
    if (prevs[t] == -1) return total
    val path = getPath(prevs)
    val inc = (0..(path.size - 2)).map { residual(path[it], path[it + 1]) }.min()!!
    (0..(path.size - 2)).forEach {
      flow[path[it]][path[it + 1]] += inc
      flow[path[it + 1]][path[it]] -= inc
    }
    total += inc
  }
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = longArrayOf(0) + readLine()!!.split(" ").map(String::toLong)
  val capacity = Array(n + 2, { LongArray(n + 2) })
  val s = 0
  val t = n + 1
  for (k in 1..n) {
    if (xs[k] >= 0) {
      capacity[k][t] = xs[k]
    } else {
      capacity[s][k] = -xs[k]
    }
  }

  for (i in 1..n) {
    for (j in (i + 1)..n) {
      if (j % i == 0) {
        capacity[i][j] = INF
      }
    }
  }

  val maxFlow = maxFlow(capacity, s, t)
  val ans = xs.filter { it >= 0 }.sum() - maxFlow
  println(ans)
}
