using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. _maxMoves = new Dictionary(); _maxMoves.Add(1, 1); long total = 0; foreach(var length in a) { if(length == 1) total += 1; else total += length % 2 == 1 ? length + 1 : CalculateMoves(length, 1); } return total; } static Dictionary _maxMoves; static long CalculateMoves(long a, int multiplier) { if(_maxMoves.ContainsKey(a)) return multiplier * _maxMoves[a]; if(a % 2 == 1) return a + 1; long three = a % 3 == 0 ? CalculateMoves(a / 3, multiplier * 3) : 0; long two = CalculateMoves(a / 2, multiplier * 2); return multiplier + Math.Max(three, two); } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); long[] a = Array.ConvertAll(a_temp,Int64.Parse); long result = longestSequence(a); Console.WriteLine(result); } }