n=input()
array=list(input().split(' '))
count=[0 for i in range(10)]
for i in array:
        count[len(i)-1]+=1

result=0
for i in array:
        for l in range(len(count)):
                t=min(l+1,len(i))
                if(count[l]!=0):
                        count_1=len(i)-1
                        for j in range(t*2):
                                result+=int(i[count_1])*(10**j)*count[l]
                                if(j%2!=0):
                                        count_1-=1
                
                #print(c*(int(i)-int(i)%10**t)*10**t)
                result+=2*count[l]*(int(i)-int(i)%10**t)*10**t
print(result)
#11