# coding: utf-8 # Your code here! def Eratosthenes(N): #N以下の素数のリストを返す #iが素数のときis_prime_list[i]=1,それ以外は0 N+=1 is_prime_list = [True]*N # is_prime_list[0], is_prime_list[1] = False, False #リストが必要なときはこの2行を有効化 # for j in range(4,N,2): is_prime_list[j] = False m = int(N**0.5)+1 for i in range(3,m,2): if is_prime_list[i]: is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1) return [2] + [i for i in range(3,N,2) if is_prime_list[i]] # return is_prime_list import sys #sys.setrecursionlimit(10**6) readline = sys.stdin.readline n = int(input()) a = [int(i) for i in readline().split()] ra = list(reversed(a)) from itertools import accumulate primes = [1]+Eratosthenes(n) def ans(k,a,ra): res1 = [] R1 = [0] for i in range(k,n+1,k): l = a[i-k:i] l.sort() res1.append(l[(k+1)//2-1]) for i in accumulate(res1): R1.append(max(R1[-1],i)) # print(res1,R1) res2 = [] R2 = [0] for i in range(k,n+1,k): l = ra[i-k:i] l.sort() res2.append(l[(k+1)//2-1]) for i in accumulate(res2): R2.append(max(R2[-1],i)) # print(res2,R2) res1 = R1 res2 = R2 res = 0 for r1,r2 in zip(res1,reversed(res2)): res = max(res,r1+r2) # print(res*k) return(res*k) c = 0 for p in primes: c = max(c,ans(p,a,ra)) print(c)