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):
from itertools import accumulate


def main():
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    ac = list(accumulate(a))
    ans = 0
    for i in range(n):
        ans += a[i] * (ac[-1] - ac[i])
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
ans=0
tmp=sum(A)
for x in A:
    tmp-=x
    ans+=x*tmp
    ans%=MOD
print(ans)

Solution (Python):



 
import sys
import math



 

fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile


mod=1000000007
 

def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 

t=1
for tt in range(t):
    n=int(input())
    
    a=list(map(int,sys.stdin.readline().split(' ')))
    s=sum(a)

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

if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Solution (Python):
n=int(input())
mod1,mod2=10**9+7,998244353
mod=mod1
ans=0
s=0
for i in map(int,input().split()):
    ans=(ans+s*i)%mod
    s=(s+i)%mod
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
s = 0
for a in A:
    ans = (ans + s * a) % mod
    s = (s + a) % mod
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7

n = int(input())
alst = list(map(int, input().split()))
total = sum(alst)
ans = 0
for a in alst:
    ans += a * (total - a)
    ans %= MOD
ans *= pow(2, MOD - 2, MOD)
ans %= MOD
print(ans)

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

Solution (Python):
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]


from collections import defaultdict as ddic, Counter, deque
import heapq, bisect, itertools
MOD = 10 ** 9 + 7

N = rri();A=rrm()

S = sum(A)
S %= MOD
ans = S*S % MOD
for x in A:
    ans -= x*x % MOD
    ans %= MOD
ans *= pow(2, MOD-2, MOD)
ans %= MOD
print ans

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

Solution (Python):
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()
mod = 1000000007

s = sum(a)
s2 = 0
for u in a:
    s2 += u*u
print((s*s - s2) // 2 % mod)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    S = 0
    T = 0
    for a in A:
        S = (S + a)%mod
        T = (T + (a*a)%mod)%mod
    print(((((S * S)%mod - T)%mod) * pow(2, mod-2, mod))%mod)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [i* i for i in a]
print((sum(a)**2 - sum(b))//2 % (10**9+7))

Solution (Python):
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  mod = 10**9+7
  ans = sum(A)**2
  for i in range(N):
    ans -= A[i]**2
  ans //=2
  return ans%mod
print(solve())

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=(S[i]+A[i])%mod
        
    ans=0
    for i in range(N):
        a=A[i]
        s=S[-1]-S[i+1]
        ans=(ans+a*s)%mod
        
    print(ans)
        
        

main()

Solution (Python):

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
s = 0
ans = 0
for i in range(N):
    ans += s * A[i]
    s += A[i]
    ans %= mod
    s %= mod

print (ans)