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: Wrong Answer

Solution code:
import itertools

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

saisyo = input()
X = NextInts()
p = itertools.combinations(X, 2)
ANSWER = 0
MOD = 10**9+7
for i in p:
	answer = (int(i[0])%MOD*int(i[1])%MOD)
	ANSWER+=answer
print(ANSWER)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=0
l=[int(i) for i in input().split()][:n]
for i in range(len(l)):
  for j in range(i,len(l)):
    if i!=j:
        m=l[i]*l[j]
        s+=m
print(s)

Submission status: Wrong Answer

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

for i in a:
    for j in a:
        if(i!=j):
          sum += i*j

print(sum/2%(1000000000+7))

Submission status: Wrong Answer

Solution code:
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])))
    ans %= 1000000007

print(int(ans%1000000007/2))

Submission status: Wrong Answer

Solution code:
# required function 
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    return (array_sum_square - 
            individual_square_sum) / 2

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

print(int(findProductSum(A, N) % 1000000007))

Submission status: Wrong Answer

Solution code:
ans = 0
mod = 1e9+7

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

A_sum = sum(A)
A_squared = sum([num**2 for num in A])

ans = (A_sum**2 - A_squared)/2
ans = int(ans%mod)
print(ans)

Submission status: Wrong Answer

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

s = sum(lis) ** 2
ss = sum([i ** 2 for i in lis])

print((s - ss)//2)

Submission status: Wrong Answer

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

combi = itertools.combinations(list(range(n)),2)

ans = 0

for i in combi:
  ans += (A[i[0]] * A[i[1]]) % (10**9 + 7)
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) / 2
    print(int(ans % mod))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split(" ")))
s = 0
for i in range(0,N):
  s += a[i]

s = s*s

for i in range(0,N):
  s -= a[i]*a[i]

s = int(s/2)
if s >= 10**9 + 7:
  s = s +49

while s >= (10**9 +7):
  s = int(s % (10**9 +7))

print(int(s))

Submission status: Wrong Answer

Solution code:
import itertools

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

saisyo = input()
X = NextInts()
p = itertools.combinations(X, 2)
ANSWER = 0
MOD = 10**9+7
for i in p:
	answer = (int(i[0])*int(i[1]))%MOD
	ANSWER+=answer
print(ANSWER)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
import math
 
mod=int(1e9)+7
def main():
    n=int(input())
    a=list(map(int,input().split(" ")))
    totsum=(sum(a)%mod*sum(a)%mod)%mod
    prosum=0
    for x in a:
        prosum=(prosum%mod+(x*x)%mod)%mod
    print(math.ceil((totsum-prosum)%mod/2))
    


#-----------------------------BOSS-------------------------------------!
# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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])%1000000007*((Sum-int(A[i]))%1000000007))%1000000007
    ans %= 1000000007

print(int(ans%1000000007/2))

Submission status: Wrong Answer

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

LA = len(A)
print(N)
print(A)
i = 0
j = 0
SUM = 0

for i in range(LA):
    for j in range(LA):
        if j <= i:
            continue

        SUM = SUM + (A[i] * A[j])


        
print(SUM % 1000000007)

Submission status: Wrong Answer

Solution code:
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])
    s[(i+1)*-1]=tmp
    
print(((s*a[:-1])%(10**9+7)).sum()%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

total = 0

s = sum(a)
aa = sum(list(map(lambda x: x**2, a)))

total = int(((s**2 - aa) / 2)) % (10**9 + 7)
 
  
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
ps = A.copy()
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = (sum_now+A[j])%(1e9+7)
    ps[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*ps[i+1])%(1e9+7)) %(1e9+7)
print(int(res))

Submission status: Wrong Answer

Solution code:
import itertools

n,*a=map(int,open(0).read().split())
r=0
for pair in itertools.combinations(a, 2):
  r+=(pair[0]*pair[1])%(10**9 + 7)
  
print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
res = 0
B = np.cumsum(A[::-1])
for i in range(N-1):
    res = (res + A[i] * B[N-i-2]) % 1000000007
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
result = 0
i = 0
for x in A[:N]:
  for y in A[i+1:]:
    result += (x * y)
  i += 1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
a=int(input())
d=list(map(int,input().split()))
d=sorted(d)
z=[i for i in range(a)]
c =itertools.combinations(d, 2)

al =0
end =0
for v in c:
  if v[0]<v[1]:
    al += np.prod(v)
print(al%(10**9+7))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
arr = [int(i) for i in input().split()]
print(sum(a*b for a, b in combinations(arr, 2)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
import math
 
mod=int(1e9)+7
def main():
    n=int(input())
    a=list(map(int,input().split(" ")))
    totsum=(sum(a)*sum(a))%mod
    prosum=0
    for x in a:
        prosum=prosum%mod+(x*x)%mod
    print(math.ceil((totsum-prosum)%mod/2))
    


#-----------------------------BOSS-------------------------------------!
# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=int(input())
A=input().split()
n=len(A)
array_sum = 0
for i in range(0, n, 1): 
    A[i]=int(A[i])
    array_sum = array_sum + A[i]
array_sum_square = array_sum * array_sum
individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum += A[i] * A[i]
print( int((array_sum_square - individual_square_sum) / 2) %1000000007 )

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
sum1 = 0

for i in range(N):
        for j in range(i+1,N):
            sum1 += (A_list[i])*(A_list[j])

print(sum1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

# i = j
ij = np.sum(A_array * A_array)

Acum = np.sum(A_array)

temp = 0
for i in A:
    temp += (i*Acum - i**2)/2 % (10**9 + 7)

print(int(temp) % (10**9 + 7))

Submission status: Wrong Answer

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

combi = itertools.combinations(list(range(n)),2)

ans = 0

for i in combi:
  ans += A[i[0]] * A[i[1]]
  
print(ans)

Submission status: Wrong Answer

Solution code:
MAX = 10**9+7

def sol(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum%MAX + A[i]%MAX 
    array_sum_square = array_sum%MAX * array_sum%MAX 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum = individual_square_sum%MAX + A[i]%MAX * A[i]%MAX 
    return (array_sum_square - 
            individual_square_sum) / 2
n = int(input())
lis = list(map(int,input().strip().split(' ')))
sol(lis,n)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

mod_num = 1e9 + 7

tmp_sum = 0
mod_lst = []
for i in range(N-1):
    for j in range(i+1, N):
        tmp_sum+=(A[i]*A[j])%mod_num
        print(i,j)
        if tmp_sum>mod_num:
            tmp = tmp_sum%mod_num
            mod_lst.append(tmp)
            tmp_sum = 0

if len(mod_lst)!=0:
    tmp_sum = 0
    flag = True
    while flag:
        print(flag)
        print(mod_lst)
        tmp_mod_lst = []
        for m in mod_lst:
            tmp_sum+=m
            if tmp_sum>mod_num:
                tmp = tmp_sum%mod_num
                tmp_mod_lst.append(tmp)
                tmp_sum = 0
        if len(tmp_mod_lst) == 0:
            print(tmp_sum)
            flag=False
        if len(tmp_mod_lst) == 1:
            print(tmp_mod_lst[0])
            flag = False
        else:
            mod_lst = tmp_mod_lst
else:
    print(tmp_sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
# = str(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

A = np.asarray(A)
total = (sum(A)%(10**9+7))**2
doubleA = (A**2)%(10**9+7)

minustotal = sum(doubleA)%(10**9+7)

print(((total-minustotal)%(10**9+7)//2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
def findProductSum(A, n):
    # calculating array sum (a1 + a2 ... + an)
    array_sum = 0
    for i in range(n):
        array_sum = array_sum + A[i]

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

    # calcualting a1^2 + a2^2 + ... + an^2
    individual_square_sum = 0
    for i in range(n):
        individual_square_sum += A[i] * A[i]

    # required sum is (array_sum_square -
    # individual_square_sum) / 2
    return (array_sum_square - individual_square_sum) / 2

ans = int(findProductSum(a, n))
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
assert(len(A) == N)
ps = A.copy()
sum_now = A[N-1]
for j in range(N-2,0,-1):
    sum_now = (sum_now + A[j])%(1e9+7)
    ps[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + A[i] * ps[i+1]) % (1e9+7)
print(int(res))

Submission status: Wrong Answer

Solution code:
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((s*a[:-1]).sum()%(10**9+7))

Submission status: Wrong Answer

Solution code:
def main():

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


    m = 10**9 + 7
    ans = 0
    s = sum(a)
    for i in a:
        tmp = (s - i) % m
        ans += tmp * i
    ans //= 2
    print(ans%m)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
 
 
mod=int(1e9)+7
def main():

    n=int(input())
    a=list(map(int,input().split(" ")))
    totsum=(sum(a)*sum(a))%mod
    prosum=0
    for x in a:
        prosum=prosum%mod+(x*x)%mod
    print(((totsum-prosum)%mod//2))
    


#-----------------------------BOSS-------------------------------------!
# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
def findProductSum(A, n):
    # calculating array sum (a1 + a2 ... + an)
    array_sum = 0
    for i in range(0, n, 1):
        array_sum = array_sum + A[i]

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

    # calcualting a1^2 + a2^2 + ... + an^2
    individual_square_sum = 0
    for i in range(0, n, 1):
        individual_square_sum += A[i] * A[i]

    # required sum is (array_sum_square -
    # individual_square_sum) / 2
    return (array_sum_square - individual_square_sum) / 2

ans = int(findProductSum(a, n))
ans %= mod
print(ans)

Submission status: Wrong Answer

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

# 拡張ユークリッドアルゴリズム
# (d, x, y): d=ax+by を満たすd, x, yを求める
# aとbが互いに素な整数であればgcd(a,b)=d=1, ax=1 (mod b)
# xは法bの元でaの乗法逆元a^-1になる
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//2

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

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

Submission status: Wrong Answer

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

LA = len(A)
print(N)
print(A)
i = 0
j = 0
SUM = 0

for i in range(LA):
    for j in range(LA):
        if j <= i:
            continue
        print(A[i])
        print(A[j])
        SUM = SUM + (A[i] * A[j])


        
print(SUM % 1000000007)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
x = 0
z = 0
MOD = 10**9 + 7
for i in A:
  x += i%MOD
  z += i*i%MOD
y = x*x%MOD
print((y-z)//2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
T=0
x=0
D=0
S=0
L=10**9+7

for i in range(0,N):
    x=A[i]**2
    D+=x

for j in range(0,N):
    S+=A[j]
    F=S**2

T=(F-D)/2
T=int(T)

ans=T%L
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = input().split()
ai=np.array(a, dtype="int")

div=1000000007

total=sum(ai)**2
diagonal=sum(ai ** 2)
ans=((sum(ai))**2-sum(ai ** 2))//2

print(ans%div)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
  N = int(input(""))
  in2 = input("")
  num_list = np.array([int(x) for x in in2.split(" ")])
  
  sum = 0
  for i in range(N-1):
    i_vector = num_list[i]
    j_vector = num_list[i+1:]
    
    sum += np.sum(i_vector * j_vector)

  print(sum % (10**9+7))
 
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
    Asum = Asum - A[i]
    ans += A[i]*Asum
    if ans > (10**9 + 7):
        ans = ans % (10**9 + 7)

print (ans)

Submission status: Wrong Answer

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

# 拡張ユークリッドアルゴリズム
# (d, x, y): d=ax+by を満たすd, x, yを求める
# aとbが互いに素な整数であればgcd(a,b)=d=1, ax=1 (mod b)
# xは法bの元でaの乗法逆元a^-1になる
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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
N = int(input())

modsum = 0
A = list(map(int, input().split()))
for a in A:
    modsum = (modsum + a) % MOD

count = 0
for a in A[:-1]:
    modsum -= a
    if modsum < 0:
        modsum -= MOD - a
    count = (count + modsum * a) % MOD
print(count)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = 1
d= 0
e = b[0]*b[-1]

for i in range(0, a-1):
    c =b[i]*b[i+1]
    d = d + c
print(d + e)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
t=np.array(input().split(' '))
num=np.zeros(n)
for a in range(n):
  num[a]=int(t[a])
a=np.sum(num)**2
b=np.sum(num**2)
x=int((a-b)/2)
if x<10**9+7:
  print(x)
else:
  tmp=int(x/(10**9+7))
  x=x-tmp*(10**9+7)-1
  print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
result = 0
i = 0
for x in A[:N]:
  for y in A[i+1:]:
    result += (x * y) % (10**9 + 7)
  i += 1

print(result)

Submission status: Wrong Answer

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

sum=0

print(n)
print(a)

for i in range(n) :
  for j in range(n) :
    if i < j :
      sum += a[i]*a[j]
      sum = sum%1000000007

print(sum)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')
import sys
import itertools
import copy


def main():
    N = I()
    a_list = LI()
    # print(a_list)
    # print(list(range(N)))
    # print(list(itertools.combinations(list(range(N))), 2))
    # print(list(itertools.combinations([1, 2, 3], 2)))
    cnt = 0
    for i in list(itertools.combinations(list(range(N)), 2)) :
        # print(i[0])
        if i[0] < i[1]:
            tmp = a_list[i[0]] * a_list[i[1]] % (10**9 + 7)
            cnt += tmp % (10**9 + 7)
    print(cnt)
    # L = LLIN(N)

    #     if T[-i]
    # if D / T <= S:
    #     print('Yes')
    # else:
    #     print('No') 
    # cnt = 0
    # for l in L:
    #     num = l[0] ** 2 + l[1] ** 2 
    #     if num <= D ** 2:
    #         cnt+=1
    # print(cnt)
    # print(row)
    # total = sum(row)
    # target = total - K
    # if K == total:
    #     print(1)
    #     sys.exit()
    # col = []
    # for w in range(W):
    #     cnt = 0
    #     for h in range(H):    
    #         print(A[h][w])
    #         if A[h][w] == '#':
    #             cnt += 1
    #     col.append(cnt)
    # print(col)
    # ans = 0
    # for w in range(W):
    #     for h in range(H):
    #         if A[h][w] == '#':
    #             if col[w] + row[h] - 1 == target:
    #                 print(str(h) + str(w))
    #                 ans +=1
    #         else:
    #             if col[w] + row[h] == target:
    #                 print(str(h) + str(w))
    #                 ans +=1
    # print(ans)
    #     for  in x:


    # print('AC x ' + str(cnt['AC']))
    # print('WA x ' + str(cnt['WA']))
    # print('TLE x ' + str(cnt['TLE']))
    # print('RE x ' + str(cnt['RE']))
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
T=0
x=0
D=0
S=0
L=10**9+7

for i in range(0,N):
    x=A[i]**2
    D+=x

for j in range(0,N):
    S+=A[j]
    F=S**2

T=(F-D)/2

ans=T%L
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
N=int(input())
A = list(map(int, input().split()))
A2=copy.copy(A)
del A2[-1]
B=list(sum(A)-np.cumsum(np.array(A2)))
S = [(x*y)%(10**9+7)for (x, y) in zip(A2,B)]
print(sum(S)%(10**9+7))

Submission status: Wrong Answer

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