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



Sample input:
3
1 2 3


Sample output:
11

Submission status: Accepted

Solution code:
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):
    #print(n-1-i)
    ans += a[i]*sum_a[n-2-i]
    ans %= mod
    
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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(a, b)

print(ans)

Submission status: Accepted

Solution code:



#for _ in range(int(input())):
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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
# input = sys.stdin.readline 
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 )

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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
##import numpy as np
#sys.setrecursionlimit(10**7)
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):         ##from beginning
        pre[0]=a[0]
        for i in range(1,n):
            pre[i]=a[i]+pre[i-1]
    else:              ##from end
        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)
    
    
            
    
    
        
    

        
        
        
    
    
    

        
    

        
        
    
        
    
    
            
    
        
    
    
    

                    
                    
                    
                    
                    
        
    
    
    
    
            
        
    

            
            
            
            
        
        
                
                
    

    
    
    
    
    

                    
                
    

    

        


    
        

    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
        
    
    
    
    


    




##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):             
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24 
##def kadane(a,size): 
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##       
##    for i in range(0, size): 
##        max_ending_here = max_ending_here + a[i] 
##        if (max_so_far < max_ending_here): 
##            max_so_far = max_ending_here 
##  
##        if max_ending_here < 0: 
##            max_ending_here = 0   
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    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 kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    a=list(map(int,input().split()))
    totalsum=sum(a)%MOD
    total=0
    temp=0
    for i in range(n):
        temp+=a[i]%MOD
        total+=((totalsum-temp)*a[i])%MOD
    print(total%MOD)



if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
input = lambda: sys.stdin.readline().rstrip('\r\n')

mod = int(pow(10, 9) + 7)

n = int(input())
a = list(map(int, input().split()))
x = a[:]
b = a[::-1][:]
b = list(accumulate(b))
a = b[::-1][:]
ans = 0
for i in range(n - 1):
    ans += (x[i] * a[i + 1]) % mod
print(ans % mod)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()

    # dct = defaultdict(lambda: 0)
    # for a in A:
    #     dct[a] += 1
    # print(dct)
    MOD = 1000000007
    sm = sum(A)
    ans = 0
    for a in A[:-1]:
        sm -= a
        # print(sm)
        ans += a * sm
        ans %= MOD

    print(ans % MOD)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
suml=sum(l)
num=0
for i in range(n-1):
    suml-=l[i]
    num+=(l[i]*suml)%(10**9+7)
print(num%(10**9+7))

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
mod = 10 ** 9 + 7
S = sum(A)

res = 0
for i in range(N):
    S -= A[i]
    res += (S % mod) * (A[i] % mod) % mod

print(res % mod)

Submission status: Accepted

Solution code:
import sys

def mmul(a,b):
	return ((a%m)*(b%m))%m

def madd(a,b):
	return (a%m+b%m)%m

def msub(a,b,):
	return (a%m-b%m+m)%m

N=int(sys.stdin.readline())

A=[int(i) for i in sys.stdin.readline().split()]

m=pow(10,9)+7

pre=[0]

for h in range(N):
	pre.append(madd(A[h],pre[h]))

ans=0

for p in range(N-1):
	val=mmul(A[p],msub(pre[N],pre[p+1]))
	ans=madd(ans,val)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
mod = pow(10, 9) + 7
ans = 0
summ = 0
for i in range(1, n):
  summ += lst[i]
  summ %= mod
for i in range(n - 1):
  ans += lst[i] * summ
  ans %= mod
  summ -= lst[i + 1]
  summ %= mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cum=[0]
for i in range(N):
  cum.append(cum[-1]+A[i])
  
ans = 0
for i in range(N-1):
  ans += A[i]*(cum[-1]-cum[i+1])
  ans %= mod
  
print(ans)

Submission status: Accepted

Solution code:
import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############

def diff(S, i, T):
    res = 0
    for j in range(len(T)):
        if S[i + j] != T[j]:
            res += 1
    return res

def solve():
    N = inp()
    AA = inlt()
    M = 10 ** 9 + 7
    s = 0
    res = 0
    for i in range(N - 1, 0, -1):
        s = (s + AA[i]) % M
        res = (res + (AA[i - 1] * s) % M) % M
    return res

    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
s = sum(a)
# for i in a:
#     s  = s*a % mod
ans = 0
for i in a:
    ans = (ans + (s-i)*i) % mod
print(ans*pow(2,mod-2,mod) % mod)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, As):
    mod = 10 ** 9 + 7
    tmp = sum(As)
    mlt = []
    for i in range(N):
        tmp -= As[i]
        mlt.append(tmp)
    ans = 0
    for i in range(N):
        ans += (As[i] * mlt[i]) % mod
        ans %= mod
    print(ans)


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]

    # test
    # N = 2 * 10 ** 5
    # As = [10 ** 9 for _ in range(N)]
    solve(N, As)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split())) 

p = 10**9+7

sal = sum(al)  % p

import itertools
cumsum = list(itertools.accumulate(al))

temp = 0

for i in range(n):
    temp += (sal-cumsum[i]) *al[i]
    temp = temp % p

print(temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()

B = sum(A) * sum(A)
taikaku = 0
for a in A:
    taikaku += a * a  
ans = (B - taikaku) // 2
print(ans % mod)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
n = int(input())
A = list(int(x) for x in input().split())
acc = [A[-1]]
for a in reversed(A[:-1]):
    acc.append((acc[-1] + a) % MOD)
acc.reverse()

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

Submission status: Accepted

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

mod=10**9+7

inv = pow(2,mod-2,mod)

tmp1=0
for i in range(N):
    tmp1+=A[i]
    tmp1%=mod

tmp2=0
for i in range(N):
    tmp2+=A[i]**2
    tmp2%=mod

res = tmp1**2-tmp2
res %= mod
res *= inv
res %= mod

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
mod = 1000000007
a = [int(i)%mod for i in input().split()]
s = [0]*(n+1)
for i in range(n)[::-1]:
    s[i] = (s[i+1] + a[i])%mod
ans = 0
for i in range(n-1):
    ans += s[i+1]*a[i]%mod
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
t = [0]
t.append(a[-1])
for i in range(n - 2, -1, -1) :
    t.append((t[-1] + a[i]) % mod)
ans = 0
for i in range(n) :
    ans = (ans + a[i] * t[n - i - 1]) % mod
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations, accumulate
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    A = list(map(int, input().split()))
    cA = list(accumulate(A))
    ans = 0
    for i in range(N - 1):
        term = A[i] * (cA[-1] - cA[i]) % MOD
        ans = (ans + term) % MOD
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ttl = sum(A)
ttl -= A[0]

ans = 0
mod= 10**9+7
for i in range(len(A)-1):
    ans += A[i]*ttl
    ttl %= mod
    ans %= mod
    ttl -= A[i+1]
    # print(ans,ttl)
print(ans)

Submission status: Accepted

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

print((sum(A)**2 - sum(a**2 for a in A)) // 2 % (10**9+7))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10 ** 9 + 7

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

S = 0
for a in A:
    S += a
    S %= MOD

ans = 0

for a in A:
    t = (S - a) * a
    t %= MOD
    ans += t
    ans %= MOD

fact = [1]
fact_inv = [1]  # numpyなし
for i in range(10):
    new_fact = fact[-1] * (i + 1) % MOD
    fact.append(new_fact)
    fact_inv.append(pow(new_fact, MOD - 2, MOD))

ans *= fact_inv[2]
ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
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=ans//2
print(ans%mod)

Submission status: Accepted

Solution code:
# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
S = sum(A)%mod
ans = 0
for k in range(N-1):
  S -= A[k]
  S %= mod
  ans += S*A[k]
  ans %= mod
print(ans)

Submission status: Accepted

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

mod = pow(10,9)+7

x = (sum(a)**2)%mod
y = 0
for i in range(n):
	y += (a[i]**2)%mod
print((x-y)*(pow(2,mod-2,mod))%mod)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
t=sum([i*i for i in a])
print(((s*s-t)//2)%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())

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

suff = []

mod = 10**9+7

s = 0
suff.append(s)
for i in range(n-1, -1, -1):
    s = (s%mod + a[i]%mod)%mod
    suff.append(s)


res = 0

for i in range(n):
    
    curr = (suff[n-1-i]%mod * a[i]%mod)%mod
    res = (res%mod + curr%mod)%mod

print(res)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

n = int(input())
a = [int(x) for x in input().split()]
ans = 0
sum = a[n-1]
for i in range(n-2, -1, -1):
    ans = (ans + sum * a[i]) % mod
    sum += a[i]
ans %= mod

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = sum(a) ** 2
for i in range(n):
  ans -= a[i] ** 2
ans //= 2
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
As = list(map(int, input().split()))
D = 10 ** 9 + 7
ans = 0
s = sum(As)

for a in As:
  ans += (s-a) * a
  
print(ans // 2 % D)

Submission status: Accepted

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

MOD = 1000000007

sum_a = sum(a) % MOD 
sum_aa = sum((ai * ai) % MOD for ai in a) % MOD

mod_inv = pow(2, -1, MOD) 

ans = ((((sum_a * sum_a) % MOD) - sum_aa) * mod_inv) % MOD

print(ans)

Submission status: Accepted

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

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + A[i]

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

Submission status: Accepted

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


sum = 0

for i in range(n):
  s -= a[i]
  if s < 0:
    s += m
  sum += a[i] * s
  sum %= m

print(sum)

Submission status: Accepted

Solution code:
from itertools import accumulate

def resolve():
    n = int(input())

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

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())

nlist = list(map(int, input().split()))
tsum = sum(nlist)

result = 0
for i in nlist:
    tsum -= i
    result += i*tsum
    result %= (10**9+7)

print(result)

Submission status: Accepted

Solution code:
import sys

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


def add(a, b, BIGMOD):
    return (a + b) % BIGMOD


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


A_Sum = sum(A)
Sum = 0
BIGMOD = 10 ** 9 + 7

for i in range(N - 1):
    A_Sum -= A[i]
    Sum = add(Sum,mul(A[i], A_Sum, BIGMOD),BIGMOD)

print(Sum)

Submission status: Accepted

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

B = list(map(lambda x : x**2 , A))
x = sum(A)
y = sum(B)
ans = (x**2 - y) // 2

print(ans%(10**9 + 7))

Submission status: Accepted

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

p = 10 ** 9 + 7

suma = 0
dsum = 0
for i in a:
  suma = (suma + i) % p
  dsum = (dsum + i ** 2) % p

sa2 = (suma ** 2) % p
ans2 = (sa2 - dsum) % p
if ans2 % 2  == 0:
  ans = ans2 // 2
else:
  ans = (ans2+p) // 2
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    md = 10**9+7

    S = list(reversed(A))

    for i in range(1,N):
        S[i] = (S[i-1]+S[i])%md
    
    S.reverse()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i in range(N):
    a = As[i]
    ans += (SUM-a)*a
    ans %= mod
print(ans*pow(2, mod-2, mod)%mod)

Submission status: Accepted

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

A_acc=[sum(A)]
for a in A:
    A_acc.append(A_acc[-1]-a)

MOD=10**9+7

ans=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    mod = 10**9+7
    S = sum(a)
    ans = 0
    for i in range(n):
        ans += (a[i] * (S-a[i]))
    print(ans//2%mod)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sums = [sum(a)]
cnt = 0
N = 10 ** 9 + 7

for i in range(n-1):
    sums.append((sums[-1] - a[i]) % N)

for i in range(n-1):
    cnt += a[i] * sums[i+1]
    cnt %= N

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(w) for w in input().split()]

ans = 0
mod = 10**9 + 7
s = sum(x)

for i in range(n):
    ans += ((x[i])**2)

ans = (s**2 - ans)//2
print(ans%mod)