qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)
sum *= sum
sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = sum - sum2 % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= ((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))


Fixed code:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))
Buggy code:
MODINT = 1000000007
n = int(input())
A = list(map(int,input().split()))
prodsum = [0]*n
prodsum[0] = A[0]
for i in range(1,n):
    prodsum[i] = prodsum[i-1]+A[i]
# print(prodsum)
ans = 0
for i in range(n-1):
    ans += A[i]*(prodsum[-1]-prodsum[i])
    ans % MODINT
print(ans)


Fixed code:
MODINT = 1000000007
n = int(input())
A = list(map(int,input().split()))
prodsum = [0]*n
prodsum[0] = A[0]
for i in range(1,n):
    prodsum[i] = prodsum[i-1]+A[i]
# print(prodsum)
ans = 0
for i in range(n-1):
    ans += A[i]*(prodsum[-1]-prodsum[i])
print(ans%MODINT)
Buggy 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)


Fixed code:
N = int(input())

A = list(map(int, input().split()))
S = sum(A)
ans = 0
for i in range(N):
    S -= A[i]
    ans += A[i] * S
    

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

print(ans)
Buggy code:
N = int(input())
A = input().split(' ')
a = 0
sum = 0
for i in range(1, N):
    sum += int(A[i])
for i in range(N):
    a += int(A[i]) *  sum
    if i < N - 1:
        sum -= int(A[i + 1])
    a %= (10e9 + 7)
    
    
print(int(a))

Fixed code:
N = int(input())
A = input().split(' ')
a = 0
sum = 0
for i in range(1, N):
    sum += int(A[i])
for i in range(N):
    a += int(A[i]) *  sum
    if i < N - 1:
        sum -= int(A[i + 1])
    
print(int(a % (10 ** 9 + 7)))
Buggy code:
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
y=sum(a[i]**2 for i in range(n))
z=(x*x-y)/2

print(z%1000000007)



Fixed code:
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
y=sum(a[i]**2 for i in range(n))
z=(x*x-y)//2

print(z%1000000007)
Buggy code:
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)

Fixed code:
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)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
count = 0
su = sum[a]
for i in range(n-1):
	su -= a[i]
	count += a[i]*su
print(count%(10**9+7))

Fixed code:
n = int(input())
a = list(map(int,input().split()))
count = 0
su = sum(a)
for i in range(n-1):
	su -= a[i]
	count += a[i]*su
print(count%(10**9+7))
Buggy code:
N = int(input())
A = list(map(int,input().split()))
Ans = 0
for i in range(N-1):
    Ans += A[N-i-1]*sum(A[:N-i-1])
    print(A[N-i-1],sum(A[:N-i-2]))
print(Ans%((10**9)+7))

Fixed code:
N = int(input())
A = list(map(int,input().split()))
Ans = 0
S = sum(A)

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

print(Ans%((10**9)+7))
Buggy code:
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))/2)%c)

Fixed code:
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
c = 10 ** 9 + 7

ans = 0
tmp_val = 0
for i in range(n):
  tmp_val = (tmp_val + a[i]) % c

for i in range(n-1):
  tmp_val = (tmp_val - a[i]) % c
  ans += (tmp_val * a[i]) % c

print(ans)


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

ans = 0
tmp_val = 0
for i in range(n):
  tmp_val = (tmp_val + a[i]) % c

for i in range(n-1):
  tmp_val = (tmp_val - a[i]) % c
  ans += (tmp_val * a[i]) % c

print(ans % c)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
ans=0

for ai in A:
    ans+=(ai*(s-ai)/2)
print(int(ans%(10**9+7)))

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

for ai in A:
    ans+=(ai*(s-ai))
print((ans//2)%(10**9+7))
Buggy code:
n = int(input())
an = list(map(int,input().split()))

mod = 10**9 + 7
total =sum(an)
ans = 0

for x in range(n-1):
  nokori = total-sum(an[:x+1])
  ans += an[x] * nokori % mod

    
    
print(ans)
    

Fixed code:
n = int(input())
an = list(map(int,input().split()))

mod = 10**9 + 7
total =sum(an)
ans = 0
z = an[0]

for x in range(n-1):
  nokori = total-z
  ans += an[x] * nokori % mod
  z += an[x+1]

    
ans = ans % mod    
print(ans)
Buggy code:
n = int(input())
list1 = list(map(int,input().split()))

mod = 10 ** 9 + 7
total = 0

for i in range(0,n-1):
    x = sum(list1)-sum(list1[:i+1])
    total += list1[i] * x % mod

print(total)


Fixed code:
n = int(input())
list1 = list(map(int,input().split()))

mod = 10 ** 9 + 7
total = 0
y = sum(list1)

for i in range(0,n-1):
    y = y- list1[i]
    total += list1[i] * y % mod

total = total % mod
print(total)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
c = sum(a)

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

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


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

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

print(ans % (10 ** 9 + 7))
Buggy code:
import collections

n = int(input())

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

q = collections.deque(a)

retu = sum(a)
ans = 0

for i in range(n):
    nowA = q.popleft()
    retu -= nowA
    ans += (nowA * retu)
    print(nowA,retu)

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

Fixed code:
import collections

n = int(input())

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

q = collections.deque(a)

retu = sum(a)
ans = 0

for i in range(n):
    nowA = q.popleft()
    retu -= nowA
    ans += (nowA * retu)

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

Fixed 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

ans = ans%m

print(ans)
Buggy code:
n,*l=map(int,open(0).read().split())
print((sum(l)**2-sum(i**2 for i in l)//2)%(10**9+7))

Fixed code:
n,*l=map(int,open(0).read().split())
print((sum(l)**2-sum(i**2 for i in l))//2%(10**9+7))
Buggy code:
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))

Fixed code:
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))
Buggy code:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)/2)) % 1000000007
print(round(res))

Fixed code:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)%(1000000007)
sumA2 = (sumA * sumA)%(1000000007)
square = 0
for i in range(N):
    square +=  ( A[i]**2 ) % (1000000007)
    square = square % (1000000007)
buf = sumA2 - square
if buf < 0:
  buf = buf + (1000000007)
res = ( buf * ((1000000007+1)//2)) % 1000000007
print(int(res))
Buggy code:
N = int(input())
A_ls=list(map(int, input().split()))

a=(sum(A_ls))**2
for i in A_ls:
	a-=(i**2)

b=int(0.5+a/2)
print(b%(10**9+7))
#print(b)

# 2darray [[0] * 4 for i in range(3)]
# import itertools

Fixed code:
N = int(input())
A_ls=list(map(int, input().split()))

a=(sum(A_ls))**2
b=0
for i in A_ls:
	b+=(i**2)

c=int((a-b)//2)
print(c%(10**9+7))
#print(b)

# 2darray [[0] * 4 for i in range(3)]
# import itertools
Buggy code:
N = int(input())
A = list(map(int, input().split()))

from itertools import combinations

num = 10**9 + 7
ans = 0

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


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

from itertools import combinations

num = 10**9 + 7
ans = 0

B = []
b = 0
for i in reversed(A[1:]):
    b += i
    B.append(b)
B.reverse()
for x, y in zip(A[:-1], B):
    ans += x*y
    ans %= num
print(ans)
Buggy code:
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)


Fixed code:
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 - a[i]
  sigma = sigma + start * after
  if sigma >= (10**9 + 7):
    sigma = sigma % (10**9+7)

print(sigma)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
s=0
v=0
for i in range(n):
    s=(s+a[i])%(10**9+7)
    v=(v+a[i]**2)%(10**9+7)
s_2=s**2%(10**9+7)
print(((s_2-v)//2)%(10**9+7))

Fixed code:
n=int(input())
a=list(map(int,input().split()))
s=0
v=0
for i in range(n):
    s+=a[i]
    v+=a[i]**2
s_2=s**2
print(((s_2-v)//2)%(10**9+7))
Buggy code:
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)


Fixed code:
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)
Buggy code:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read
MOD = 10**9 + 7

n = int(input())
a = np.array(readline().split(), dtype=np.uint64)
r = np.cumsum(a[::-1])[::-1]
r &= MOD
x = a[:-1] * r[1:]
x %= MOD
ans = np.sum(x) % MOD
print(ans)

Fixed code:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read
MOD = 10**9 + 7

n = int(input())
a = np.array(readline().split(), dtype=np.uint64)
r = np.cumsum(a[::-1])[::-1]
r %= MOD
x = a[:-1] * r[1:]
x %= MOD
ans = np.sum(x) % MOD
print(int(ans))
Buggy code:
n = int(input())
Ai = list(map(int, input().split()))
sum_ans = sum(Ai)
ans = 0
mod = 100000007

for i in range(n-1):
    sum_ans -= Ai[i]
    ans += sum_ans * Ai[i]
    ans %= mod
print(ans)

Fixed code:
n = int(input())
Ai = list(map(int, input().split()))

sum_ans = sum(Ai)
ans = 0
mod = 1000000007

for i in range(n-1):
    sum_ans -= Ai[i]
    ans += sum_ans * Ai[i]
    ans %= mod

print(ans)
Buggy code:
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)


Fixed code:
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)
Buggy code:

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


mod = 10**9+7
s = sum(A)

ans = 0

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

print(ans)

Fixed code:

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


mod = 10**9+7
s = sum(A)

ans = 0

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

print(ans%mod)
Buggy code:
N=int(input())
A=list(map(int, input().split()))
p=10**9+7
S=sum(A)
S2=S**2
T=0
for i in range(N):
    T+=A[i]**2
ans=((S2-T)//2)%p
print(ans,S2)

Fixed code:
N=int(input())
A=list(map(int, input().split()))
p=10**9+7
S=sum(A)
S2=S**2
T=0
for i in range(N):
    T+=A[i]**2
ans=((S2-T)//2)%p
print(ans)
Buggy code:
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))


Fixed code:
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))
Buggy code:
N = int(input())
A = list(map(int, input().split()))

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

ans = ans % 10**9+7

print(int(ans))

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

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


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

s = sum(a**2 for a in n_list)
ans = sum(n_list) ** 2 - s

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

Fixed code:
n = int(input())
n_list = [int(i) for i in input().split()]

s = sum(a**2 for a in n_list)
ans = sum(n_list) ** 2 - s

print((ans//2)%(10**9+7))
Buggy code:
def solve(n,A):
	mod=10**9+7
	s=0
	print(A)
	for _,x in enumerate(A):
		s+=x
	s=s**2
	squared_terms=0
	for _,x in enumerate(A):
		y=x**2
		squared_terms+=y
	ans=(s-squared_terms)//2
	return ans%mod


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

Fixed code:
def solve(n,A):
	mod=10**9+7
	s=0
	for _,x in enumerate(A):
		s+=x
	s=s**2
	squared_terms=0
	for _,x in enumerate(A):
		y=x**2
		squared_terms+=y
	ans=(s-squared_terms)//2
	return ans%mod


N=int(input())
A=list(map(int,input().split()))
print(solve(N,A))
Buggy code:
N = int(input())
# N = 2 * 10 ** 5
A = tuple(map(int, input().split()))
# A = [10 ** 9] * N
MOD = 10 ** 9 + 7
rev_sum_list = [0] * N
rev_sum_list[-1] = A[-1]
for i in range(N - 2, -1, -1):
    rev_sum_list[i] = (rev_sum_list[i + 1] + A[i]) % MOD
print(rev_sum_list)
ans = 0
for i in range(1, N):
    ans += A[i - 1] * rev_sum_list[i]
    ans %= MOD
print(ans)

Fixed code:
N = int(input())
# N = 2 * 10 ** 5
A = tuple(map(int, input().split()))
# A = [10 ** 9] * N
MOD = 10 ** 9 + 7
rev_sum_list = [0] * N
rev_sum_list[-1] = A[-1]
for i in range(N - 2, -1, -1):
    rev_sum_list[i] = (rev_sum_list[i + 1] + A[i]) % MOD
# print(rev_sum_list)
ans = 0
for i in range(1, N):
    ans += A[i - 1] * rev_sum_list[i]
    ans %= MOD
print(ans)
Buggy code:
N = int(input())
A = [int(v) for v in input().split()]
MOD = int(1e9 + 7)

S = sum(A)
SQ = S * S
IS = sum(a*a for a in A)

print((SQ - IS) // 2)

Fixed code:
N = int(input())
A = [int(v) for v in input().split()]
MOD = int(1e9 + 7)

S = sum(A)
SQ = S * S
IS = sum(a*a for a in A)

print(((SQ - IS) // 2) % MOD)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
S = 0
S2 = 0
MOD = 1000000007
for i in range(N):
  S += A[i]
  S2 += A[i]*A[i]
print((S*S-S2)/2%MOD)


Fixed code:
N = int(input())
A = list(map(int,input().split()))
S = 0
S2 = 0
MOD = 1000000007
for i in range(N):
  S += A[i]
  S2 += A[i]*A[i]
print((S*S-S2)//2%MOD)
Buggy code:
n=int (input())
a= list(map(int,input().split()))
s2=int(sum(a)*sum(a))
a2=[int(i*i) for i in a]
ans1=int((s2-sum(a2))/2)
print(int(ans1%10**9+7))


Fixed code:
n=int (input())
a= list(map(int,input().split()))
s2=int(sum(a)*sum(a))
a2=[int(i*i) for i in a]
ans1=(s2-sum(a2))//2

print(int(ans1%((10**9)+7)))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
 
s = 0
for i in range(N):
  s += A[i]
  s %= (10**9+7)
s = s**2
s %= (10**9+7)
 
t = 0
for i in range(N):
  t += (A[i]**2 % (10**9+7))
t %= (10**9+7)

ans = (s-t) % (10**9+7)
tmp = (2**1000000005) % (10**9+7)
ans *= tmp
ans %= (10**9+7)
print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
 
s = 0
for i in range(N):
  s += A[i]
  s %= (10**9+7)
s = s**2
s %= (10**9+7)
 
t = 0
for i in range(N):
  t += (A[i]**2 % (10**9+7))
t %= (10**9+7)
 
ans = (s-t) % (10**9+7)
'''
tmp = (2**1000000005) % (10**9+7)
'''
tmp = 500000004
ans *= tmp
ans %= (10**9+7)
print(ans)
Buggy code:
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)

Fixed code:
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)
Buggy code:
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))

Fixed code:
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))**2 - sum_sq_a) // 2

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

Fixed code:
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
##print(S)
tmp=0
T=0
for i in range(N-1):
  T=T+A[i]
  ##print(T)
  ##print(A[i])
  tmp=(A[i]*(S-T)+tmp)
tmp=tmp%(10**9+7)
print(tmp)
Buggy code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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

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


if __name__ == '__main__':
    main()


Fixed code:
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

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

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


if __name__ == '__main__':
    main()
Buggy code:
# C - Sum of product of pairs
import numpy as np

N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
A = np.array(A)
csA = np.zeros((N+1), np.object)
for i in range(N):
    csA[i+1] = csA[i] + A[i]
    
ans = 0
for i in range(N-1):
    ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD)

Fixed code:
# C - Sum of product of pairs
import numpy as np

N = int(input())
A = list(int(a) for a in input().split())
MOD = 10**9 + 7
A = np.array(A)
csA = np.zeros((N+1), np.int64)
for i in range(N):
    csA[i+1] = (csA[i] + A[i]) % MOD
    
ans = 0
for i in range(N-1):
    ans += (A[i] * (csA[N] - csA[i+1])) % MOD
print(ans%MOD)
Buggy code:
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 
    temp=int(array_sum_square - 
            individual_square_sum) / 2
    return temp%1000000007








list=list()
n=int(input())
for i in range(n):
	l=int(input())
	list.append(l)
print(findProductSum(list,n))	
	

Fixed code:
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 
    temp=int(array_sum_square - 
            individual_square_sum) 
    temp=temp//2
    return temp%1000000007








n = int(input())
l = list(map(int, input().split()))
print(findProductSum(l,n))
Buggy code:
n=int(input())
i = list(map(int, input().split())) 

m=sum(i)

ans=0
for k in range(n-1):
    ans+=(i[k]+(m-i[k]))
ans=ans//2
ans=ans%(10**9+7)
print(ans)

Fixed code:
n=int(input())
i = list(map(int, input().split())) 

m=sum(i)

ans=0
for k in range(n):
    ans+=(i[k]*(m-i[k]))
ans=ans//2
ans=ans%(10**9+7)
print(ans)
Buggy code:
N = input()
As = list(map(int, input().split()))

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


Fixed code:
N = int(input())
As = list(map(int, input().split()))

result = 0
before_sum = sum(As)
for i in range(N-1):
    before_sum-=As[i]
    result+=As[i]*(before_sum)
print(result%(1*10**9+7))
Buggy code:
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()

Fixed code:
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()
Buggy code:
N = int(input())
A=list(map(int, input().split()))
B=[A[N-1]]
#print(B[0])
for i in range(len(A)-2):
    #print(i)
    b=B[i]+A[N-2-i]
    B.append(b)
print(B)
total=0
for i in range(len(B)):
    total += A[i]*B[len(B)-1-i]

print(total%(10**9+7))
    #print(v)

Fixed code:
N = int(input())
A=list(map(int, input().split()))
B=[A[N-1]]
#print(B[0])
for i in range(len(A)-2):
    #print(i)
    b=B[i]+A[N-2-i]
    B.append(b)
#print(B)
total=0
for i in range(len(B)):
    total += A[i]*B[len(B)-1-i]

print(total%(10**9+7))
Buggy code:
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
total=0

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

print(total)




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

A=sum(a)%mod
total=0

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

print(total)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]

sum1 = 0
sum2 = 0

for _ in a:
  sum1 += _
  sum2 += (_*_)
sum1 = (sum1 * sum1)
print((sum1 - sum2)//2)


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

sum1 = 0
sum2 = 0

for _ in a:
  sum1 += _
  sum2 += (_*_)
sum1 = (sum1 * sum1)
print(((sum1 - sum2)//2)%1000000007)
Buggy code:
n = int(input())
l = list(map(int,input().split()))
M = 1000000007
sm = 0
for i in l:
	sm = (sm + i)
sms = pow(sm,2,M)
ss = 0
for i in range(n):	
	ss = (ss + (l[i] * l[i]))
print(sms,ss)
print(((sms - ss)//2)%M)


Fixed code:
n = int(input())
l = list(map(int,input().split()))
M = 1000000007
sm = 0
for i in l:
	sm = (sm + i)
sms = pow(sm,2)
ss = 0
for i in range(n):	
	ss = (ss + (l[i] * l[i]))
print(((sms - ss)//2)%M)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
h = sum(a)
ans = 0
for i in range(n):
  h -= a[i]
  ans += (a[i]*(h)%(10**9+7))
print(ans)
 



Fixed code:
n = int(input())
a = list(map(int,input().split()))
h = sum(a)
ans = 0
for i in range(n):
  h -= a[i]
  ans += a[i]*(h)
print(ans%(10**9+7))
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i, a in enumerate(As, 1):
    ans += a*(SUM-a)
    ans %= mod
print(ans*pow(2, mod-2, mod))

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
mod = 10**9+7

SUM = sum(As)
ans = 0
for i, a in enumerate(As, 1):
    ans += a*(SUM-a)
    ans %= mod
print(ans*pow(2, mod-2, mod)%mod)