qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
numbers = list(map(int, input().split()))
result = 0
sum_of_numbers = sum(numbers)
for i in range(n - 1):
    sum_of_numbers -= numbers[i]
    result += (numbers[i] * sum_of_numbers) % 1000000007
print(result)

Fixed code:
n = int(input())
numbers = list(map(int, input().split()))
result = 0
sum_of_numbers = sum(numbers)
for i in range(n - 1):
    sum_of_numbers -= numbers[i]
    result += numbers[i] * sum_of_numbers
    result %= 1000000007
print(result)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

M = 0

for i in range(1,N-1):
  for j in range(i+1,N):
    M  += A[i] * A[j]
    if  M > 10**9 + 7:
      M = M %(10**9 +7)
print(M)

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

M = 0
sum = 0
for i in range(N):
  sum += A[i]

for i in range(N-1):
  sum = sum - A[i]
  M += A[i] * sum
  if M > 10 ** 9 + 7:
    M = M % (10 ** 9 + 7)
print(M)
Buggy code:
n = int(input())
arr = list(map(int,input().split()))
su = sum(arr)
c = 0
for item in arr:
  c+= item*item
print((su**2 - c)%(10**9 + 7))

Fixed code:
n = int(input())
arr = list(map(int,input().split()))
su = sum(arr)
c = 0
for item in arr:
  c+= item*item
print(((su**2 - c)//2)%(10**9 + 7))
Buggy code:
34I=lambda:list(map(int,input().split()))
mod=10**9+7
n,=I()
l=I()
pre=l.copy()
suf=l.copy()
for i in range(n-2,-1,-1):
	suf[i]+=suf[i+1]
ans=0
#print(suf)
for i in range(n-1):
	ans+=(l[i]*suf[i+1])
	ans%=mod
print(ans)


Fixed code:
I=lambda:list(map(int,input().split()))
mod=10**9+7
n,=I()
l=I()
pre=l.copy()
suf=l.copy()
for i in range(n-2,-1,-1):
	suf[i]+=suf[i+1]
ans=0
#print(suf)
for i in range(n-1):
	ans+=(l[i]*suf[i+1])
	ans%=mod
print(ans)
Buggy code:
import math
from fractions import Fraction as frac

MOD = 1e9 + 7

def solve(case_no):
    n = int(input())
    a = list(map(int, input().split()))
    ps = [a[0]]
    for i in range(1, n):
        ps.append(ps[i - 1] + a[i])
    ans = 0
    for i in range(n - 2, -1, -1):
        ans += a[i + 1] * ps[i]
        ans %= MOD
    print(ans)

t = 1
# t = int(input())
for i in range(1, t + 1):
    solve(i)


Fixed code:
import math
from fractions import Fraction as frac

MOD = 1000000007

def solve(case_no):
    n = int(input())
    a = list(map(int, input().split()))
    ps = [a[0]]
    for i in range(1, n):
        ps.append(ps[i - 1] + a[i])
    ans = 0
    for i in range(n - 2, -1, -1):
        ans += a[i + 1] * ps[i]
        ans %= MOD
    print(int(ans))

t = 1
# t = int(input())
for i in range(1, t + 1):
    solve(i)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
S = sum(A)
S2 = sum(map(lambda x: x*x%mod,A))
ans = ((S*S - S2)/2)%mod
print(int(ans))

Fixed code:
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
S = sum(A)
S2 = sum(map(lambda x: x*x,A))
ans = (S*S - S2)// 2 % mod
print(ans)
Buggy code:
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)

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

def main():
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0]*(n+1)
    MOD = 10**9 + 7

    for i in range(n):
        b_list[i+1] = b_list[i] + a_list[i]
    
    ans = 0
    for i in range(n):
        ai_sum = b_list[n] - b_list[i+1]
        ans += ai_sum * a_list[i]
        ans %= MOD
    print(ans)

Fixed code:
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0]*(n+1)
    MOD = 10**9 + 7

    for i in range(n):
        b_list[i+1] = b_list[i] + a_list[i]
    
    ans = 0
    for i in range(n):
        ai_sum = b_list[n] - b_list[i+1]
        ans += ai_sum * a_list[i]
        ans %= MOD
    print(ans)




    


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
a = list(map(int, input().split()))
A = sum(a)
print(A)
s = 0
for i in range(n-1):
    A = A - a[i]
    b = (a[i]*A)%(10**9+7)
    s = s + b
print(s%(10**9+7))

Fixed code:
n = int(input())
a = list(map(int, input().split()))
A = sum(a)
s = 0
for i in range(n-1):
    A = A - a[i]
    b = (a[i]*A)%(10**9+7)
    s = s + b
print(s%(10**9+7))
Buggy code:
N = int(input())
As = list(map(int,input().split()))
MOD = 7+10**9
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    print(As[i],As[j])
    ans = (ans+(As[i]*As[j]))%MOD
print(ans)

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

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

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

print(ans)


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

MOD = 10 ** 9 + 7

p = sum(A)

ans = 0
for i in range(N):
    p -= A[i]
    ans += (A[i] * p) % MOD
    ans %= MOD

print(ans)
Buggy code:
def findProductSum(A, n): 
    s = 0
    for i in range(n): 
        s = s + A[i] 
    array_sum_square = s * s 
    individual_square_sum = 0
    for i in range(n): 
        individual_square_sum += A[i] * A[i] 
    return (array_sum_square -individual_square_sum) / 2
n=int(input())
a=list(map(int,input().split()))
print(findProductSum(a,n))

Fixed code:
M=1000000007
def findProductSum(A, n): 
    s = 0
    for i in range(n): 
        s+=A[i] 
    array_sum_square = s*s
    individual_square_sum = 0
    for i in range(n): 
        individual_square_sum += A[i]*A[i]
    return (array_sum_square -individual_square_sum) // 2
n=int(input())
a=list(map(int,input().split()))
print(findProductSum(a,n)%M)
Buggy code:
n=int(input())
a = list(map(int,input().split()))
def p(val):
    print(val)
 
sho = 10**9 +7
a1 = sum(a)**2
b1 = list(map(lambda y:y**2,a))
b2=sum(b1)
result = ((a1-b2)/2)% sho
p(result)

Fixed code:
n=int(input())
a = list(map(int,input().split()))
def p(val):
    print(val)
 
sho = 10**9 +7
a1 = sum(a)**2
b1 = list(map(lambda y:y**2,a))
b2=sum(b1)
result = ((a1-b2)//2)% sho
p(result)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)


Fixed code:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)**2
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)
Buggy code:
n=int(input())
L=list(map(int,input().split()))
s=0
t=0
p=10**9+7
x=5*10**4+4
for i in range(0,n):
  s=(s+L[i])%p
  t=(t+L[i]*L[i])%p
ans=(x*(s*s-t))%p
print(ans)


Fixed code:
n=int(input())
L=list(map(int,input().split()))
s=0
t=0
p=10**9+7
x=5*10**8+4
for i in range(0,n):
	s=(s+L[i])%p
	t=(t+L[i]*L[i])%p

ans=x*(pow(s,2,p)-t)

print(ans%p)
Buggy code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    mylist = LI()
    shift = int(10e9 + 7)
    S = sum(mylist)
    res = 0
    
    for i in mylist:
        S-=i
        if S==0:
            break
        res += (i % shift) * (S % shift)
        res = res % shift
    

    print(int(res))
    
if __name__ == "__main__":
    main()

Fixed code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    mylist = LI()
    shift = 1000000007
    S = sum(mylist)
    res = 0
    
    for i in mylist:
        S-=i
        if S==0:
            break
        res += (S*i)%shift
    

    print(int(res % shift))
    
if __name__ == "__main__":
    main()
Buggy code:
M = 1000000007
n = int(input())
a = list(map(int,input().split()))
S = [0]
for i in range(n):
 S.append(S[-1]+a[i])%M
sum = 0
for i in range(n-1):
 sum += (a[i]*(S[n]-S[i+1]))%M
print(sum%M)


Fixed code:
M = 1000000007
n = int(input())
a = list(map(int,input().split()))
S = [0]
for i in range(n):
 S.append((S[-1]+a[i])%M)
sum = 0
for i in range(n-1):
 sum += (a[i]*(S[n]-S[i+1]))%M
print(sum%M)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans=0
suma=sum(a)
for i in range(n):
  ans+=(a[i]*(suma-a[i]))
  ans/=2
print(int(ans%(10**9+7)))

Fixed code:
n=int(input())
a=list(map(int,input().split()))
ans=0
suma=sum(a)
for i in range(n):
  suma-=a[i]
  ans+=(a[i]*(suma))%(10**9+7)
print(int(ans%(10**9+7)))
Buggy code:
import numpy as np
n = int(input())
num_list = list(map(int, input().split()))

mod = 1e+7+9
cumsum_list = np.cumsum(num_list[::-1])[::-1][1:]
score = 0
for i in range(n-1):
    score += num_list[i] * cumsum_list[i] % mod
    
print(score % mod)

Fixed code:
import numpy as np
n = int(input())
num_list = list(map(int, input().split()))

mod = int(1e+9+7)
cumsum_list = np.cumsum(num_list[::-1])[::-1][1:]
all_sum = sum(num_list)
score = 0
for i in range(n-1):
    #print(num_list[i], cumsum_list[i])
    #score += (num_list[i] * cumsum_list[i]) % mod
    all_sum -= num_list[i]
    score += (num_list[i] * all_sum) % mod
print(score % mod)
Buggy code:
def square(list):
    return [i ** 2 for i in list]
m = 1000000007
n = int(input())
A = list(map(int, input().split()))
sq = square(A)
s1 = sum(A)
s2 = sum(sq)

result = (s1**2-s2)/2
print(result%m)

Fixed code:
def square(list):
    return [i ** 2 for i in list]
m = 1000000007
n = int(input())
A = list(map(int, input().split()))
sq = square(A)
s1 = sum(A)
s2 = sum(sq)
 
result = (s1**2-s2)//2
print(result%m)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

partial_sum = copy.deepcopy(A)
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))


Fixed code:
import copy

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

partial_sum = copy.deepcopy(A)
sum_now = A[N-1]
for j in range(N-2,-1,-1):
    sum_now = int((sum_now+A[j])%mod)
    partial_sum[j] = sum_now
res = 0
for i in range(N-1):
    res = (res + (A[i]*partial_sum[i+1])%mod) %mod
print(int(res))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n-1):
    for j in range(i+1, n):
        s += a[i]*a[j] % (10**9+7)

print(str(s))


Fixed code:
n = int(input())
a = list(map(int, input().split()))
s = 0
mod = 10**9+7
asum = 0
for i in a:
    asum += i % mod
for i in range(n-1):
    s += ((a[i]%mod)*(asum-(a[i]%mod)))%mod
    asum = asum-(a[i]%mod)
s %= mod
print(str(s))
Buggy code:
n = int(input())
a = list(map(int, input().split()))

sum = 0

for i in range(n-1):
    sum_i = 0
    for j in range(n-i-1):
        sum_i += a[-(j+1)]
    print(sum_i)
    sum += (sum_i * a[i])

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

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

sum_a = 0
sum_i = sum(a)

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

print(sum_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)])

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

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

MOD = 10**9+7

ans = 0
for i in range(N-2):
  t =  A[i] * (A[i+1] + A[-1]) * (N - i - 1) // 2
  # print(t)
  ans += t % MOD

t = A[-2] * A[-1]
# print(t)
ans += t % MOD

print(ans)


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

MOD = 10**9 + 7

ans = 0
t = 0
for i in range(N-1):
  t += A[-1-i]
  ans += A[-2-i] * t % MOD
  ans %= MOD
print(ans)
Buggy code:
n = int(input())

s = input().split(" ")

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

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

Fixed code:
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))
Buggy code:
mod = 1000000007
n = int(input())
a = list(map(int,input().split()))
ans = 0
ans += (sum(a)*sum(a))%mod
for i in range(n):
    ans -= (a[i]*a[i])%mod
    if ans < 0:
        ans += mod
ans *= (mod + 1) / 2
ans %= mod
print(int(ans))

Fixed code:
mod = 1000000007
n = int(input())
a = list(map(int,input().split()))
ans = 0
ans += (sum(a)*sum(a))%mod
for i in range(n):
    ans -= (a[i]*a[i])%mod
    if ans < 0:
        ans += mod
ans *= (mod + 1) // 2
ans %= mod
print(int(ans))
Buggy code:
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)


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

for i in range(N-1):
  for j in range(i+1,N):
    s = s + x[i]*x[j] % 1000000007

print(s)


Fixed code:
N = int(input())
x = list(map(int, input().split()))
s = sum(x) - x[0]
ans = 0

for i in range(N-1):
  ans = ans + x[i]*s
  s = s - x[i+1]
ans = ans % 1000000007
  
  
print(ans)
Buggy code:
# Date [ 2020-08-29 21:10:46 ]
# Problem [ c.py ]
# Author Koki_tkg

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    a = read_int_list()
    
    ans = 0

    total = sum(a)
    for i in range(n):
        ans += (a[i] * (total - a[i])) / 2
        ans %= MOD

    print(ans % MOD)

if __name__ == '__main__':
    Main()

Fixed code:
# Date [ 2020-08-29 21:10:46 ]
# Problem [ c.py ]
# Author Koki_tkg

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    a = read_int_list()
    
    ans = 0

    total = sum(a)
    floatcnt = 0
    for i in range(n):
        ans += a[i] * (total - a[i])
        ans %= MOD
        total -= a[i]

    print(int(ans % MOD))

if __name__ == '__main__':
    Main()
Buggy code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
import numpy 
 
def main():
    n = int(input())
    alist = list(map(int, input().split()))
    max_num = 10**9 + 7
    ans = 0
    for i in range(n):
        ans += numpy.cumsum(alist[:i+1])

    print(ans%max_num)

if __name__ == "__main__":
    main()

Fixed code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
 

def cumsum(xs):
    pass

def main():
    n = int(input())
    alist = list(map(int, input().split()))
    max_num = 10**9 + 7
    ans = 0
    sum_num = sum(alist)

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

    print(ans%max_num)

if __name__ == "__main__":
    main()
Buggy code:
MOD = 1000000007

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

array_sum = 0
for i in range(0, n, 1): 
    array_sum = (array_sum % MOD + a[i]%MOD)%MOD 

array_sum_square = pow(array_sum,2,MOD)

individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum+= pow(a[i],2,MOD)
    individual_square_sum%MOD

ans=(array_sum_square - individual_square_sum) / 2
print(int(ans%MOD))

Fixed code:
MOD = 1000000007

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

array_sum = 0
for i in range(0, n, 1): 
    array_sum += a[i]
    #array_sum%=MOD

array_sum_square = pow(array_sum,2)

individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum+= pow(a[i],2)
    #individual_square_sum%=MOD

ans=(array_sum_square - individual_square_sum) //2
print(ans%MOD)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
ans=0
for i in range(n-1):
  s-=a[i]
  ans+=a[i]*s
print(ans)


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

for i in range(n-1):
    s-=a[i]
    ans+=a[i]*s
    ans%=INF
print(ans)
Buggy code:
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))

Fixed code:
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))
Buggy code:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = (ans+(10**9+7)**2//2) % (10**9+7)
  print(ans)
solve()

Fixed code:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans//2
  print(ans%(10**9+7))
solve()
Buggy code:
n = int(input())
a = list(map(int, input().split()))

s_1 = 0
s_2 = 0
for i in range(n):
    s_1 += a[i]
    s_2 += a[i] * a[i]
s = (s_1 * s_1 - s_2) / 2
print(s % (pow(10, 9) + 7))

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

s_1 = 0
s_2 = 0
m = 10 ** 9 + 7
for i in range(n):
    s_1 += a[i] % m
    s_2 += (a[i] ** 2) % m
s = (s_1 * s_1 - s_2) * pow(2, -1, m) % m
print(s)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

ans = 0
Q = 1e9 + 7

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

print(int(ans))

Fixed code:
N = int(input())
A = list(map(int, input().split()))
 
ans = 0
Q = int(1e9 + 7)
 
sumA = sum(A)
 
for i in range(N-1):
    sumA -= A[i]
    ans += sumA * A[i]
    ans %= Q
 
print(ans)
Buggy code:
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum += A[i] %MOD
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = (array_sum * array_sum )%MOD
  
    # 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 = [int(x) for x in input().split()]
MOD = 10**9 +7

print(int(findProductSum(a,n))%MOD)

# print(s%MOD)

Fixed code:
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        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 = [int(x) for x in input().split()]
MOD = 10**9 +7

print(int(findProductSum(a,n))%MOD)

# print(s%MOD)
Buggy code:
N = int(input())
A = list(map(int, input().split()))


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a) % 1000000007

print(int(ans))


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


sum_a = sum(A)
ans = 0
mod = int(1e9+7)

for a in A:
    sum_a -= a
    ans += (sum_a * a) % mod

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

Fixed code:
N = int(input())
A = list(map(int, input().split()))
tmp = sum(A[1:])
ans = 0
for i in range(N-1):
  ans += A[i]*tmp
  tmp -=A[i+1]
print(ans%(10**9+7))
Buggy code:
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

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

Fixed code:
n = input()
vals = list(map(int, input().split()))
s = sum(vals)
ret = 0
for i, val in enumerate(vals):
    ret += val * (s - val)

mod = 10 ** 9 + 7
print(int(ret//2) % mod)
Buggy code:
n = int(input())
A = map(int,input().split())

mod = 1000000007

ans = 0
tmp1, tmp2 = 0, 0

for m in A:
  tmp1 = (tmp1+m) %mod
  tmp2 = (tmp2+m*m%mod)%mod
  
ans = ((tmp1*tmp1)%mod-tmp2)%mod

if ans%2 ==0:
  ans = ans/2
else:
  ans =(ans+mod)/2

print(float(ans))

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

mod = 1000000007

ans = 0
tmp1, tmp2 = 0, 0

for m in A:
  tmp1 = (tmp1+m) %mod
  tmp2 = (tmp2+m*m%mod)%mod
  
ans = ((tmp1*tmp1)%mod-tmp2)%mod

if ans%2 ==0:
  ans = ans/2
else:
  ans =(ans+mod)/2

print(int(ans))
Buggy code:
l = int(input())
num = input().split(' ')
num = [int(i) for i in num]
ans = 0
s = sum(num)
for i in range(l):
    print(s)
    s -= num[i]
    ans += num[i] * s
    print(ans)
print(ans%(10**9+7))

Fixed code:
l = int(input())
num = input().split(' ')
num = [int(i) for i in num]
ans = 0
s = sum(num)
for i in range(l):
    s -= num[i]
    ans += num[i] * s
print(ans%(10**9+7))