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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()
S = sum(A)

SS = sum(a*a for a in A)

print(((S*S-SS)//2)%MOD)

Submission status: Accepted

Solution code:
LI = lambda: list(map(int, input().split()))

N = int(input())
A = LI()

MOD = 10 ** 9 + 7


def modinv(x):
    return pow(x, MOD - 2, MOD)


def main():
    s = sum(A) % MOD
    ans = s * s % MOD
    for a in A:
        ans = (ans - a ** 2) % MOD
    ans = ans * modinv(2) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=input()
a=[int(i) for i in raw_input().split()]
s=0
for i in a:
    s+=i
c=0
for i in a:
    c+=i*s-i*i
print (c/2)%(10**9+7)

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, -1, mod)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = [0] * (n+1)
    for i in range(n):
        c[i+1] = c[i] + a[i]

    ans = 0
    for i in range(n):
        ans += a[i] * (c[n] - c[i+1])
        ans %= mod
    print(ans)
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):
    ans += (s-a[i]) * a[i]
print((ans//2)%1000000007)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
Asum = list(accumulate(A))
X = Asum[-1]

ans = 0
for i, a in enumerate(A[:-1]):
    ans += a * (X - Asum[i])
    ans %= mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, *aaa = map(int, sys.stdin.buffer.read().split())
ans = sum(aaa) ** 2
ans -= sum(a ** 2 for a in aaa)
ans //= 2
print(ans % (10 ** 9 + 7))

Submission status: Accepted

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

ssum = sum(a)

ans = 0
for i in a:
    ssum -= i
    ans += ssum*i%(10**9+7)

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

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
s=sum(arr)
ans=0
m=10**9+7
c=0
for i in arr:
    c+=i
    ans+=i*(s-c)
    ans%=m
print(ans)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    arr = list(map(int, input().split()))
    arr_sum = sum(arr)
    arr_sum_sqr = arr_sum**2
    res = sum(i**2 for i in arr)
    res = (arr_sum_sqr - res) // 2
    print(res % (10**9+7))


def main():
    t = 1
    while t > 0:
        solve()
        t -= 1


main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
sm = sum(a)
res = 0
div = pow(2, mod - 2, mod)
for x in a:
  res += x * (sm - x)
  res %= mod
print(res * div % mod)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
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

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    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)
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
assert len(A) == N
total = 0
sumA = []
for i,ai in enumerate(A):
  sumA.append(sum(A[i+1]))

for i,ai in enumerate(A):
  total += ai * sumA[i]
print(total % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
total = 0
for i in range(1, N+1):
  for j in range(i, N+1):
    total += A[i] * A[j]
print(total)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
add = 0
for i in range(N):
    tmp = sum(A[i+1:N])
    add += tmp * A[i]
print(add%mod

Submission status: Runtime Error

Solution code:
def SumOfProduct(n, arrayA):
  ans = 0

  for i in range(0, len(arrayA)):
    for j in range(i + 1, len(arrayA)):
      ans += arrayA[i] * arrayA[j]

  print(ans)

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

SumOfProduct(n, arrayA)

print(a+b+c+d+e+f)

Submission status: Runtime Error

Solution code:
f=open('in','r')
input=lambda:f.readline().strip()

n=int(input())
r=list(map(int,input().split()))
mod=1000000007
s=sum(r)%mod
x=0
for u in r:
  x+=u**2
x%=mod
t=500000004
print((s**2-x)*t%mod)

Submission status: Runtime Error

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

mod = 7 + 10**9
for i in A:
	A[i] %= mod
for j in range(N-1): 
	for	k in range(j+1, N):
		t = A[j] * A[k] 
		ans += t

ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
#N = int(input())
#A = list(map(int, input().split()))
n, a = input().split("\n")
N = int(n)
A = list(map(int, a.split()))

mod = 7 + 10**9
s = 0

for i in range(N-1): 
	for	j in range(i+1, N):
		t = A[i] * A[j] % mod
		s += t

ans = s % mod
print(ans)

Submission status: Runtime Error

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

for i in range(N-1): 
	for	j in range(i+1, N):
		t = A[i]*A[j] % (10**9+7)
		sum = sum(t)

print(sum)

Submission status: Runtime Error

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

for i in range(N-1) and j in range(i+1, N):
	t = A[i]*A[j] % (10**9+7)
	sum = sum(t)

print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
L=len(str(max(A)))//4
A=A/10**L

x=np.sum(np.outer(A,A))-np.sum(A*A)
print(int(x/2*10**(2*L)%(10**9+7)))

Submission status: Runtime Error

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

count = 0

stack = set()
visited = []
visited_set = set()
endf = False

current = 0
while True:
    i = A[current]-1
    visited_set.add(current)
    visited.append(current)

    if not i in visited_set:
        current = i
        count += 1
    else:
        leng = len(visited_set)
        roop_len = leng - visited.index(i)
        header_len = leng - roop_len
        break

    if count >= K:
        endf = True
        print(i+1)
        break

if not endf:
    roop_ind = (K - header_len + 1) % roop_len
    if roop_ind == 0:
        print(visited[-1]+1)
    else:
        print(visited[header_len + roop_ind-1]+1)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
print(np.sum(np.tril(np.outer(np.array(A), np.array(A)), k = -1)) % (10 ** 9 + 7))

Submission status: Runtime Error

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

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

# answer = s % (10**9+7)
print(answer)

Submission status: Runtime Error

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

for i in range(1,N-1):
  for j in range(i,N):
    K = sum(A[i]*A[j])

print(K)

Submission status: Runtime Error

Solution code:
n = int(input())
mod = 10 ** 9 + 7
import numpy as np
a = list(map(int, input().split())
s=0
ss=0
for i in range(n):
    ss += a[i]%mod
    s += ss * a[i] % mod
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
mod = 10 ** 9 + 7
import numpy as np
a = np.array(map(int, input().split())
s=0
ss=0
for i in range(n):
  ss += a[i]%mod
  s += ss * a[i] % mod
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
mod = 10 ** 9 + 7
import numpy as np
a = np.array(map(int, input().split())
s=0
ss=0
for i in range(n):
    ss += a[i]%mod
    s += ss * a[i] % mod
print(s)

Submission status: Runtime Error

Solution code:
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

void dfs(int x,vector<vector<int>> &v,vector<int> &g, int &num){
  int x_size = v[x].size();
  if(x > 0){
    rep(i,x_size){
      if(g[v[x][i]] == 0){
        g[v[x][i]] = num;
        dfs(v[x][i],v,g,num);
      }
    }
  }
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M),B(M),group(N+10,0);
  rep(i,M)cin >> A[i] >> B[i];
  vector<vector<int>> G(N+10);
  rep(i,M){
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }
  int num = 1;
  for(int i = 1;i <= N;i++){
    if(group[i] == 0){
      group[i] = num;
      dfs(i,G,group,num);
      num++;
    }
  }
  vector<int> cnt(N+10,0);
  for(int i = 1;i <= N;i++){
    cnt[group[i]]++;
  }
  int ans = -1;
  for(int i = 1;i <= N;i++){
    if(ans < cnt[i])ans = cnt[i];
  }
  cout << ans << endl;
/*
  for(int i = 1;i <= N;i++){
    cout << group[i] << " ";
  }
  cout << endl;
  for(int i = 1;i <= N;i++){
    cout << G[i].size() << " ";
  }
  cout << endl;
*/
  return 0;
}

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll A[N], sumA[N];
  for(int i=0;i<N;++i) {
    cin>>A[i];
    sumA[i] = A[i];
  }
  for(int i=1;i<N;++i) {
    sumA[i] += sumA[i-1];
    sumA[i] %= mod;
  }
  ll ans = 0;
  for(int i=0;i<N;++i) {
    ans += A[i]*(sumA[N-1]-sumA[i]+mod)%mod;
    ans %= mod;
  }
  cout<<ans<<endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=input().split()
sum=0
for i in range(len(a)):
  a[i]=(int)(a[i])
for i in a:
  sum+=i
ans=0
ans+=(sum**2)
for i in a:
  ans-=i*i
return (ans/2)%(10**9+7)

Submission status: Runtime Error

Solution code:
a=input().split()
sum=0
for i in range(len(a)):
  a[i]=(int)(a[i])
for i in a:
  sum+=i
ans=0
ans+=(sum**2)
for i in a:
  ans-=i*i
return ans%(10**9+7)

Submission status: Runtime Error

Solution code:
a=(int)(input().split())
sum=0
for i in range(len(a)):
  a[i]=(int)(a[i])
for i in a:
  sum+=a
ans=0
ans+=(sum**2)
for i in a:
  ans-=i*i
return ans%(10**9+7)

Submission status: Runtime Error

Solution code:
a=input().split()
sum=0
for i in a:
  sum+=a
ans=0
ans+=(sum**2)
for i in a:
  ans-=i*i
return ans%(10**9+7)

Submission status: Runtime Error

Solution code:
a=map(int,input().split())
sum=0
for i in a:
  sum+=a
ans=0
ans+=(sum**2)
for i in a:
  ans-=i*i
return ans%(10**9+7)

Submission status: Runtime Error

Solution code:
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


n = int(input())
arr = map(int, input().split())

MOD = 10 ** 9 + 7

answer = 0
t = itertools.combinations(arr, 2)
for i in t:
    answer = (answer + i[0] * i[1]) % MOD

print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [list(map(str,input().split()) for i in range(N))]
mod = 10**9+7
ans=0
for i in range(2**N):
  cl = [False]*N
  for j in range(N):
    if ((i>>j)&1):
      cl[N-1-j] = True
  total=''
  if cl.count(True) == 2:
    for k in range(len(cl)):
      if cl[k]:
        total+= A[k] + '*'
      total+= '1'
  ans += eval(total)

print(ans%mod)

Submission status: Runtime Error

Solution code:
 = int(input())
A = list(map(int, input().split()))
t = 0 
S = sum(A)
c = 0 
for i in range(len(A) - 1): 
        S -= A[i]
        t = (t + (A[i] * S))
print(t % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
sm=0
mod=10**9+7
s=sum(A)
for i in range(A):
    s-=i
    sm+=i*s
    sm%=mod
print(sm)

Submission status: Runtime Error

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

    ans = 0
    A_ = sum(A_list) % mod
    for i in range(N-1):
        A = A_list[i]
        A_ = A_ - A
        ans = (ans + (A * A_) % mod)) % mod
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

    ans = 0
    A_ = sum(A_list) % mod
    for i in range(N):
        A = A_list[i]
        A_ = A_ - A
        ans = (ans + (A * A_) % mod)) % mod
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=input()
A=map(int,input().split(' '))
summed=0
for i in range(0,N):
	for j in range(i+1,N):
		sumed+=A[i]*A[j]
MOD=10**9+7
print(sumed%MOD)

Submission status: Runtime Error

Solution code:
N=input()
A=map(int,input().split(' '))
sum=0
for i in range(0,N):
	for j in range(i+1,N):
		sum+=A[i]*A[j]
MOD=10**9+7
print(sum%MOD)

Submission status: Runtime Error

Solution code:
N=input()
A=map(int,input().split(' '))
sum=0
for i in range(0,N):
	for j in range(i+1,N):
		sum+=A[i]*A[j]

print(sum)

Submission status: Runtime Error

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

modn = int(1e9 + 7)

A = np.mod(A, modn)

ret = 0
for i in range(0, len(A)-1):
  for j in range(i+1, len(A)):
    ret += A[i]*A[j]

print(np.mod(ret, modn))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections

n,m = map(int,input().split())
friend = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if a not in friend[b]:
        friend[a].append(b)
        friend[b].append(a)

q = collections.deque()
visited = [0 for i in range(n)]

ans = 0
for i in range(n):
    if visited[i] == 0:
        visited[i] = 1
        tmp = 1
        for j in friend[i]:
            if visited[j] == 0:
                visited[j] = 1
                tmp += 1
                q.append(j)
        while q:
            s = q.pop()
            for k in friend[s]:
                if visited[k] == 0:
                    visited[k] = 1
                    tmp += 1
                    q.append(k)
    ans = max(ans,tmp)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
"""C."""

import sys

input = sys.stdin.readline  # noqa: A001

n = int(input())
a = list(map(int, input()[:-1].split(' ')))

result = 0

for i, v1 in enumerate(a):
    for j in range(i + 1, n + 1):
        result += v1 * a[j]
print(result)

Submission status: Runtime Error

Solution code:
"""C."""

import sys

input = sys.stdin.readline  # noqa: A001

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

result = 0

for i, v1 in enumerate(a):
    for j in range(i + 1, n + 1):
        result += v1 * a[j]
print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
ai = np.array(list(map(int, input().split())))

# n=3
# ai = np.array([1, 2, 3])

ai = ai[np.newaxis, :]

ai2 = ai.T.dot(ai)
ai2u = np.triu(ai2, k=1)

s = ai2u.sum()


# l = len(ai)
# 
# s = 0
# for j in range(l):
#     for i in range(j+1, l):
#         s += ai[j] * ai[i]

ans = s % (1000000000 + 7)

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
sum=sum*sum

s=0
for i in range(n):
    s+=A[i]**2

ans=(sum-j)//2
ans%=J
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
n=int(input())
A=INPUT()
sum=0
for i in range(n):
    sum+=A[i]
    sum%=J 
sum=sum*sum  
sum%=J  
s=0
for i in range(n):
    s+=A[i]**2
    s%=j  
ans=sum-j  
ans%=J  
print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

for i in range(len(a)):
    for j in range(len(a)):
        if i<j:
            sum += (a[i]) * (a[j])
    
print(sum % 10**9+7)

Submission status: Runtime Error

Solution code:
num = int(input())
input_line = input().split()

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
	num_a = num_list[i]
    temp_sum = 0
	for j in range(i+1,num):
		temp_sum += num_list[j]
    	
    
    sigma += num_a * temp_sum

sigma %= law
print(sigma)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
i=0;j=i+1
mod = 1000000000+7
sum=0
while i<n-1:
  j = i+1
  while j<n:
    minsum=l[i]*l[j]
    minsum%=mod
    sum+=modsum
  i+=1
print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
A = np.array(list(map(int, input().split())))
B = np.outer(A,A)
ans = (np.sum(B) - np.dot(A,A)) / 2 % (10**9+7)
print(int(ans))

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a_lis = [int(input()) for i in range(n)]
sum = 0
mod = 10**9+7
for a,b in itertools.combinations(a_lis,2):
    sum += (a*b)%mod

print(sum%mod)

Submission status: Runtime Error

Solution code:
from itertools import combinations
n = int(input())
a_lis = [int(input()) for i in range(n)]
sum = 0
mod = 10**9+7
for a,b in combinations(a_lis,2):
    sum += (a*b)%mod

print(sum%mod)

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

Solution code:
import copy
N=int(input('N='))
s=0
list1=[]
while s<N:
    A=int(input('Aを入力して下さい。'))
    list1.append(A)
    s=s+1
list2=copy.copy(list1)

x=0
for i in list1:
    for j in list2:
        if i<j:
            x=x+i*j
        else:
            continue

x=x%(10**9+7)
print(str(x))

Submission status: Runtime Error

Solution code:
MAX=101010
is_prime=[True]*MAX
is_prime[0]=False
is_prime[1]=False
for i in range(2,MAX):
  if is_prime[i]==False:
    continue
  for j in range(i*2,MAX,i):
    is_prime[j]=False

a=[0]*MAX
for i in range(MAX):
  if i%2==0:
    continue
  if is_prime[i] and is_prime[(i+1)//2]:
    a[i]=1

s=[0]
for x in a:
  s.append(s[-1]+x)

Q=int(input())
for _ in range(Q):
  l,r=map(int,input().split())
  print(s[r+1]-s[l])

Submission status: Runtime Error

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

for i in a:
s -=i
ans += s*i
s+=i

ans = ans%m

print(ans)

Submission status: Runtime Error

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

for i in range a:
s -=i
ans += s*i
s+=i

ans = ans%m

print(ans)

Submission status: Runtime Error

Solution code:
n=input()
l=list(map(int,input().split()))
s=0
for i in range(1,n):
    s=s+l[i]*l[i-1]
print(s)

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
p = 0
for n in range(N):
  for m in range(n+1, N):
    p += X[n]*X[m]
    if p >= 10**9 + 7:
  while p >= 10**9 + 7:
    p -= 10**9 + 7
      
print(p)

Submission status: Runtime Error

Solution code:
a = [list(map(int, input().split())) for i in range(2)]
sum = 0

for i in range(1,a[1][1]):
  for j in range(i+1,a[1][1]+1):
    sum += a[2][i] * a[2][j]

q = 10 ** 9 + 7
    
print(sum % q)