import java.io.* import java.util.* val stepsCache = HashMap() fun main(args: Array) { val sc = Scanner(System.`in`) val n = sc.nextInt() val sticks = LongArray(n, { sc.nextLong() }) println(sticks.map { steps(it) }.sum()) } fun steps(n: Long): Long { if (n == 1L) { return 1 } if(stepsCache.containsKey(n)) { return stepsCache.getValue(n) } var max = 0L for(d in divisors(n)) { if(d > 1) { max = maxOf(max, 1 + d * steps(n / d)) } } stepsCache.put(n, max) return max } fun divisors(n: Long): Set { val divisors = HashSet() val limit = Math.round(Math.sqrt(n.toDouble())) + 1 var i = 1L while (i <= limit) { if (n % i == 0L) { val ndivi = n / i if (ndivi == i) divisors.add(i) else divisors.add(i) divisors.add(ndivi) } i++ } return divisors }