import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static long longestSequence(long[] a) { HashMap map = new HashMap<>(); for(int i = 0;i map, long num) { if(map.containsKey(num)) { return map.get(num); } if(num == 1) { map.put(num, 1L); return 1L; } if(num == 2) { map.put(num, 3L); return 3L; } long j = 2; boolean prime = true; while(j*j <= num) { if(num%j == 0) { prime = false; long val = num/j; if(!map.containsKey(num)) { map.put(num, j * getMinSequence(map, val) + 1L); } else { map.put(num, Math.max(map.get(num), j * getMinSequence(map, val) + 1L)); } map.put(num, Math.max(map.get(num), val * getMinSequence(map, j) + 1L)); } j++; } if(prime) { map.put(num, num + 1L); //System.out.println(num + " " + map.get(num)); } return map.get(num); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] a = new long[n]; for(int a_i = 0; a_i < n; a_i++){ a[a_i] = in.nextLong(); } long result = longestSequence(a); System.out.println(result); in.close(); } }