import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static HashMap DP = new HashMap(); static ArrayList getDivisors(long n) { // Vector to store half of the divisors ArrayList v = new ArrayList(); for (long i=(long)Math.sqrt(n); i>0; i--) { if (n%i==0) { if (n/i == i) v.add(i); else { v.add(n/i); v.add(i); } } } v.remove(v.indexOf(n)); return v; } static long getMoves(long n, long res, long r){ if(DP.containsKey(n)){ if(n==1) return r; else return DP.get(n)*res; } else{ ArrayList divisor = getDivisors(n); //System.out.println("Divisor of "+n+":"+divisor); if(divisor.size()==0){ //System.out.println(n+":1:"+r); DP.put(n,r); return r; } else{ long ans = 0; for(int i=divisor.size()-1;i>=0;--i){ long val=res+getMoves(divisor.get(i),res*(n/divisor.get(i)),r); if(val>ans) { //System.out.println(divisor.get(i)+":2:"+val); ans = val; } } DP.put(n,ans/res); return ans; } } } static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. long ans = 0; for(int i=0;i