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:
n=int(input())
a=list(map(int,input().split()))
MOD=10**9+7
tot=(sum(a))%MOD
ans=0
for i in range(n):
  ans=(ans+a[i]*(tot-a[i]))%MOD
ans=(ans*pow(2,MOD-2,MOD))%MOD
print(ans)

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, *a = map(int, open(0).read().split())
    m = 10 ** 9 + 7
    *acm, = accumulate(a)
    ans = 0
    for i in range(n):
        rem = acm[-1] - acm[i]
        ans += rem * a[i]
        ans %= m

    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()))
MOD = 10**9+7
sum1 = sum(A)
sum2 = 0
for a in A:
    sum2 += a**2
ans = (sum1**2-sum2)//2
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = list(map(int,input().split()))
B = [A[0] % mod]
for i in range(N-1):
    B.append((B[-1] + A[i+1]) % mod)
ans = 0
for i in range(N-1):
    ans += A[-i-1] * B[-i-2]
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = 10**9+7
s = (sum(A[i]**2 for i in range(N))) % C
t = (sum(A)**2) % C
print(((t-s)*pow(2, C-2, C)) % C)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    S = 0
    for a in A:
        S += a
        S %= mod

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def examA():
    D,T,S = LI()
    if (D-1)//S<T:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    S = SI()
    T = SI()
    s = len(S)
    t = len(T)
    ans = t
    for i in range(s-t+1):
        cnt = 0
        for j in range(t):
            if S[i+j]!=T[j]:
                cnt += 1
        ans = min(ans,cnt)

    print(ans)
    return

def examC():
    N = I()
    A = LI()
    S = sum(A)
    cnt = 0
    for a in A:
        cnt += (S-a)*a
        cnt %= mod
    ans = cnt * pow(2,mod-2,mod) % mod
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    la = rli()
    su = sum(la)
    ans = 0
    mod = 10**9+7
    for a in la:
        su -= a
        ans += su*a
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
mod = 10**9+7
n = int(input())
A = tuple(map(int, input().split()))
B = [0]*n
B[0] = A[0]
for i in range(1, n):
    B[i] = B[i-1] + A[i]
    B[i] %= mod
ans = 0
for i in range(1, n):
    a = A[i]
    a *= B[i-1]
    a %= mod
    ans += a
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
li = [0]
for num in lis:
    li.append(li[-1] + num)
ans = 0
mod = 10 ** 9 + 7
for i in range(n):
    ans += (lis[i] * li[i]) % mod
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    sa=sum(A)%mod
    sa2=0
    for a in A:
        sa2+=a**2
        sa2%=mod
    i2=pow(2,mod-2,mod)
    print((sa**2-sa2)%mod*i2%mod)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n = ii()
    a = li()
    s = sum(a)
    ss = 0
    for i in a:
        ss += i**2
    print(((s**2 - ss) // 2) % 1000000007)


main()

Submission status: Accepted

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

'''
Author: andyli
Time: 2020-08-29 19:58:34
'''

import os
from io import BytesIO, IOBase
import sys

MOD =  10**9+7

def inv(x): return pow(x,MOD-2,MOD)
def main():
    n = int(input())
    a = list(map(int,input().split()))
    S = [1]
    for i in range(1,n):
        S.append(S[i-1]+a[i])
    ans=0
    for i in range(n):
        ans += a[i]*(S[n-1]-S[i])%MOD
        ans %= MOD
    print(ans)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()

Submission status: Accepted

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

s=sum(a)

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

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

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))
curr_sum = sum(al)
ans = 0
MOD = 10**9+7
for i,a in enumerate(al):
    curr_sum -= a
    ans += curr_sum*a
    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) % mod) ** 2
for i in range(n):
    ans -= a[i] ** 2
    ans %= mod
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + mod) // 2)

Submission status: Accepted

Solution code:
n = int(input())
a= list(map(int, input().split()))
s=sum(a)
INF=1000000007
ans=0

for i in range(n-1):
    s-=a[i]
    ans+=a[i]*s
    ans%=INF
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    s = sum(A) % MOD
    ans = 0

    for x in A:
        s = s - x
        s %= MOD
        ans += s * x
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

total = sum(a)
mod = 10**9 + 7

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

mod = 10**9+7

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

s = 0
s2 = 0
for a in A:
    s2 = (s2 + a*a) % mod
    s = (s + a) % mod

ans = (s*s - s2) * pow(2, mod-2, mod) % mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod =10**9+7
sd=0
sdd = 0
for i in a:
    sd+=i**2
    sdd +=i
    sd %= mod
    sdd %=mod
print((sdd**2-sd)*(5*10**8+4)%mod)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

s = [0]

for i in a:
  s.append(s[-1]+i)

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

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

Submission status: Accepted

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

s = sum(A)
ans = s*s - sum(a*a for a in A)
print(ans // 2 % mod)

Submission status: Accepted

Solution code:
# by the authority of GOD   author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase

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

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A = list(mi())

    s = 0
    t = 0
    for i in range(N):
        s += A[i]*A[i]
        t += A[i]

    print(((t*t-s)//2)%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

import sys
input=sys.stdin.readline

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
ans=0
sums=sum(arr)
for val in arr:
    ans+=(val*sums)%mod
    ans-=(val*val)%mod
print((ans*pow(2,mod-2,mod))%mod)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
s1 = 0
s2 = 0
M = 10**9+7
for item in a:
    s1 += item
    s2 += item**2
    s1 %= M
    s2 %= M
ans = (s1**2 - s2)*pow(2, M-2, M)
print(ans%M)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
s = sum(a*a for a in A)
ans = sumA*sumA - s
print((ans//2)%(10**9+7))

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

po = sum(a) % mod

ans = 0

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

Submission status: Accepted

Solution code:
mod = 10**9+7
half = 5*10**8+4
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += a[i]
  ans %= mod
ans **= 2
#print(ans)
ans %= mod
#print(ans)
for i in range(n):
  ans -= a[i] ** 2
  ans %= mod
ans *= half
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod=10**9+7
n=int(input())
a=lmp()
s=sum(a)%mod
ans=0
for i in range(n):
    s-=a[i]
    s%=mod
    ans+=a[i]*s
    ans%=mod
print(ans)

Submission status: Accepted

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

kMod = (10**9) + 7

ans = 0
s = 0

for a in A:
    ans += s * a
    s += a
    s %= kMod
    ans %= kMod
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
pfx = 0
ans = 0
mod = int(1e9) + 7
for i in a:
    ans = (ans + pfx * i) % mod
    pfx += i
print(ans)

Submission status: Accepted

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

sum_a = [0]
for v in a:
    sum_a.append(sum_a[-1] + v)

res = 0
mod = 10 ** 9 + 7
for i in range(n):
    res = (res + a[i] * sum_a[i] % mod) % mod

print(res)

Submission status: Accepted

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

sm = 0
ans = 0
for e in a:
    ans += e * sm
    ans %= mod
    sm += e
    sm %= mod

print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7

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

S = 0
T = 0

for i in range(N):
    S += A[i] **2
    T += A[i]
    S %= MOD
    T %= MOD

print((T**2 - S) * pow(2, MOD - 2, MOD) % MOD)

Submission status: Accepted

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

res = sum([a[i] ** 2 for i in range(n)])
s = sum(a)
ans = (s ** 2 - res) // 2
ans %= mod

print(ans)

Submission status: Accepted

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

s=sum(a)%mod

ans=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def cin():  return list(map(int,input().split()))

N = cin()[0]
A = cin()
S = sum(A)
INF = 10 ** 9 + 7
ans = 0
for i in range(N):
    S -= A[i]
    ans += A[i] * S
    ans %= INF
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7
n=I()
A=LI()
ret=sum(A)
r=0
for i in range(n):
    r+=(ret-A[i])*A[i]
    r%=mod

print(r*pow(2,mod-2,mod)%mod)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
mod = 10**9+7

ans = sum(A)**2
ans %= mod
a = sum(A[i]**2 for i in range(N))
a %= mod
ans -= a
ans *= pow(2,mod-2,mod)
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())
s = 0
ss = 0
MOD = 10 ** 9 + 7
for v in A:
    s += v
    ss += v * v
    s %= MOD
    ss %= MOD

out = s * s - ss
out %= MOD
if out % 2 == 1:
    out += MOD
out //= 2
print(out)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    sm = sum(a)%mod
    ans = (sm**2)%mod
    for i in a:
        ans -= i**2
        ans %= mod

    print((ans*500000004)%mod)

    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def twosekisum(A):
    return (sum(A)**2-sum([i**2 for i in A]))//2
print(twosekisum(A)%(10**9+7))

Submission status: Accepted

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

cums = [0]
for a in A:
    cums.append(cums[-1] + a)

ans = 0
for i,a in enumerate(A):
    ans += a*(cums[-1] - cums[i+1])
    ans %= MOD
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

An = [int(i) for i in input().split()]
S = sum(An)
Sn = S**2
Sn2 = 0
for a in An:
    Sn2 += a**2

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

Submission status: Accepted

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

MOD = 10**9+7

t = sum(A)**2
d = sum(a*a for a in A)
print(((t-d)//2)%MOD)

Submission status: Accepted

Solution code:
N=int(input())
MOD=10**9+7
A=[int(x) for x in input().split()]
sumA=sum(A)
ans=0
for i in range(N):
    now=A[i]
    sumA-=now
    ans+=now*sumA
    ans%=MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

MOD = 10**9+7

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

res = 0
res2 = 0
for a in A:
    res = (res + a)%MOD
    res2 = (res2 + a*a)%MOD


print(pow(2, MOD-2, MOD)*(res**2 - res2)%MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = sum(A)
    mod = 10**9 + 7
    r = 0
    for a in A:
        S -= a
        r = (r + S * a) % mod
    return r

print(main())

Submission status: Accepted

Solution code:
# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	N = int(input())
	A = getlist()
	S = sum(A)
	S %= con
	ans = 0
	for i in range(N):
		ans += A[i] * (S - A[i])
		ans %= con

	ans = ans * pow(2, con - 2, con)
	ans %= con
	print(ans)

if __name__ == '__main__':
	main()