import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] n=II() aa=LI() # 遅延セグツリーの準備...sq2乗和、sm和、lz遅延 wd=1<<(n-1).bit_length() sq=[0]*2*wd sm=[0]*2*wd lz=[0]*2*wd for i,a in enumerate(aa):sq[wd+i]=a**2 sm[wd:wd+n]=aa for u in range(wd-1,0,-1): sq[u]=sq[u*2]+sq[u*2+1] sm[u]=sm[u*2]+sm[u*2+1] def _eval(u,tl,tr): if lz[u]==0:return sq[u]+=lz[u]**2*(tr-tl)+2*sm[u]*lz[u] sm[u]+=lz[u]*(tr-tl) if u