import sys if sys.platform =='ios': import clipboard a=clipboard.get() a = a.split('\n') text = '\n'.join(a) with open('input_file.txt','w') as f: f.write(text) sys.stdin = open('input_file.txt') sys.setrecursionlimit(410000000) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() nm = lambda: map(int,input().split()) na_1 = lambda: list(map(lambda x:int(x)*(-1), stdin.readline().split())) na_2 = lambda: list(map(lambda x:int(x)-1, stdin.readline().split())) N = ni() A = na() k = max(A) m = min(A) num = [0]*8 ans = 0 for i in range(N): if num[A[i]-1] > 0: ans += num[A[i]-1] else: tmp = 0 for j in range(N): tmp += A[i]**A[j] ans += tmp num[A[i]-1] += tmp print(ans)