def main(): N = int(input()) A = list(map(int, input().split())) partial_results = [-1] * 8 sum_ = 0 for base in A: if partial_results[base-1] == -1: partial = sum(base ** a_elm for a_elm in A) partial_results[base-1] = partial sum_ += partial_results[base-1] print(sum_) if __name__ == "__main__": main()