qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    x = sum(A)

    ans = 0

    for i in range(N):
        x -= A[i]
        y = x%MOD
        z = (y*A[i])%MOD

        ans +=z

    return print(ans)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    aa = list(accumulate(A))
    #print(aa)
    x = sum(A)
    #print(x)

    ans = 0

    for i in range(N):
        ans += A[i]*(aa[N-1]-aa[i])%MOD
        ans %= MOD
    return print(ans)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
A = list(map(int, input().split()))



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

A_sum_sq = A_sum * A_sum

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

Answer = (A_sum_sq -
          idv_sq_sum) / 2
print(Answer%(10**9 + 7))

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



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

A_sum_sq = A_sum * A_sum

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

Answer = (A_sum_sq -
          idv_sq_sum) // 2
print(Answer%(10**9 + 7))
Buggy code:
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)


Fixed code:
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)
Buggy code:
a=input().split()
sum=0
for i in range(len(a)):
  a[i]=(int)(a[i])
for i in a:
  sum+=i
ans=0
ans+=(sum**2)
for i in a:
  ans-=i*i
return (ans/2)%(10**9+7)

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

MOD = 1000000007

Alist = Alist[::-1]

mod = 0

ans = 0
for n in range(N-1):
    mod += (Alist[n]%MOD)
    mod = mod % MOD
    ans += (Alist[n+1] * mod)%MOD

print(ans)

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

MOD = 1000000007

Alist = Alist[::-1]

mod = 0

ans = 0
for n in range(N-1):
    mod += (Alist[n]%MOD)
    mod = mod % MOD
    ans += (Alist[n+1] * mod)%MOD

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

Fixed code:
n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
mod = 10**9 + 7
for i in range(n):
  ans = (ans + a[i] * s) % mod
  s = (s + a[i]) % mod
print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
total = sum(a)
total %= mod
total = total ** 2
total %= mod
cnt = 0
for i in range(n):
  cnt += a[i]**2
  cnt %= mod

ans = total - cnt
ans %= mod
print(ans)
  

Fixed code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
total = sum(a)
total = total ** 2
cnt = 0
for i in range(n):
  cnt += a[i]**2

ans = (total - cnt) // 2
ans %= mod

print(ans)
Buggy code:

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


Fixed code:

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

for a in A:
    tmp -= a
    sum_ += a * tmp

print(sum_)


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

for a in A:
    tmp -= a
    sum_ += a * tmp

print(sum_ % (1_000_000_007))
Buggy code:
n=int(input())
a=list(map(int,input().split()))

mod=10**9+7
total = sum(a)
cum=[]

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

print(ans)


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

mod=10**9+7
total = sum(a)
cum=[]

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

print(ans%mod)
Buggy code:
n = int(input())
l = list(map(int,input().split()))
s = 0
s1 = sum(l)
for x in range(n-1):
  s+=l[x]*(s1-l[x])
print(s%1000000007)


Fixed code:
n = int(input())
l = list(map(int,input().split()))
s = 0
s1 = sum(l)
a = 0
for x in range(n-1):
  s+=(l[x]*(s1-l[x]-a))
  a+=l[x]
print(s%1000000007)
Buggy code:
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))


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

Fixed code:
ans = 0
N = int(input())
array = list(map(int, input().split()))
x = sum(array)
y = 0
for i in range(N):
  y += array[i]**2

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

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

A_sum = sum(A)
ans = 0


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

print(ans%(10**9+7))
Buggy code:
n = int(input())
a = map(int,input().split())
mod = 10**9 + 7
temp = sum(a)**2
for x in a:
  temp -= x**2
print((temp//2)%mod)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
temp = sum(a)**2
for x in a:
	temp -= x**2
print((temp//2)%mod)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
prod_sum = 0
sum_arr = [0]*n
sum_arr[n-1] = a[n-1]
for i in range(n-2, -1, -1):
    sum_arr[i] = sum_arr[i+1] + a[i]
print(a, sum_arr)
for i in range(n-1):
        prod_sum += a[i]*sum_arr[i+1]
print(prod_sum%(10**9+7))


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

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

mod = 1000000007
res = np.cumsum(A, dtype=np.float64)
ans = 0

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

print(ans)



Fixed code:
import numpy as np

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

mod = 1000000007
res = np.cumsum(A, dtype=np.float64)
ans = 0

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

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

a2=[a[n-1]]
for i in range(n-1,0,-1):
    a2.append(a2[-1]+a[i-1])
print(a2)
ans=0
for i in range(n-1):
    ans = ( ans + (a[i]*a2[-i-2]) )%(10**9+7)
print(ans)


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

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

Fixed code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
invtwo = pow(2, mod-2, mod)
s = sum(a) % mod
ans = 0
for x in a:
  ans += (s-x) * x
  ans %= mod
print((ans * invtwo) % mod)
Buggy code:
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9 + 7
sum_A = sum(A)
ans = 0
for i in A:
  ans += i * (sum_A := sum_A - i) % mod
  
print(ans)  
  


Fixed code:
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9 + 7
sum_A = sum(A)
ans = 0
for i in A:
  ans += i * (sum_A := sum_A - i) % mod
  
print(ans % mod)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
 
# 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
 
print(int(findProductSum(a, n))%10**9+7) 

Fixed code:
n = int(input())
a = list(map(int, input().split()))
 
# 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)
mod = 10**9+7
  
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
  
print(modinv(2)*int(findProductSum(a, n))%mod)
Buggy code:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
a_sum=sum(A)%MOD
ans=(a_sum**2)%MOD
ans-=sum(map(lambda x: x*x%MOD, A))%MOD
print(ans//2%MOD)

Fixed code:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=sum(A)**2
ans-=sum(map(lambda x: x**2, A))
ans//=2
print(ans%MOD)
Buggy code:
from itertools import combinations
import math
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007

def add(a, b):
    return (a + b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(add(result[-1], x))
    return result

#N = int(input())
#C = input()
#D, T, S=map(int,input().split())
#C = []
#for i in range(N):
#    C.append(list(map(int,input().split())))

inv = cumsum(list(reversed(A)))
c = 0
for i in range(0,N-1):
    print(N-i-2)
    c = add(c,mul(A[i],inv[N-i-2]))

print(c)


Fixed code:
from itertools import combinations
import math
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007

def add(a, b):
    return (a + b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(add(result[-1], x))
    return result

#N = int(input())
#C = input()
#D, T, S=map(int,input().split())
#C = []
#for i in range(N):
#    C.append(list(map(int,input().split())))

inv = cumsum(list(reversed(A)))
c = 0
for i in range(0,N-1):
    c = add(c,mul(A[i],inv[N-i-2]))

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

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

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

Fixed code:
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))
Buggy code:
p=10**9+7
n=int(input())
A=[int(x) for x in input().split()]
A2=[(x**2) for x in A]
print((((sum(A))**2-sum(A2))/2)%p)

Fixed code:
p=(10**9+7)*2
n=int(input())
A=[int(x) for x in input().split()]
A2=[(x**2)%p for x in A]
result=(((sum(A)%p)**2 - sum(A2)%p)%p)/2
print(int(result))
Buggy code:
N = int(input())
A = [int(e) for e in input().split()]

S = [0]
sum =0
for i in range(0, N):
    S.append(S[i] + A[i])
    print(S[i+1])

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

print(sum)
 

Fixed code:
N = int(input())
A = [int(e) for e in input().split()]

S = [0]
sum =0
for i in range(0, N):
    S.append(S[i] + A[i])
for i in range(N):
    sum = sum + (S[i+1]-A[i]) * A[i]
print(sum%1000000007)
Buggy code:
N = int(input())
As = list(map(int, input().split()))
S = 0
T = 0
for i in range(N):
  S += As[i]
  T += As[i] * As[i]
# print(S)
# print(T)
A = S*S % 1000000007
B = T % 1000000007
print(int((A - B)/2) % 1000000007)

Fixed code:
N = int(input())
As = list(map(int, input().split()))
S = 0
T = 0
for i in range(N):
  S += As[i]
  T += (As[i] * As[i]) % 1000000007
# print(S)
# print(T)
A = S*S % 1000000007
B = T % 1000000007
X = (A - B) % 1000000007

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


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

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print((tmp*tmp-tmp2)//2%1000000007)

Fixed code:
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print((tmp*tmp-tmp2)//2%1000000007)
Buggy code:
n = int(input())
a_list = list(map(int, input().split()))

MOD = (10**9)+7
a_sum = 0
ans = 0
for i in range(n-1):
    a_sum += a_list[n-i-1]
    print(a_sum)
    ans += a_sum * a_list[n-i-2]
    ans = ans % MOD

print(ans)


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

MOD = (10**9)+7
a_sum = 0
ans = 0
for i in range(n-1):
    a_sum += a_list[n-i-1]
    ans += a_sum * a_list[n-i-2]
    ans = ans % MOD

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

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

Fixed code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

S = sum(A)
S %= MOD
ans = 0
for a in A:
    S += MOD
    S -= a
    S %= MOD
    ans += a * S
    ans %= MOD

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

mod= 10**9+7

A = sum(a)

ans=0

for i in a:
  ans += (A-i)*i %mod
print(ans//2%mod)
  

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

mod= 10**9+7

A = sum(a)

ans=0

for i in a:
  A -= i
  A%=mod
  ans += A*i
  ans%=mod
print(ans)
Buggy 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]
for i in range(n-1, 0, -1):
    ans += (A[i]*a[i])%num
    ans = ans%num
print(ans)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
A = [0]*(n)
num = 1000000007
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 = int(ans % num)
print(int(ans))
Buggy code:
n = int(input())
a = list(map(int,input().split()))

sums = 0
for i in range(n):
    sums += a[i]

sums *= sums;
ans = sums;

for i in range(n):
    ans -= a[i]*a[i]
ans /= 2

ans %= 1000000007
print(ans)


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

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

ans = (suma - sums) // 2
ans %= 1000000007

print(int(ans))
Buggy code:
n = int(input())
a = list(map(int, input().split()))
i = 0
tmp = 0
tmpura = 0
while(i < n):
    tmp += a[i]
    i+=1
tmp=tmp **2
i = 0
while (i < n):
    tmpura += a[i]**2
    i+=1
tmpura=tmpura
ans = ((tmp - tmpura)/2)%(10**9+7)
print(ans)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
i = 0
tmp = 0
tmpura = 0
while(i < n):
    tmp += a[i]
    i+=1
tmp=tmp **2
i = 0
while (i < n):
    tmpura += a[i]**2
    i+=1
tmpura=tmpura
ans = ((tmp - tmpura)//2)%(10**9+7)
print(ans)
Buggy code:
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)

Fixed code:
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)
Buggy code:
n = int(input())
mod = 10**9 + 7
a = [int(x)%mod for x in input().split()]
allsum = sum(a)
s = 0
for i in range(n):
    allsum = allsum -a[i]
    s += a[i]*allsum
print(s)

Fixed code:
n = int(input())
mod = 10**9 + 7
a = [int(x)%mod for x in input().split()]
allsum = sum(a)
s = 0
for i in range(n):
    allsum = allsum -a[i]
    s += a[i]*allsum
print(s%mod)
Buggy code:

mod = 10 ** 9 + 7


N = int(input().rstrip())
As = list(map(int, input().rstrip().split()))
ans = 0.0
add = 0.0

for i in range(N):
	add += As[i]
ans = add * add / 2.0

for i in range(N):
	ans -= As[i] * As[i] / 2.0

print(int(ans) % mod)


Fixed code:

mod = 10 ** 9 + 7


N = int(input().rstrip())
As = list(map(int, input().rstrip().split()))
ans = 0
add = 0

for i in range(N):
	add += As[i]
	add %= mod
ans = add * add % mod

for i in range(N):
	ans -= As[i] * As[i] % mod
	if (ans < 0):
		ans += mod

ans *= int((mod + 1) / 2)
ans %= mod

print(ans)
Buggy code:
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()
b = 0
ans = 0

for i in a:
    b += i ** 2

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


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

n = int(input())
a = readInt()
b = 0
ans = 0

for i in a:
    b += i ** 2

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

Fixed code:
N=int(input())
List = list(map(int, input().split()))
S=0
for i in range(len(List)):
    S+=List[i]
mod=10**9+7
S=S%mod
T=0
s=0
for i in range(len(List)):
    s+=List[i]
    s=s%mod
    T+=List[i]*(S-s)
    T=T%mod
print(T)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
D = 1000000007


ans = 0
B = [0] * (N + 1)

for i in range(N-1, -1, -1):
    print(i)
    B[i] = (B[i+1] + A[i]) % D

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

print(int(ans % D))

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


ans = 0
B = [0] * (N + 1)

for i in range(N-1, -1, -1):
    B[i] = (B[i+1] + A[i]) % D

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

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

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

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

for i in range(N):
  sum_A = sum_A - A[i]
  
  ans += A[i] * sum_A
  
print(ans%(10**9 + 7))
Buggy code:
mod = 1000000007

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    for i in range(N - 1):
        ans += (A[i] * sum(A[i + 1:]) / mod)
    print(ans % mod)

if __name__ == "__main__":
    solve()

Fixed code:
mod = 1000000007

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    s = sum(A)
    for i in range(N - 1):
        s -= A[i]
        ans += A[i] * s
    print(ans % mod)

if __name__ == "__main__":
    solve()
Buggy code:
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

mod=1000000007
n = r()
a = rl()
b = [a[-1]]
for i in range(n-2,-1,-1):
    b.append(b[-1]+a[i])
b = b[::-1]
print(b)
ans = 0
for i in range(n-1):
    ans= (ans+(a[i]*b[i+1])%mod)%mod
print(ans)

Fixed code:
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

mod=1000000007
n = r()
a = rl()
b = [a[-1]]
for i in range(n-2,-1,-1):
    b.append(b[-1]+a[i])
b = b[::-1]
ans = 0
for i in range(n-1):
    ans= (ans+(a[i]*b[i+1])%mod)%mod
print(ans)
Buggy code:
N = int(input())
As = list(map(int,input().split()))
sums = 0
moder = 1000000007
s=[0 for i in range(N-1)]
s[-1] = As[-1]
for i in range(N-2):
  s[-(i+2)] = s[-(i+1)]+As[-(i-2)]
for i in range(N-1):
  sums+= (As[i]*s[i])%moder
print(sums%moder)

Fixed code:
N = int(input())
As = list(map(int,input().split()))
sums = 0
moder = 1000000007
s=[0 for i in range(N-1)]
s[-1] = As[-1]
for i in range(N-2):
  s[-(i+2)] = s[-(i+1)]+As[-(i+2)]

for i in range(N-1):
  sums+= (As[i]*s[i])%moder
print(sums%moder)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
s = [0]
ans = 0
for i in range(0, n, 1):
    s.append((s[i] + a[i]) % 1000000007)

for i in range(0, n, 1):
    ans += (s[n] - s[i + 1]) * a[i] % 1000000007

print(ans)


Fixed code:
n = int(input())
a = list(map(int, input().split()))
s = [0]
ans = 0
MOD = 1000000007
for i in range(0, n, 1):
    s.append((s[i] + a[i]) % MOD)

for i in range(0, n, 1):
    ans += ((s[n] - s[i + 1]) * a[i]) % MOD

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

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

MOD=10**9+7
sumA=0
for i in range(N):
    sumA=(sumA+A[i])%MOD

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

print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
A_sum = sum(A[1:])

tot = 0
for i in range(N-1):
    tot += (A[i]*A_sum)%(10**9+7)
    A_sum -= A[i+1]
    
print(tot)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
A_sum = sum(A[1:])

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

A = sum(a)
A *= A
B = 0
for ai in a:
    B += ai * ai
print((A - B)/ 2 % 1000000007)

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

M = 1000000007
A = sum(a)
A *= A
B = 0
for ai in a:
    B += ai * ai
print(int((A - B) // 2 % M))