Problem:
 Score : 300 points    Problem Statement Given are N integers A_1,\ldots,A_N .  Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N , modulo (10^9+7) .      Constraints  2 \leq N \leq 2\times 10^5  0 \leq A_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  \ldots  A_N       Output Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j , modulo (10^9+7) .        Sample Input 1 3
1 2 3      Sample Output 1 11  We have 1 \times 2 + 1 \times 3 + 2 \times 3 = 11 .       Sample Input 2 4
141421356 17320508 22360679 244949      Sample Output 2 437235829

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

MOD  = 10**9 + 7

l = [0]*(N)
for i in range(N-1):
  l[i+1] += (l[i] +  A[i])%MOD
  


ans = 0
for i in  range(N-1):
  ans += (A[N-1-i] * l[N-1-i])%MOD
  
print(ans%MOD)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

MOD = 10**9+7
ans = 0

mul = [0]*(N+1)

for i in range(N):
  mul[i+1] = mul[i]+A[i]
  mul[i+1] = mul[i+1]%MOD
  
for i in range(N-1):
  ans += A[i] * (mul[-1]-mul[i+1])
  ans %= MOD
  
print(ans)

Solution (Python):
def find(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
    array_sum_square = array_sum * array_sum 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    return (array_sum_square - 
            individual_square_sum) // 2
n=int(input())
arr=list(map(int,input().split()))
ans=find(arr,n)
mod=1000000007
print(ans%mod)

Solution (Python):
from itertools import accumulate
MOD = 10**9 + 7


N = int(input())
A = list(map(int, input().split()))
A_cumsum = list(accumulate(A))

ans = 0
for i in range(N-1):
    ans += A[i] * (A_cumsum[-1] - A_cumsum[i]) % MOD

print(ans % MOD)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
MOD = 10**9+7

array_sum = 0
for i in range(n):
  array_sum += a[i]
  array_sum %= MOD

ans = 0
for i in range(n):
  array_sum -= a[i]
  ans += array_sum * a[i]
  ans %= MOD
  
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))

ans2 = (sum(a) % MOD) ** 2 - sum(ai ** 2 for ai in a)

if ans2 % 2 != 0:
    ans2 += MOD
ans = (ans2 // 2) % MOD
print(ans)

Solution (Python):

import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
sys.setrecursionlimit(10**6)




def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


MOD = pow(10, 9)+7

N = z()
A = zz()
ans = 0
part_sum = [0]*N
part_sum[0] = A[0]
sum_a = sum(A) % MOD
for i in range(1, N):
    part_sum[i] = (part_sum[i-1] + A[i]) % MOD

for i in range(N - 1):
    tmp = A[i]*(sum_a - part_sum[i])
    ans = (ans+tmp) % MOD
    ans = ans % MOD
print(ans)

Solution (Python):
n = input()
a = list(map(int, input().split()))

sa = sum(a)
ans = 0
p = 10**9 + 7
for i in a:
  sa -= i
  t = (i * sa) % p
  ans += t
  ans %= p

print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
s=sum(A)
ans=0
mod=10**9+7
for i in range(n-1):
  s=s-A[i]
  ans=(ans+A[i]*s)%mod
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
num = sum(A)
for i in range(N - 1):
  num -= A[i]
  ans += A[i] * num
print(ans % (10 ** 9 + 7))

Solution (Python):
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] + list(accumulate(A))
    MOD = 10 ** 9 + 7
    ans = 0
    for i in range(N):
        ans += A[i] * (B[N] - B[i+1])
        ans %= MOD

    print(ans)




if __name__ == "__main__":
    main()

Solution (Python):
import copy
mod = (10 ** 9) + 7
n = int(input())
a = list(map(int, input().split()))
M = sum(a)
a_sum = copy.copy(a)
for i in range(1, n):
    a_sum[i] = (a_sum[i - 1] + a_sum[i]) % mod


ans = 0
for i in range(n):
    ans += a[i] * M
    ans -= a[i] * a_sum[i]
print(ans % mod)

Solution (Python):
def main(sample_file = ''):

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product, combinations_with_replacement 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):   
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter 
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)
    def make_divisors(n, reversed=False):
        """create list of divisors
        
        Args:
            number (int): number from which list of divisors is created
            reversed (bool, optional): ascending order if False. Defaults to False.
        
        Returns:
            list: list of divisors
        """
        divisors = set()
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.add(i)
                divisors.add(n//i)
        return sorted(list(divisors),reverse=reversed)
    
    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    AtoZ = list('abcdefghijklmnopqrsruvwxyz') 
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    class SegTree:
        """
        ref: https://qiita.com/takayg1/items/c811bd07c21923d7ec69
        init(init_val, ide_ele): 配列init_valで初期化 O(N)
        update(k, x): k番目の値をxに更新 O(logN)
        query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
        """
        def __init__(self, init_val, segfunc, ide_ele):
            """
            init_val: 配列の初期値
            segfunc: 区間にしたい操作
            ide_ele: 単位元
            n: 要素数
            num: n以上の最小の2のべき乗
            tree: セグメント木(1-index)
            """
            n = len(init_val)
            self.segfunc = segfunc
            self.ide_ele = ide_ele
            self.num = 1 << (n - 1).bit_length()
            self.tree = [ide_ele] * 2 * self.num
            
            for i in range(n):
                self.tree[self.num + i] = init_val[i]
            
            for i in range(self.num - 1, 0, -1):
                self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

        def update(self, k, x):
            """
            k番目の値をxに更新
            k: index(0-index)
            x: update value
            """
            k += self.num
            self.tree[k] = x
            while k > 1:
                self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
                k >>= 1

        def query(self, l, r):
            """
            [l, r)のsegfuncしたものを得る
            l: index(0-index)
            r: index(0-index)
            """
            res = self.ide_ele
            l += self.num
            r += self.num
            while l < r:
                if l & 1:
                    res = self.segfunc(res, self.tree[l])
                    l += 1
                if r & 1:
                    res = self.segfunc(res, self.tree[r - 1])
                l >>= 1
                r >>= 1
            return res

    
    
    
    
    
    
    
    

    def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
        """to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
        
        Args:
            N (int): number of vertices
            M (int): number of edges
            ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci 
            vertex_start (int): start vertex. usually use 0.
            vertex_end (int): end vertex. usually use N-1.
            value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
            find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
        
        Returns:
            int or string: normally int (but can be str if you set value_if_inf to str)
            
        Example:
                N, M, P = R()
                ABC = [R() for _ in range(M)]
                ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
                print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))

        """

        def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
            reachable_to_direct = defaultdict(list)
            reachable_from_direct = defaultdict(list)
            reachable_from_start = [False] * N
            reachable_to_end = [False] * N
            reachable_from_start[vertex_start] = True
            reachable_to_end[vertex_end] = True
            reachable_from_both_sides = [False] * N
            dfs_from_start = []
            dfs_to_end = []
            for a, b, c in ABC:
                reachable_to_direct[a].append(b)
                reachable_from_direct[b].append(a)
                if a == vertex_start:
                    dfs_from_start.append(b)
                    reachable_from_start[b] = True
                if b == vertex_end:
                    dfs_to_end.append(a)
                    reachable_to_end[a] = True
            while dfs_from_start:
                v = dfs_from_start.pop()
                for i in reachable_to_direct[v]:
                    if not reachable_from_start[i]:
                        reachable_from_start[i] = True
                        dfs_from_start.append(i)
            while dfs_to_end:
                v = dfs_to_end.pop()
                for i in reachable_from_direct[v]:
                    if not reachable_to_end[i]:
                        reachable_to_end[i] = True
                        dfs_to_end.append(i)
            for i in range(N):
                reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
            return reachable_from_both_sides
        
        reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
        
        if find_shortest:
            dist = [INF for i in range(N)]
        else:
            dist = [-INF for i in range(N)]
        
        dist[vertex_start] = 0
        for i in range(N):
            updated = False
            for a, b, c in ABC:
                if not reachable_from_both_sides[a]:
                    continue
                elif find_shortest:
                    update_condition = dist[a] + c < dist[b]
                else:
                    update_condition = dist[a] + c > dist[b]
                if dist[a] != INF and update_condition:
                    dist[b] = dist[a] + c
                    updated = True
                    if i == N-1:
                        return value_if_inf
            if not updated:
                break
        return dist[vertex_end]

    
    def warshall_floyd(number_vertex, XYD, shift_one_for_vertex=False):
        
        
        
        
        
        d = [[float("inf")]*number_vertex for i in range(number_vertex)]
        for x, y, dist in XYD:
            if shift_one_for_vertex:
                x = x - 1
                y = y - 1
            d[x][y] = dist
            d[y][x] = dist
        for i in range(number_vertex):
            d[i][i] = 0 
        for k in range(number_vertex):
            for i in range(number_vertex):
                for j in range(number_vertex):
                    d[i][j] = min(d[i][j],d[i][k] + d[k][j])
        return d


    """ initialize variables and set inputs
    
        
        
            
            
    
        
        
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    r_float = lambda: float(r())
    R = lambda: list(map(int, r().split()))
    R_str = lambda: r().split()
    R_map = lambda: map(int, r().split())
    R_float = lambda: list(map(float, r().split()))
    R_tuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    
    if sample_file:
        sys.stdin = open(sample_file)
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    N = r_int()
    A = R()
    tmps = sum(A)
    ans = 0
    m = 10**9 + 7
    for i, a in enumerate(A):
        if i == len(A)-1:
            continue
        ans = (ans + a * (tmps-a))%m
        tmps -= a
    print(ans)
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    


    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """
    
    """memo: how to solve binary problems
    
    >>> a = 5
    >>> bin_str_a = format(a, '
    >>> print(bin_str_a)
    0b0101 
    """
    
    """memo: how to solve the problem
    creating simple test/answer
    greed
    simple dp
    graph
    """

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
p = 10 ** 9 + 7

ans = 0
sq = 0
twoinv = pow(2, p - 2, p)

for i in range(n):
    ans += a[i]
    ans %= p
    sq += a[i] * a[i]
    sq %= p

ans = (ans * ans % p - sq) * twoinv % p
print(ans)

Solution (Python):
mod = 10**9+7
n = int(input())
a = [int(i) for i in input().split()]

sum_a = [0]*(n-1)
sum_a[0] = a[n-1]

for i in range(1,n-1):
    sum_a[i] = sum_a[i-1] + a[n-1-i]
    
ans = 0

for i in range(n-1):
    
    ans += a[i]*sum_a[n-2-i]
    ans %= mod
    
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

now = sum(A) % mod
ans = 0

for i in range(N):
  now -= A[i]
  now %= mod
  ans += A[i] * now
  ans %= mod
print(ans % mod)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
sm = sum(a)
mod = 10**9 + 7
ans = 0
for i in range(n-1):
    ans += a[i]*(sm-a[i])
    sm -= a[i]
    ans = ans%mod
    
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
s=sum(a)
ans=0
for i in a:
    s-=i
    ans+=i*s
    ans%=10**9+7
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
s=sum(a)%mod

aa=sum([i**2 for i in a])%mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, pow(b, mod-2,mod)) % mod

ans=div((pow(s,2)%mod-aa)%mod,2)

print(int(ans))

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]
b = [0 for i in range(n+1)]

for i in reversed(range(n)):
    b[i] += a[i]+b[i+1]

ans = 0

MOD = 10**9+7

for i in range(n-1):
    ans = (ans+a[i]*b[i+1]) % MOD



print(ans)

Solution (Python):




n=int(input())
a=[int(x) for x in input().split()]  


p=[]
r=0
for x in a[::-1]:
   r+=x
   p.append(r)  
  
p=p[::-1]
ans=0
for i in range(0,n-1):

    ans+=(a[i]*p[i+1])
print(ans%1000000007)

Solution (Python):
n=int(input())
v=pow(10,9)+7
arr=list(map(int,input().split()))
s=sum(arr)
it=0
for item in arr:
    it+=item**2
print (((s**2-it)//2)%v)

Solution (Python):
n=int(input())
*a,=map(int,input().split())
b=[x**2 for x in a]

mod=10**9+7
print(((sum(a)**2-sum(b))//2)%mod)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
p=sum(a)
for i in range(n):
    p-=a[i]
    s[i]=p
ans=0
for i in range(n):
    ans+=(s[i]*a[i])
    ans=ans%(10**9+7)
print(ans)

Solution (Python):
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N, = map(int, input().split())

X = list(map(int, input().split()))
sx=sum(X)
sx=sx*sx
sx%=mod
for x in X:
    sx -= x**2
    sx %= mod
print(div2(sx,2))

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    ans = 0

    sum_count = sum(num_list)

    for i in range(n-1):
        sum_count -= num_list[i]
        ans += num_list[i] * sum_count
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
mod = 10**9+7
ans = 0
for i in range(1,n+1):
    di[i] = di[i-1] + ls[i-1]
for j in range(n-1):
    ans += ls[j]*(di[n]-di[j+1]) % mod
print(ans%mod)

Solution (Python):
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]
 
def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))
 
def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))
 
def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD
 
    return (num*(pow(den,MOD-2,MOD)))%MOD
 
def flush():
    return sys.stdout.flush()




'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
n = int(input())
a = arrIN()

pre = list(accumulate(a))

ans = 0
for i in range(n-1):
    ans+=(a[i]*(pre[n-1]-pre[i]))
    ans%=MOD
print(ans)

Solution (Python):
n=int(input())
c=list(map(int, input().split())) 
s = sum(c)
m = 10**9+7
S = s%m
a = 0

for i in range(n-1):
    S -= c[i]
    a += c[i]*S
    a = a%m
print(a)

Solution (Python):
p = 10**9+7
s = 0
s_sq = 0

N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    s += A[i]
    s_sq += A[i]**2
    s %= p
    s_sq %= p

print((s**2 - s_sq) * pow(2, p-2, p) % p)

Solution (Python):
n = int( input() )
a = list( map( int, input().split() ) )

MOD = 10 ** 9 + 7

sum_a = 0
for a_i in a:
    sum_a = ( sum_a + a_i ) % MOD

ans = 0
for i in range( n ):
    sum_a = ( sum_a - a[ i ] ) % MOD
    ans = ( ans + a[ i ] * sum_a % MOD ) % MOD

print( ans )

Solution (Python):
mod=10**9+7
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N)]
B[0]=sum(A)-A[0]
count=(A[0]*B[0])%mod
for i in range(1,N):
    B[i]=B[i-1]-A[i]
    count=(count+A[i]*B[i])%mod
print(count)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

MOD = 10**9 + 7

ans = 0
sum_arr = sum(arr)

for x in arr:
    sum_arr -= x
    ans += x * sum_arr
    ans %= MOD

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
S = sum(A)**2
SS = 0

for i in range(N):
    SS += A[i]**2

print(((S - SS)//2)%mod)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 +7
ans = 0

S = [0]*N

for i in range(1,N):
    S[i] = (A[N-i]+S[i-1])%mod

for j in range(1,N):
    ans += (S[j]*A[N-1-j])%mod
    ans = ans%mod

print(ans%mod)

Solution (Python):
MOD = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
rui = [A[0]]
for i in range(1,len(A)):
  rui.append((rui[-1]+A[i]) % MOD)


res = 0
for i in range(len(A)):
  res += A[i]*(rui[-1]-rui[i]) % MOD
  
print(res % MOD)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]

sm = 0
for i in range(len(a)):
    sm += a[i]

ans = 0
for i in range(len(a)):
    ans += a[i]*(sm-a[i])

ans //= 2
print(ans%(10**9+7))

Solution (Python):
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint


mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
def pref(a,n,f):             
    pre=[0]*n
    if(f==0):         
        pre[0]=a[0]
        for i in range(1,n):
            pre[i]=a[i]+pre[i-1]
    else:              
        pre[-1]=(a[-1])%mo
        for i in range(n-2,-1,-1):
            pre[i]=(pre[i+1]+a[i])%mo
    return pre
for _ in range(1):
    n=inin()
    a=ain()
    post=pref(a,n,1)+[0]
    
    s=0
    for i in range(n):
        s=(s+(a[i]*post[i+1])%mo)%mo
    print(s)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ruisekiwa = [0]
MOD = 10**9+7
for i in reversed(range(N)):
    ruisekiwa.append((ruisekiwa[-1]+A[i])%MOD)
ruisekiwa.reverse()
ruisekiwa = ruisekiwa[1:]
ans = 0
for i in range(N):
    ans += (A[i]%MOD)*ruisekiwa[i]
    ans %= MOD
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
ans = 0
cs = [0]*N
cs[0] = A[0]

for i in range(1, N):
    cs[i] = cs[i-1] + A[i]

for i in range(N-1):
    n = A[i] * (cs[-1] - cs[i]) % mod
    ans += n
    ans %= mod

print(ans)

Solution (Python):
num = int(input())
ar = list(map(int,input().split()))
mod = 10**9 + 7
somee = sum(ar)
ans = 0
for i in range(num):
    ans+=(somee-ar[i])*ar[i]
print((ans//2)%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
b = sum(a)
ans = 0
for i in range(n - 1):
    b -= a[i]
    ans += b * a[i]
    ans %= mod
print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
mod=pow(10,9)+7
su=0
ans=0
for i in range(n-1,-1,-1):
	ans=(ans+((l[i]%mod)*(su%mod))%mod)%mod
	su+=l[i]
print(ans)

Solution (Python):
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    mod = 1000000007
    N = ri()
    A  = ril()
    x = sum(A) ** 2
    y = sum(list(map(lambda i : i * i, A)))
    ans = ((x - y) // 2) % mod
    print(ans)


if __name__ == '__main__':
    main()