import sys input = sys.stdin.readline N=int(input()) A=sorted(map(int,input().split())) mod=10**9+7 LEN=500000 BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。 def update(v,w): # index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v): # [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ return ANS def bisect_on_BIT(x): # [1,ind]の和がはじめてx以上になるindexを探す if x<=0: return 0 ANS=0 h=1<<(LEN.bit_length()-1) # LEN以下の最小の2ベキ while h>0: if ANS+h<=LEN and BIT[ANS+h]=2*10**5: break score+=(getvalue((j+1)*a-1)-getvalue(j*a-1))*j score%=mod if j==1: score-=1 ANS+=score*a ANS%=mod print(ANS)