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:
import math
import sys,collections
from sys import stdin, stdout  
#MAXN = 10000001

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip() 
def input(): return sys.stdin.readline().strip()
#spf = [0 for i in range(MAXN)] 
def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w') 
def is_subsequence(x, y):
    """Test whether x is a subsequence of y"""
    x = list(x)
    for letter in y:
        if x and x[0] == letter:
            x.pop(0)

    return not x    
def sieve(): 
	spf[1] = 1
	for i in range(2, MAXN): 
		spf[i] = i 
	for i in range(4, MAXN, 2): 
		spf[i] = 2

	for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
		if (spf[i] == i): 
			for j in range(i * i, MAXN, i): 
				if (spf[j] == j): 
					spf[j] = i 
def getFactorization(x): 
	ret = list() 
	while (x != 1): 
		ret.append(spf[x]) 
		x = x // spf[x] 

	return ret 
def getFloor(A, x):

    (left, right) = (0, len(A) - 1)

    ind,floor = -1,-1
    while left <= right:
        mid = (left + right) // 2
        '''if A[mid] == x:
            return mid'''
        if x < A[mid]:
            right = mid - 1
        else:
            floor = A[mid]
            ind=mid
            left = mid + 1
            
    return ind
def check(st) : 
  
    # Compute sum of digits 
    n = len(st) 
    digitSum = 0
      
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i]) 
  
    # Check if sum of digits 
    # is divisible by 9. 
    return (digitSum % 9 == 0)     
def isPowerOfTwo(n): 
    if (n == 0): 
        return False
    while (n != 1): 
            if (n % 2 != 0): 
                return False
            n = n // 2
            
              
    return True
def kitte(n):
	c=0
	while(n!=0):
		n=n//2
		c+=1
	return c	
def aa(b,c):
	m=min(b,c)
	b-=m
	c-=m
	if(c>0 and b>0):
		return(m+((b+c)//3))
	else:
		return(m)
def bb(a,c):
	m=min(a,c)
	a-=m
	c-=m
	if(c>0 and a>0):
		return(m+((a+c)//3))
	else:
		return(m)
def cc(b,a):
	m=min(b,a)
	b-=m
	a-=m
	if(a>0 and b>0):
		return(m+((b+a)//3))
	else:
		return(m)		
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = (array_sum + A[i])
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = (array_sum * array_sum)
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += (A[i] * A[i])
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum) // 2		
#file()
#sieve() 
mod=(10**9)+7	
def main():
		n=int(input())
		l=get_array()
		s=0
		s=findProductSum(l,n)
		print(s%mod)		

	



	

	
			


		




		






		







			



	

	




	





















	




















		
			


		

			

		





			

	























				

	















	

	










if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, permutations, combinations, accumulate
from bisect import bisect_left, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor


def input_list():
    return list(map(int, input().split()))


def input_int():
    return int(input())


N = int(input())
A_LI = input_list()
A_ACC = list(accumulate(A_LI))
MOD = 10 ** 9 + 7
ans = 0
for i in range(1, N):
    ans += A_LI[i] * A_ACC[i - 1]
print(ans % MOD)

Submission status: Accepted

Solution code:
n=int(input())
alist=list(map(int,input().split()))
MOD=10**9+7
nijo=0
for i in range(n):
    nijo+=(alist[i]**2)
gokei=sum(alist)

ans=(gokei**2-nijo)
ans=ans//2
ans=ans%MOD
print(ans)

Submission status: Accepted

Solution code:
# abc177_c.py
# https://atcoder.jp/contests/abc177_c


# [開発時用] ログ関数
def lg(value):
    flag = False
    # flag = True
    if flag:
        print(str(value))


# [開発時用] exit処理
def xt(log):
    lg('★exit() - ' + str(log))
    exit()


# 本体
def get_results():

    # 引数処理部
    lines = list()
    # 仕様でn行と決まっている場合(の例)
    lines_count = 2
    # 先頭行のNで行数が決まる場合(の例)
    # line = input()
    # lines.append(line)
    # N = int(line)
    # lines_count = N
    for _ in range(lines_count):
        lines.append(input())

    # 演算部
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    lg(f'values=[{values}]')

    targets = list()
    # [1, 2, 3] => targets = [3, 5]
    su = 0
    for j in range(1, N):
        # targets.append(3)
        # targets.append(5)
        su += values[N - j]
        targets.append(su)

    su = 0
    for i in range(N-1):
        # for j in range(i+1, N):
        #     target += values[j]
        su = (su + values[i] * targets[N-2-i]) % (10**9+7)

    return [su]


# 主処理
def main():
    results = get_results()

    for result in results:
        print(result)


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
suma, ans = sum(v), 0
for i in range(n - 1):
    suma -= v[i];
    ans += (suma * v[i])
print(ans % 1000000007)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()

ruiseki = [a[-1]]
for i in range(1,n):
	ruiseki.append(ruiseki[i-1]+a[i*-1-1])

ans = 0

for i in range(n-1):
	ans = (ans+(a[i]%(10**9+7)*(ruiseki[-1*i-2]%(10**9+7)))%(10**9+7))%(10**9+7)


print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
A_list = list(map(int, input().split()))
ans = 0
SUM = sum(A_list)
for i in range(N):
    SUM -= A_list[i]
    if i != N -1:
        ans += A_list[i] * SUM
while ans >= 10 ** 21 + 7000000000000:
    ans -= 10 ** 21 + 7000000000000
while ans >= 10 ** 19 + 70000000000:
    ans -= 10 ** 19 + 70000000000
while ans >= 10 ** 17 + 700000000:
    ans -= 10 ** 17 + 700000000
while ans >= 10 ** 15 + 7000000:
    ans -= 10 ** 15 + 7000000
while ans >= 10 ** 13 + 70000:
    ans -= 10 ** 13 + 70000
while ans >= 10 ** 11 + 700:
    ans -= 10 ** 11 + 700
while ans >= 10 ** 9 + 7:
    ans -= 10 ** 9 + 7
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import itertools

def main():

    input = stdin.readline

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

    mod = (10 ** 9) +7

    ans = 0

    total = sum(A)

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    AArray = LI()
    MOD = 1000000007
    aSum = sum(AArray)
    nowAsum = 0
    ans = 0

    for i in range(N-1):
        a = AArray[i]
        nowAsum += a
        asum = aSum-nowAsum
        asum %= MOD
        ans += a*asum % MOD
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# C Sum of product of pairs

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

s = 0
old = 0
for i in range(N-1):
  old += A[i]
  s += old * A[i+1]
        
print(s % (10**9 + 7))

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())]
MOD = (10**9)+7
ans = 0

# print(A)

sum_a = [0] * (n+1)
for i in range(n):
    sum_a[i+1] = sum_a[i] + A[i]

# print(sum_a)

for i in range(n):
    ai = A[i]
    ans = (ans + ai*(sum_a[-1] - sum_a[i+1])) % MOD
    # print(sum_a[-1], sum_a[i+1],sum_a[-1] - sum_a[i+1] )

# for i in range(n):
#     for j in range(i+1, n):
#         ans = (ans + A[i]*A[j]%MOD) % MOD
ans = (ans + MOD) % MOD
print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9+7

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

arr = [a[-1]]
for i in range(len(a)-2,-1,-1):
    arr += [arr[-1] + a[i]]

arr.reverse()
ans = 0
for i in range(len(a)-1):
    
    ans += (a[i] * (arr[i]-a[i]))%MOD
   
print(ans%MOD)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    m = 1000000007
    ans = 0
    ss = sum(a[1:])
    for i in range(n-1):
        ans += a[i]*ss
        ss -= a[i+1]
        ans %= m
    print(ans)

main()

Submission status: Accepted

Solution code:
import numpy as np
MOD = 10**9+7
n = input()
a = list(map(int, input().split()))
ans = 0
cum_a = np.cumsum(a[::-1])
cum_a = cum_a[::-1]
for i, ai in enumerate(a):
  if i == len(a)-1:
    continue
  sum_aj = cum_a[i+1]
  ans += ((ai%MOD)*(sum_aj%MOD))%MOD

print(ans%MOD)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=0
m=1000000007
s1=sum(l)
s1=(s1*s1)
s2=0
for i in range(n):
  s2=s2+l[i]*l[i]
print(((s1-s2)//2)%m)

Submission status: Accepted

Solution code:
#
# abc177 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 2 3"""
        output = """11"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
141421356 17320508 22360679 244949"""
        output = """437235829"""
        self.assertIO(input, output)


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

    S = sum(A)
    ans = 0
    for a in A:
        S -= a
        ans += a * S

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


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

from itertools import combinations

num = 10**9 + 7
ans = 0

B = []
b = 0
for i in reversed(A[1:]):
    b += i
    B.append(b)
B.reverse()
for x, y in zip(A[:-1], B):
    ans += x*y
    ans %= num
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
lst = list(map(int,input().split()))
s = 0
t = 0
for x in lst:
  s += x
  t += (x ** 2) % (10**9+7)

w = (s**2-t) % (10**9+7)
if w % 2 == 0:
  print(w//2)
else:
  print((w+10**9+7)//2)

Submission status: Accepted

Solution code:

def findProductSum(A, n):

    array_sum = 0
    for i in range(0, n, 1):
        array_sum = array_sum + A[i]

    # calcualting square of array sum
    # (a1 + a2 + ... + an)^2
    array_sum_square = array_sum * array_sum

    # calcualting a1^2 + a2^2 + ... + an^2
    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


def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    # n = len(A)
    mod = (10**9) + 7
    print(int(findProductSum(A, n))%mod)

main()

Submission status: Accepted

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

sum_ = 0
temp = 0
for i in range(len(a)-1):
    temp += a[-i-1]
    sum_ += temp * a[-i-2]

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N = a_int()
A = ints()
B = [0] * N
for a in A:
    B[0] += a
    B[0] %= MOD
for i in range(1, N):
    B[i] = B[i - 1] - A[i - 1]
    B[i] %= MOD

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.reverse()
ans=0
tempsum=0
for i in range(len(A)-1):
    tempsum+=A[i]
    ans=ans+tempsum*A[i+1]

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

Submission status: Accepted

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

a_sum = sum(a)
ans = 0
for i in range(n):
    a_sum -= a[i]
    ans += a[i] * a_sum

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

Submission status: Accepted

Solution code:
from sys import stdin
from collections import defaultdict
readline = stdin.readline
read = stdin.buffer.read
def r_map(): return map(int, readline().rstrip().split())
def r_list(): return list(r_map())

MOD = 10 ** 9 + 7
# import numpy as np
# from numba import jit
# stdin = open('sample.txt')

def main():
    N = int(readline().rstrip())
    A = r_list()
    A.sort()
    ans = 0
    a_dic = defaultdict(lambda: 0)
    for j, a in enumerate(A[:0:-1]):
        i = N - 2 - j
        a_dic[i] += a
        if i > 0:
            a_dic[i - 1] = a_dic[i]
    for i, a in enumerate(A[:-1]):
        ans += a * a_dic[i]
    print(ans % MOD)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
s=[]
sum_a=0
for i in range(n-1):
    sum_a+=A[i]
    ans+=sum_a*A[i+1]
    #s.append(sum_a)
print(ans%mod)
"""
for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        ans+=A[i]*A[j]
        
print(ans%mod)
"""

Submission status: Accepted

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

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
prev = 0
s = []
for a in A:
    now = prev + a
    s.append(now)
    prev = now

start = 0
last = s[-1]
for i in s[:-1]:
    ans += (i - start) * (last - i)
    start = i
    
    
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

sm = sum(a)
ans = 0

for i in range(len(a)):
    ans += a[i]*(sm-a[i])
    sm = sm - a[i]
    ans %= (10**9)+7
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = tuple(map(int,input().split()))
t = 0
mod = 10**9 + 7
at = []
for j in range(1,n):
  t += a[n-j] % mod 
  at.append(t)

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

Submission status: Accepted

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

sum1=0
sum2=0

for i in arr:
    sum1+=i
    sum2+=i**2

print(((sum1**2-sum2)//2)%(10**9+7))

Submission status: Accepted

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

waru = 7 + 1000000000

asum = 0

for i in a:
  asum += i
  
mod = 0
asum -= a[0]
for i in range(len(a)-1):

  mo = (a[i] * (asum)) % waru
  mod += mo

  asum -= a[i+1]
  
print(mod % waru)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

mod = 10**9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Asum = [0] * N
    Asum[0] = A[N - 1]
    for i in range(1, N):
        Asum[i] = Asum[i - 1] + A[N - 1 - i]
    ans = 0
    for i in range(N - 1):
        ans += (A[i] * Asum[N - 2 - i]) % mod
        ans %= mod
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum1 = sum(A)
sum2 = 0
for i in range(N-1):
    sum1 -= A[i]
    sum2 += A[i] * sum1
print(sum2 % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
n = int(input())
arr  = input().split(" ")
s = int(arr[-1])
mod = 10**9 +7
ans  = 0

def moduloMultiplication(a, b, mod): 
    res = 0; 
    a = a % mod; 
    while (b): 
        if (b & 1): 
            res = (res + a) % mod; 
        a = (2 * a) % mod; 
  
        b >>= 1;
      
    return res; 

for i in range(len(arr)-2, -1, -1):
    t = int(arr[i])
    ans = (ans+  moduloMultiplication(s,t,mod))%mod
    s = (s+t)
print( ans)

Submission status: Accepted

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

all_sum = 0
for i in a:
    all_sum += i

ans = 0
for i in a:
    all_sum = all_sum - i
    ans = (ans + i * all_sum) % (pow(10, 9) + 7)
print(ans)

Submission status: Accepted

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

sum_a = sum(a)
ans = 0
for i in range(n-1):
  sum_a-=a[i]
  ans += a[i]*sum_a
  ans = ans%(10**9+7)
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

Sam = sum(A)
#print(Sam)
result = 0

for n in range(N-1):
    Sam = Sam - A[n]
    result += Sam * A[n]
    result = result % 1000000007
print(result)

Submission status: Accepted

Solution code:
n=int(input())
aa=list(map(int,input().split()))
su=sum(aa)
new=[n**2 for n in aa]
sa=sum(new)
x=10**9+7
print((su**2-sa)//2%x)
sa

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    past_a = 0

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        ans += a * past_a
        past_a += a

    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
list_a = [int(x) for x in input().split(' ')]

# sum_a = sum(list_a) % (10**9+7)
# sum_a2 = sum([(x**2) % (10**9+7) for x in list_a])
sum_a = sum(list_a)
sum_a2 = sum([x**2 for x in list_a])

print(((sum_a ** 2 - sum_a2) // 2) % (10**9+7))

Submission status: Accepted

Solution code:
from sys import stdin, stdout,stderr
import time,math
from collections import defaultdict as dd
 
def pn(ob):stdout.write(str(ob))
def inp():return stdin.readline()

mod = 10**9 + 7

def main():
	n = int(inp())
	arr = list(map(int, inp().split()))

	tot = 0
	res = 0

	for x in arr:
		tot += x
		tot %= mod

	for x in arr:
		tot -= x
		res = (res + (x * tot)% mod) % mod
		res %= mod

	pn(res)
  
if __name__ == '__main__':
	main()
	
#n,m=map(int,input().split()) 
# for i in range(n):
#     t=int(stdin.readline()) # input using fast i/p method 
#     if t%m == 0:
#         stdout.write(str(t)+'\n') #input using fast o/p method
 
# take line of integers as input
# 	arr = list(map(int, inp().split()))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = 0
b = 0
mod = 10**9 + 7
for i in range(N):
    a += A[i]
    b += A[i]**2
    a = a 
    b = b 
a = a ** 2 
ans = (a - b) // 2 % mod
if ans < 0:
    ans += mod
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
#myans_list =  [ [0 for n in range(N)] for nn in range(N) ]
#myans = 0
#for n in range(N):
#    for nn in range(N):
#        myans_list[n][nn] = A_list[n] * A_list[nn]
#for n in myans_list:
#    print(n)
mysum = sum(A_list)
myans = 0
for n in range(N-1):
    mysum -= A_list[n]
    myans +=  mysum*A_list[n]
print(myans%(1000000007))

Submission status: Accepted

Solution code:
def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()
d = 10**9 + 7
B = [A[i] % d for i in range(len(A))]

s = 0
s2 = 0
for i in range(len(B)):
    s += B[i]
    s = s
    s2 += B[i] ** 2
    s2 = s2

ans = ((s**2 - s2) // 2) % d

print(ans)

Submission status: Accepted

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

wa = sum(suji)
goukei = 0

for i in range(N):
    goukei += suji[i] * (wa - suji[i])
    wa -= suji[i]

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

Submission status: Accepted

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

ans = 0
sum = sum(A)

for i in range(1,N):
    sum -= A[i-1]
    ans += A[i-1] * sum
    ans = ans % 1000000007

print(ans)

Submission status: Accepted

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

ruiseki = [0 for _ in range(N+5)]
for i in range(N):
    ruiseki[i+1] = ruiseki[i] + A[i]

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

print(ans)

Submission status: Accepted

Solution code:
def INT():
    return int(input())

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

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

N = INT()
A = LI()
mod = 10**9 + 7
sm = sum(A) - A[0]
ans = 0

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

Submission status: Accepted

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

ans = 0

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

for i in range(len(a)-1):
  ans = ans % 1000000007 + ((a[i] - a[i+1]) * a[i+1]) % 1000000007
    
print(ans % 1000000007)

Submission status: Accepted

Solution code:

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

mod=10**9+7

sumA=sum(A)

ans=0
for i in range(N):
    ans+=(A[i]*(sumA-A[i]))

ans=ans//2
print(ans%mod)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	S = sum(A)
	res = 0
	v = 10**9+7
	for i in range(N-1):
		S -= A[i]
		res += A[i] * S
	print(res%v)
resolve()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    MODULO = 10**9 + 7
    n = int(input())
    A = list(map(int, input().split()))
    total = 0
    sq = 0
    for i in range(n):
        total = (total + A[i]) #% MODULO
        sq = (pow(A[i], 2) + sq) #% MODULO
    total = ((pow(total, 2) - sq) // 2) % MODULO
    print(total )

Submission status: Accepted

Solution code:
n = int(input())

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

total = sum(a)
ans = 0
for i in a:
    total -= i
    ans = (ans + (i * total)) % mod

print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]

sum = 0
squaresum = 0
for i in range(N):
    sum = (sum + A[i]) % MOD
    squaresum = (squaresum + A[i]**2) % MOD
ans = ((sum**2) % MOD - squaresum) % MOD
if ans % 2 == 0:
    print(ans//2)
else:
    print((ans + MOD)//2)

Submission status: Accepted

Solution code:
N,*A = map(int, open(0).read().split())
Asq=[a**2 for a in A]
S = (sum(A)**2-sum(Asq))//2
print(S%(10**9+7))

Submission status: Accepted

Solution code:
import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

MOD = 10 ** 9 + 7

N = I()
A = LI()
ans = 0

# A = np.array(A)
sum = [0]*(N+1)
for i in range(N):
        sum[i+1] = sum[i]+A[i]

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

       
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(s) for s in input().split()]

mod_number = 10**9 + 7
sum_A = sum(A)
total = 0
for i in range(0, N - 1):
    sum_A = sum_A - A[i]
    total += A[i] * sum_A

ans = total % mod_number

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    memo = As[0]
    res = 0
    for i in range(N-1):
        res += (memo * As[i+1])%(10**9 + 7)
        memo += As[i+1]

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


if __name__ == "__main__":
    resolve()