TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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).

Submission attempts (in order):
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a





def exEuclid(a, b):
    if (b==0):
        return (a, 1, 0)
    else:
        (dd, xx, yy) = exEuclid(b, a % b)
        return (dd, yy, xx - (a//b)*yy)

def main(n,a):
    MOD=10**9+7
    sum1=0
    sum2=0
    for i in range(n):
        sum1=(sum1+a[i])%MOD
        sum2=(sum2+(a[i]*a[i]))%MOD

    aa=(sum1*sum1-sum2+MOD)//2

    d,x,y=exEuclid(2,MOD)
    return aa%MOD

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)


def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a





def exEuclid(a, b):
    if (b==0):
        return (a, 1, 0)
    else:
        (dd, xx, yy) = exEuclid(b, a % b)
        return (dd, yy, xx - (a//b)*yy)

def main(n,a):
    MOD=10**9+7
    sum1=0
    sum2=0
    for i in range(n):
        sum1=(sum1+a[i])%MOD
        sum2=(sum2+(a[i]*a[i]))%MOD

    aa=(sum1*sum1-sum2+MOD)%MOD

    d,x,y=exEuclid(2,MOD)
    if x<0:
        x+=MOD
    #print(x)

    return (aa*x)%MOD

def main2(n,a):
    MOD=10**9+7
    ruiseki=[0]*n
    ruiseki[0]=a[0]
    for i in range(1,n):
        ruiseki[i]=(ruiseki[i-1]+a[i])%MOD
    sum=0
    for i in range(n-1):
        sum=(sum+(a[i]*(ruiseki[n-1]-ruiseki[i]))%MOD)%MOD
    return sum

if __name__=='__main__':
    n,a=readinput()
    ans=main2(n,a)
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):

def input_array():
	return list(map(int,input().split()))
  
n=int(input())
A=input_array()
acc_A=[0]

for i in range(n):
	acc_A.append(acc_A[i]+A[i])
ans=0
print(A,acc_A)
for i in range(n):
	# print(A[i]*acc_A[i:n+1])
	ans+=A[i]*(acc_A[n]-acc_A[i+1])

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


def input_array():
	return list(map(int,input().split()))
  
n=int(input())
A=input_array()
acc_A=[0]

for i in range(n):
	acc_A.append(acc_A[i]+A[i])
ans=0
for i in range(n):
	ans+=A[i]*(acc_A[n]-acc_A[i+1])

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

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
pans = 0
sum_ = sum(a)%(10**9+7)
for i in range(n-1):
    sum -= a[i]
    ans = sum * a[i]
    ans = ans % (10**9+7)
    pans += ans
print(pans%(10**9+7))

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = map(int,input().split())
total=0
for i in range(1,N+1):
  try:
    sumA = A[i-1]*sum(A[i:])
    total+=sumA
  except:
    pass
print(total)


N = int(input())
A = map(int,input().split())
total=0
for i in range(N):
  try:
    sumA = A[i]*sum(A[i+1:])
    total+=sumA
  except:
    pass
print(total)

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)


N = int(input())
A = list(map(int,input().split()))
count=0
num=0
for i in range(N):
  while count != N:
    count = i
    try:
      C = i+1
      num += A[i]*A[C]
      C+=1
      count+=1
    except:
      pass
print(num)

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

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Time Limit Exceeded

Accepted
Problem: 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).

Submission attempts (in order):
sus = 0

for i in a:
    su = su - i
    sus = sus + i * su



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

n = int(input())
a = list(map(int, input().split()))
b = []
su = 0

la = len(a)
ele = a[la - 1]

for i in range(1, len(a) - 1):
    ele = ele + a[la - i - 1]
    b.append(ele)

lb = len(b)

for j in range(len(a) - 2):
    su = su + a[j] * b[lb - j - 1]

su = su + a[len(a) - 1] * a[len(a) - 2]

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

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
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))


import numpy as np

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

modn = int(1e9 + 7)

ruiseki = sum(A)

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

print(np.mod(ret, modn))

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):

n = int(input())
item = [int(i) for i in input().split()]
mod = 10**9+7
t = (sum(item)**2 - sum([i**2 for i in item]))

print(int(t * pow(2, -1, mod)))



n = int(input())
item = [int(i) for i in input().split()]
mod = 10**9+7
t = (sum(item)**2 - sum([i**2 for i in item]))

print(int(t * pow(2, -1, mod)) % mod)


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
ans = 0
s = sum(a)-a[0]
for i in range(n-1):
  ans+=(a[i]*s)
  ans%=st
  s-=a[i+1]
print(ans)


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


Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
def calc(A, N, i):
    ans = 0
    for i in range(i, N - 1):
        ai = A[i]
        aj = A[i + 1]
        ans += ai * aj
    return (ans)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = [0] * (N + 1)
    for i in range(0, N - 1):
        if A[i] != 0:
            ans[i] = calc(A, N, i)
            break
    for j in range(i + 1, N - 1):
        if A[j] != 0:
            ans[j] = (ans[j - 1] - A[j - 1] * A[j]) // A[j - 1] * A[j]
        else:
            ans[j] = 0
    ret = 0
    for k in range(0, N):
        ret += ans[k]
    ret = ret % mod_v
    print(ret)


if __name__ == '__main__':
    main()

def calc(A, N, i):
    ans = 0
    for i in range(i, N - 1):
        ai = A[i]
        aj = A[i + 1]
        ans += ai * aj
    return (ans)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = [0] * (N + 1)
    for i in range(0, N - 1):
        if A[i] != 0:
            ans[i] = calc(A, N, i)
            break
    for j in range(i + 1, N - 1):
        if A[j - 1] != 0 and ans[j] == 0:
            ans[j] = (ans[j - 1] - A[j - 1] * A[j]) // A[j - 1] * A[j]
        else:
            ans[j] = 0
    ret = 0
    for k in range(0, N):
        ret += ans[k]
    ret = ret % mod_v
    print(ret)


if __name__ == '__main__':
    main()

def calc(A, N, i):
    ans = 0
    ai = A[i]
    for i in range(i, N - 1):
        aj = A[i + 1]
        ans += ai * aj
    return (ans)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod_v = 10**9 + 7
    ans = [0] * (N + 1)
    for i in range(0, N - 1):
        if A[i] != 0:
            ans[i] = calc(A, N, i)
            break
    for j in range(i + 1, N - 1):
        if A[j] != 0:
            ans[j] = (ans[j - 1] - A[j - 1] * A[j]) // A[j - 1] * A[j]
        else:
            ans[j] = 0
    ret = 0
    for k in range(0, N):
        ret += ans[k]
    ret = ret % mod_v
    print(ret)


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split())
B = []  
mod = 10**9 + 7
ans = 0

for i in range(N+1):
    B.append(sum(A[:i]))  

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

print(ans)

N = int(input())
A = list(map(int, input().split()))
B = []  
mod = 10**9 + 7
ans = 0

for i in range(N):
    B[i+1] = B[i] + A[i]  

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

print(ans)


import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)  
mod = 10**9 + 7
ans = 0

for i in range(N):
    B[i+1] = B[i] + A[i]  

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

print(int(ans))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
arr = list(map(int, input().split(" ")))

mod = 10 ** 9 + 7

s = sum(arr) % mod

result = 0
for i in arr:
  s -= i
  s %= mod
  result += s
  result %= mod
print(result)


N = int(input())
arr = list(map(int, input().split(" ")))

mod = 10 ** 9 + 7

slist = sum(arr)

result = 0
for i in arr:
  result += i * (slist - i)
  result %= mod
print(result)


N = int(input())
arr = list(map(int, input().split(" ")))

mod = 10 ** 9 + 7

s = sum(arr) % mod

result = 0
for i in arr:
  s -= i
  s %= mod
  result += s * i
  result %= mod
print(result)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())

s = input().split(" ")

ans = 0
for i in range(n):
  for j in range(int(i)+1,n-1):
    
    ans += int(s[i])*int(s[j])
print(ans%(10**9+7))

n = int(input())

s = input().split(" ")

sumup = 0
for i in s:
  sumup += int(i) 

ans = 0
for i in s:
  r = int(i)
  
  sumup -= r
  
  ans += r*sumup
    
print(ans%(10**9+7))

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
# -*- coding: utf-8 -*-
N= int(input())
A= list(map(int,input().split(' ')))

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

print(ans)


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

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

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

sum_of_product = (sum(A) ** 2) % (10 ** 9 + 7)

for i in A:
    sum_of_product -= i ** 2
    if sum_of_product < 0:
        sum_of_product += 10 ** 9 + 7

print(sum_of_product)

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

sum_of_product = (sum(A) ** 2)

for i in A:
    sum_of_product -= i ** 2

sum_of_product = (sum_of_product / 2) % 10 ** 9 + 7

print(sum_of_product)

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

sum_of_product = sum(A) ** 2

for i in A:
    sum_of_product -= i ** 2

sum_of_product = (sum_of_product / 2) % (10 ** 9 + 7)

print(sum_of_product)

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

sum_of_product = (sum(A) ** 2)

for i in A:
    sum_of_product -= i ** 2

sum_of_product %= 10 ** 9 + 7

print(sum_of_product)

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

sum_list = sum(A)
sum_of_product = 0

for i in A:
    sum_list -= i
    sum_of_product = ((sum_list * i) % (10 ** 9 + 7) + sum_of_product) % (10 ** 9 + 7)

print(sum_of_product)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
A = list(map(int, input().split()))

S = sum(A)
S2 = sum(map(lambda x: x * x, A))

print((S * S - S2 // 2) % (10 ** 9 + 7))


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

S = sum(A)
S2 = sum(map(lambda x:x*x, A))

print(S*S - S2 / 2 % (10**9+7))

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

S = sum(A)
S2 = sum(map(lambda x:x*x, A))

print(S*S - S2 // 2 % (10**9+7))

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

S = sum(A)
S2 = sum(map(lambda x: x * x, A))

print((S * S - S2) // 2 % (10 ** 9 + 7))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
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))

n = input()
a = list(map(int, input().split()))
b= []
for i in range(len(a)):
    b.append(a[i]%(10**9+7))
sum = 0

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


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)

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

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

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

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
h = sum(a)
ans = 0
for i in range(n):
  h -= a[i]
  ans = (ans + (a[i]*(h))%(10**9+7)
print(ans)
 



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



Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
import copy
mod=10**9+7
def calc(nums,n):
    if n==2:
        return ((nums[0]%mod)*(nums[1]%mod))%mod
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save%mod+nums[i+1]%mod)%mod
        save=s%mod
    print(nums)    
    ans=0  
    
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
    





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))


import copy
mod=(10**9)+7
def calc(nums,n):
    if n==1:
        return 0
    if n==2:
        return nums[0]*nums[1]
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]
        nums[i]=save+nums[i+1]
        save=s
    ans=0  
    print(nums)
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
       





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))


import copy
mod=(10**9)+7
def calc(nums,n):
    if n==1:
        return 0
    if n==2:
        return nums[0]*nums[1]
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save+nums[i+1])%mod
        save=s
    ans=0  
    print(nums)
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
       





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))


import copy
mod=10**9+7
def calc(nums,n):
    if n==1:
        return 0
    if n==2:
        return nums[0]*nums[1]
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save+nums[i+1])%mod
        save=s
    ans=0  
    print(nums)
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
       





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))


import copy
mod=10**9+7
def calc(nums,n):
    if n==2:
        return ((nums[0]%mod)*(nums[1]%mod))%mod
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save%mod+nums[i+1]%mod)%mod
        save=s%mod
       
    ans=0  
    
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
    





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

sum_sq_a = 0
for i in range(n):
    sum_sq_a += a[i]**2

ans = ((sum(a)) - sum_sq_a) // 2

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

import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype = 'object')
mod = 10**9 + 7

sq_sum_a = sum(a)**2
sum_sq_a = sum(a**2)

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod
# xy = ((x + y)**2 - (x**2 + y**2)) // 2

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):

# C - Sum of product of pairs

from itertools import combinations

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

mod=10**9+7

ans=0

for v in combinations(ls,2):
    print(v[0],v[1],v[0]*v[1],(v[0]*v[1]%mod))
    ans+= (v[0]*v[1])%mod
    ans%=mod

print(ans)



# C - Sum of product of pairs

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

mod=10**9+7

ans=0
accumls=[0]

for i in range (N):
    accumls.append(accumls[-1]+ls[i])

for i in range (N-1):
    ans+= ls[i]*(accumls[-1]-accumls[i+1])
    ans%=mod

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
import numpy as np
from numba import jit
@jit


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    l = np.array(l)

    tot = 0
    for i in range(n):
        tot += (l[i] * (np.sum(l[i + 1:n], dtype='int64') % (10 ** 9 + 7))) % (10 ** 9 + 7)

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


if __name__ == "__main__":
    main()



def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

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


if __name__ == "__main__":
    main()



Verdicts: Time Limit Exceeded

Accepted
Problem: 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).

Submission attempts (in order):
mod = 10 ** 9 + 7
n = int(input())

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(p // 2) % mod * res % mod)

mod = 10 ** 9 + 7
n = int(input())

a_sum = 0
sq_sum = 0
for a in map(int, input().split()):
  a_sum = (a_sum + a) % mod
  sq_sum = (sq_sum + a * a) % mod
res = (a_sum * a_sum - sq_sum) % mod
print(-(mod // 2) % mod * res % mod)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = map(int, input().split())

MOD = 10**9 + 7

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

print(total % MOD)

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

MOD = 10**9 + 7

sum_a = sum(A)
sum_squares = sum([a*a for a in A])

ans = (sum_a**2 - sum_squares)//2
ans %= MOD

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
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)

# 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)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = [int(i) for i in input().split()]

res = sum(i for i in a)
ans = 0
base = 1e9 + 7
for i in a:
  res -= i
  ans += (i * res)
  
print(ans % base)

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

res = sum(i for i in a)

ans = 0
for i in a:
    res -= i
    ans += i * res

print(ans % 1000000007)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
def main():
    input()
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()
	xxx=False
    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()

def main():
    n=int(input())
    mod = 10**9 + 7
    arr = sorted(map(int, input().split()))
    arr.reverse()

    sm = arr[0] + arr[1]
    ans = arr[0] * arr[1] % mod

    for x in range(2, len(arr)):
        ans += sm * arr[x]
        sm += arr[x]

    print(ans % mod)


if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(len(a)):
  s += a[i]
for i in range(len(a)-1):
  s -= a[i]
  if s<0:
	s += 1e9+7
  ans += s*a[i]
  ans %= 1e9+7
print(int(ans))


n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(len(a)):
  s += a[i]
for i in range(len(a)-1):
  s -= a[i]
  if s<0:
    s += 1e9+7
  ans += s*a[i]
  ans %= 1e9+7
print(ans)

n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(len(a)):
  s += a[i]
for i in range(len(a)-1):
  s -= a[i]
  ans += s*a[i]
print(int(ans%1e9+7))

n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(len(a)):
  s += a[i]
for i in range(len(a)-1):
  s -= a[i]
  if s<0:
    s += 1000000007
  ans += s*a[i]
  ans %= 1000000007
print(int(ans))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

x = sum(A)
y = sum([A[i] ** 2 for i in range(n)])

print(((x ** 2 - y) / 2) % (10 ** 9 + 7))

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

A_sum = sum(A)
A_squaresum = sum([a ** 2 for a in A])
answer = ((A_sum ** 2 - A_squaresum) // 2) % (10 ** 9 + 7)

print(answer)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
a=int(input())
b = list(map(int, input().split()))
b.sort()
S=0
c=sum(b)
for i in range(0,a):
    S=S+b[i]*(c-b[i])
print(S % (10**9+7))


a=int(input())
b = list(map(int, input().split()))
b.sort()
S=0
c=sum(b)
for i in range(0,a):
    c=c-b[i]
    S=S+b[i]*c
print(S % (10**9+7))

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
import itertools

def mod(x):
  return x%((10**9)+7)
n=int(input())
a_list=list(map(int,input().split()))
sum_list=[]
for i in itertools.combinations(a_list,2):
  sum_list.append((i[0]*i[1]))
  
  
print(sum_list)
s=sum(sum_list)
s=mod(s)
print(s)

import itertools

n=int(input())
a_list=list(map(int,input().split()))
sum=0
ps = list(itertools.accumulate(a_list))
for i in range(n-1):
  sum+=a_list[i]*(ps[n-1]-ps[i])

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


Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
num = int(input())
ar = list(map(int,input().split()))
mod = 10**9 + 7
somee = sum(arr)
ans = 0
for i in range(num):
    ans+=(somee-ar[i])*ar[i]
print((ans//2)%mod)

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)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = input().split()
S = 0
B = 0

for i in range(N):
  A[i] = int(A[i])
  S += A[i] % (10**9+7)
  B += (A[i]**2) % (10**9+7)
  print(S,B)

print(((S**2) % (10**9+7) - B) / 2)

N = int(input())
A = input().split()
B = [0]*N

for i in range(N):
  A[i] = int(A[i])
  B[i] = A[i]*A[i]

print( ( ( (sum(A)*sum(A)) - sum(B) ) // 2 ) % ( 10**9 + 7 ) // 2 )


N = int(input())
A = input().split()
B = [0]*N

for i in range(N):
  A[i] = int(A[i])
  B[i] = A[i]*A[i]

print( ( ( (sum(A)*sum(A)) - sum(B) ) // 2 ) % ( 10**9 + 7 ) )


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
a=s=0
for x in[*open(0)][1].split():x=int(x);a+=s*x;s+=x
print(a%(1e9+7))

c=s=0
for a in[*open(0)][1].split():a=int(a);c+=s*a;s+=a
print(c%(10**9+7))

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
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)

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)

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
print((ans/2)%(10**9+7))

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)

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)

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)

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)

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
print((ans//2)%(10**9+7))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

ans = 0
double = 0

for i in a:
    double += i*i

ans = (sum(a) * sum(a) - double) // 2
print((ans % (10**9 + 7))

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

ans = 0
double = 0

for i in a:
    double += i*i

ans = (sum(a) * sum(a) - double) // 2
print(ans % (10**9 + 7))

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())

ai_char = map(str, input().split(" "))
Ai = []
for i in ai_char:
    Ai.append(int(i))

print(Ai)

sum = 0
for i in range(N-1):
    for j in range(i+1, N):
        sum += Ai[i]*Ai[j]
        #print("{} {}".format(i, j))

print(sum%1000000007)

N = int(input())

ai_char = map(str, input().split(" "))
Ai = []
for i in ai_char:
    Ai.append(int(i))

mod_val = 1000000007
N1 = N-1
sum = 0

sum_tmp = 0
for j in range(0, N):
    sum_tmp += Ai[j]

for i in range(N1):
    sum_tmp -= Ai[i]
    sum += Ai[i] * sum_tmp

    if sum > mod_val:
        sum = sum % mod_val


print(int(sum))

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
P = 0
Q = 0

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


import numpy as np

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

arr = np.array(A)
K = np.inner(arr, arr)
P = pow(sum(A), 2)
ans = ((P-K)/2)%mod

print(ans)


N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
k = int((10**9 + 8)/2)
sum = 0
sum_1 = 0

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

for j in range(N):
    sum_1 += A[j]**2
sum_1 = (sum_1)%mod

ans = sum - sum_1
ans = (ans*k)%mod

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
import decimal
n = int(input())
a = list(map(int, input().split())) 

first = a[0]

ans = first*a[1]

print(ans)
for i in range(1, n-1):
    first += a[i]
    ans += first*a[i+1]

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


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

first = a[0]

ans = first*a[1]

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
def main():
    mod = 1000000007
    
    n = int(input())
    a = [int() for x in input().split()]
    ans = 0
    asum = sum(a) 
    for i in range(n):
        asum = asum - a[i]
        ans = ( ans + ((a[i] * asum) % mod)) % mod
    
    print(ans)
    
if __name__ == '__main__':
    main()

import random
import numpy as np
def get_input():
    n = 200000
    a = []
    for i in range(n):
        a.append(random.randint(0,1000000000))
    aa = np.array(a,dtype='int64')
    return n,aa

def main():
    
    n = int(input())
    a = np.array([np.int64(x) for x in input().split()])
    p = (np.sum(a) ** 2) % 1000000007
    q = np.sum(a**2 % 1000000007) 
    ans = (p-q)/2
    
    print(ans)
    
        

if __name__ == '__main__':
    main()

def main():
    mod = 1000000007
    
    n = int(input())
    a = [int() for x in input().split()]
    ans = 0
    asum = sum(a)
    for i in range(n):
        asum = asum - a[i]
        ans += (a[i] * asum) % mod
    
    print(ans)
    
if __name__ == '__main__':
    main()

def main():
    mod = 10**9+7
    
    n = int(input())
    a = [int(x) for x in input().split()]
    aa = [a**2 % mod for x in a]
    ans = 0
    asum = sum(a) 
    p = asum ** 2 % mod
    q = sum(aa) % mod
    ans = (p - q) % mod
    if ans < 0:
      ans += mod
    if ans % 2 == 1:
      ans += mod
    ans = ans // 2
    print(ans)
    
if __name__ == '__main__':
    main()

def main():
    mod = 10**9+7
    
    n = int(input())
    a = [int() for x in input().split()]
    ans = 0
    asum = sum(a) 
    for i in range(n):
        asum = asum - a[i]
        ans = ( ans + ((a[i] * asum) % mod)) % mod
    
    print(ans)
    
if __name__ == '__main__':
    main()

def main():
    mod = 10**9+7
    
    n = int(input())
    a = [int(x) for x in input().split()]
    aa = [x**2 % mod for x in a]
    ans = 0
    asum = sum(a) 
    p = asum ** 2 % mod
    q = sum(aa) % mod
    ans = (p - q) % mod
    if ans < 0:
      ans += mod
    if ans % 2 == 1:
      ans += mod
    ans = ans // 2
    print(ans)
    
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = map(int,input().split())
ans = 0
ans2 = 0
mod = 10 ** 9 + 7
for a in A:
    ans += a
    ans2 += a**2
    ans %= mod 
    ans2 %= mod
print(((ans ** 2 + mod -ans2)//2)%mod) 

N = int(input())
A = map(int,input().split())
ans = 0
ans2 = 0
mod = 10 ** 9 + 7
for a in A:
    ans += a
    ans2 += a**2

print(((ans **2 - ans2)//2)%mod)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())

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

sigma = 0
after = sum(a[0:])
for i in range(len(a)-1):
  start = a[i]
  after = after - [i]
  if after >= (10**9 + 7):
    after = after % (10**9+7)
  sigma = sigma + start * after
  if sigma >= (10**9 + 7):
    sigma = sigma % (10**9+7)

print(sigma)


n = int(input())

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

sigma = sum(a)
count = 0
for i in range(len(a)-1):
  start = a[i]
  sigma = sigma-a[i]
  count = count + start * 
  if count >= 10**9+7:
    count = count % (10**9+7)

print(count)

n = int(input())

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

sigma = sum(a)
count = 0
for i in range(len(a)-1):
  start = a[i]
  sigma = sigma-a[i]
  count = count + start * sigma
  if count >= 10**9+7:
    count = count % (10**9+7)

print(count)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ans = 0

for i in a:
  q = s-i
  ans += q
print(ans%(10**9+7))

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

s = sum(a)
ans = 0

for i in a:
  s -= i
  s %= mod
  ans += s*i
  ans %= mod
  
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    c-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)


N=int(input())
A=list(map(int,input().split()))
A2=0
for i in ragne(len(A)):
  A2+=A[i]**2
c=(sum(A))**2-A2
print(c//2)

N=int(input())
A=list(map(int,input().split()))
A2=0
for i in range(len(A)):
  A2+=A[i]**2
c=(sum(A))**2-A2
print(c//2%(10**9+7))



Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N = int(input())
A = input().split()

Sum = 0

for i in range(N):
    Sum += int(A[i])

ans = 0
for i in range(N):
    ans += (int(A[i])*(Sum-int(A[i]))%1000000007)%1000000007

print((ans/2)%1000000007)


N = int(input())
A = input().split()

Sum = sum(A)

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

ans %= 1000000007

print(int(ans/2))


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

Sum = sum(A)

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

ans %= 1000000007

print(int(ans))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())

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

ans = sum(A)^2

for a in A:
  ans -= a^2

ans /= 2

print(int(ans%(10^9+7)))

N = int(input())
 
A = list(map(int, input().split()))
 
ans = sum(A) ** 2

 
for a in A:
  ans = ans - a ** 2

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

Verdicts: Wrong Answer

Accepted
Problem: 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).

Submission attempts (in order):
n= int(input())
a= [int(i) for i in input().split()]
pref=[0]*n
pref[0] = a[0]%m
for i in range(1,n):
    pref[i] =  (pref[i-1]+a[i])%m
m = 10**9+7
ans = 0
#print(pref)
for i in range(n-1):
    ans+= (a[i]%m *((pref[n-1]-pref[i])%m))%m
    ans = ans%m
print(ans)
#437235829

n= int(input())
a= [int(i) for i in input().split()]
pref=[0]*n
m = 10**9+7
pref[0] = a[0]%m
for i in range(1,n):
    pref[i] =  (pref[i-1]+a[i])%m
m = 10**9+7
ans = 0
#print(pref)
for i in range(n-1):
    ans+= (a[i]%m *((pref[n-1]-pref[i])%m))%m
    ans = ans%m
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):

using namespace std;
#define M 1000000007
int main()
{
	long long a[200000], i,n, j, s=0, su=0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		s=(s+a[i])%M;
	}
	for (i = 0; i < n; i++)
	{
		s -= a[i];
		s+=M;
		s%=M;
		su += (a[i] * s)%M;
		su %= M;
	}
	cout << su;
}

n=int(input())
l=list(map(int,input().split()))
s=sum(l)
su=0
for i in range(n):
	s=s-l[i]
	s=s%1000000007
	su=su+(l[i]*s)
	su=su%1000000007
print(su)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = input()

max = 10**9 + 7

a_list = [int(a) % max for a in input().split(" ")]

sum = 0
for i in range(0, len(a_list)-1):
    sum += a_list[i] * sum(a_list[i+1:])
sum = sum % max
print(sum)


n = input()
a_list = input().split(" ")

b = [int(a) for a in a_list]
max = 10**9 + 7

sum = 0
for i in range(0, len(b)-2):
  for j in range(i+1, len(b)-1):
    sum += b[i] * b[j]
    while sum => max:
      sum -= max
print(sum)


n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]

print(sum(a_list))
total = 0
for i in range(0, len(a_list)-1):
    total += a_list[i] * sum(a_list[i+1:])
total = total % max
print(total)


n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]
a_sum = sum(a_list)

total = 0
for i in range(0, len(a_list)-1):
    total += a_list[i] * (a_sum - a_list[i])
total = total % max
print(total)


n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]

print(sum(a_list))
total = 0
for i in range(0, len(a_list)-1):
    print(a_list[i], a_list[i+1:])
    total += a_list[i] * sum(a_list[i+1:])
total = total % max
print(total)


n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]

total = 0
for i in range(0, len(a_list)-1):
    print(a_list[i], a_list[i+1:])
    total += a_list[i] * sum(a_list[i+1:])
total = total % max
print(total)


n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]
a_sum = sum(a_list)

total = 0
for i in range(0, len(a_list)-1):
    a_sum -= a_list[i]
    total += a_list[i] * a_sum
total = total % max
print(total)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
# import sys
# import math #sqrt,gcd,pi

import queue 

# import heapq # priolity-queue

# from itertools import product,permutations,\
    # combinations,combinations_with_replacement


# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    # n = int(input())
    # a = readInt()
    n = 200000
    a = [1000000000 for i in range(n)]
    ans = 0
    for i in range(n-1):
        for j in range(i+1,n):
            ans += a[i] * a[j]
            ans %= mod
    print(ans)
    return

if __name__=='__main__':
    main()



# import sys
# import math #sqrt,gcd,pi



# import heapq # priolity-queue

# from itertools import product,permutations,\
    # combinations,combinations_with_replacement


# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n = int(input())
    a = readInt()
    c_sum = [0]
    for i in range(n):
        c_sum.append(c_sum[i]+a[i])
    ans = 0
    for i in range(n-1):
        ans += a[i] * (c_sum[-1] - c_sum[i+1])
        ans %= mod
    print(ans)
    return

if __name__=='__main__':
    main()


Verdicts: Time Limit Exceeded

Accepted
Problem: 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).

Submission attempts (in order):
a=input()
a = np.array(list(map(int, input().split())))
count=1
tmp=0
for i in a[:-1]:
    tmp=(tmp+i*(a[count:]).sum())%(10**9+7)
    count+=1
print(tmp)

import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
s=[0]*(n-1)
tmp=0
for i in range(n-1):
    tmp=(tmp+a[(i+1)*-1])%(10**9+7)
    s[(i+1)*-1]=tmp
    
print(int((s*a[:-1]%(10**9+7)).sum()%(10**9+7)))

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += ((l[i]*sum(l[i+1:n]))%1000000007
print(ans%1000000007)

n = int(input())
l = list(map(int,input().split()))
ans = 0
sum_n = [0]*n
sum_n[0] = l[0]
sumall = sum(l)
for i in range(1,n):
    sum_n[i] = sum_n[i-1] + l[i]
for i in range(n):
    ans += ((l[i]*(sumall-sum_n[i]))%1000000007)
print(ans%1000000007)

Verdicts: Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
"""C."""

import sys

input = sys.stdin.readline  

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)


"""C."""

import sys

input = sys.stdin.readline  

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)


"""C."""

import sys

input = sys.stdin.readline  

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

MOD_VALUE = 10**9 + 7
result = 0

a_sum = sum(a)

for v in a:
    result += v * (a_sum - v)
    a_sum -= v

if result < MOD_VALUE:
    print(result)
else:
    print(result % MOD_VALUE)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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).

Submission attempts (in order):
N = int(input())
A = map(int, input().split())

ans = 0
mod = 10**9+7

S = sum(A)
S2 = sum(map(lambda x: x*x, A))

print((S*S-S2)//2 % mod)


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

S = sum(A)
S2 = sum(map(lambda x: x * x, A))

print((S*S-S2)//2 % 1000000007)

Verdicts: Wrong Answer

Accepted