qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
li = list(map(int,input().split()))
mod = 10**9+7

S = sum(li)%mod
li2 = [x**2 for x in li]
S2 = sum(li2)%mod

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

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

S = sum(li)
li2 = [x**2 for x in li]
S2 = sum(li2)

print((S**2-S2)//2%mod)
Buggy code:
n = int(input())
a_list = list(map(int, input().split(' ')))
mod = 10**9 + 7

sum_ = sum(a_list)
result = 0
for a in a_list:
  sum_ -= a
  result += ((sum_ % mod) * a) % mod

print(result)

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

sum_ = sum(a_list)
result = 0
for a in a_list:
  sum_ -= a
  result += ((sum_ % mod) * a) % mod
  result = result % mod

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


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


if __name__ == '__main__':
    main()

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


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


if __name__ == '__main__':
    main()
Buggy code:
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ss=s**2
c=0
for i in range(n):
    c+=(l[i]*l[i])
print((ss-c)//2)


Fixed code:
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
ss=s**2
c=0
for i in range(n):
    c+=(l[i]*l[i])
p=(ss-c)//2
print(p%1000000007)
Buggy code:
N = int(input())
A = input().split()
S = 0
B = 0

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

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

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

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

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

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

print(((ans **2 - ans2)//2)%mod)
Buggy code:
S = int(input())
A = [int(x) for x in input().split()]

print("A:",A)

Sum = 0
Asum = sum(A) % 1000000007
for i in range(len(A) -1 ):
    b = A[i]
    Asum = Asum - b
    if Asum < 0:
        Asum = Asum + 1000000007
    Sum = (Sum + Asum * b) % 1000000007

print(Sum)

Fixed code:
S = int(input())
A = [int(x) for x in input().split()]

Sum = 0
Asum = sum(A) % 1000000007
for i in range(len(A) -1 ):
    b = A[i]
    Asum = Asum - b
    if Asum < 0:
        Asum = Asum + 1000000007
    Sum = (Sum + Asum * b) % 1000000007

print(Sum)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
summ1 = 0
answer = 0
temp = 0
summ2 = 0
summ3 = 0
for i in range(N):
    summ1 += A[i]
for l in range(N):
    summ3 += A[l]
    summ2 += A[l]*(summ1-summ3)
    print(summ3)
    print(summ2)
answer = summ2 % 1000000007
print(answer)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
summ1 = 0
answer = 0
temp = 0
summ2 = 0
summ3 = 0
for i in range(N):
    summ1 += A[i]
for l in range(N):
    summ3 += A[l]
    summ2 += A[l]*(summ1-summ3)
answer = summ2 % 1000000007
print(answer)
Buggy code:
n = int(input())
nums = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
pres = [0]
for i in nums:
    pres.append(pres[-1] + i)
for i in range(n):
    temp = nums[i] * (pres[n] - pres[i+1])
    ans += temp
print(ans)


Fixed code:
n = int(input())
nums = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
pres = [0]
for i in nums:
    pres.append(pres[-1] + i)
for i in range(n):
    temp = nums[i] * (pres[n] - pres[i+1])
    ans += temp
    ans %= mod
print(ans)
Buggy code:
MOD = 1000000007
n = int(input())
nums = list(map(int, input().split()))
x = sum(sums)
y = sum([(x[i]**2) for i in range(n)])
print(((x**2 - y)//2)% MOD)

Fixed code:
MOD = 1000000007
n = int(input())
nums = list(map(int, input().split()))
x = sum(nums)
y = sum([(nums[i]**2) for i in range(n)])
print(((x**2 - y)//2)% MOD)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)*sum(a)
for i in range(n):
  ans-=a[i]*a[i]
ans/=2
mod=10**9+7
ans//=mod
print(ans)

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

Fixed code:
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)
c = 0
for a in A:
  c += a**2
print(((sumA**2 - c)//2) % (10**9+7))
Buggy code:
from itertools import accumulate
mod = 1e9 +7
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans =0
    ac = list(accumulate(a))
    
    for i in range(n):
        ans += a[i]* (ac[-1]-ac[i])
        ans %=mod
    print(ans)

if __name__ == '__main__':
    main()

Fixed code:
from itertools import accumulate
mod = 10**9 +7

def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans =0
    ac = list(accumulate(a))

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

if __name__ == '__main__':
    main()
Buggy code:
n=int(input())
 
a=list(map(int,input().split()))
s = sum(a)
num = 0
for i in range(n):
  s = s- a[i]
  num =num+a[i]*s
else:
  print(num)


Fixed code:
n=int(input())

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

S = [0]*N

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

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

print(ans%mod)

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

S = [0]*N

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

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

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

mod = 10**9+7

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

tmp = 0
for i in range(N):
    tmp += (A[i]* A[i]) % mod
di = tmp % mod

tri = (all-di)//2

print(tri % mod)

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

mod = 10**9+7

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

tmp = 0
for i in range(N):
    tmp += (A[i]* A[i]) % mod
di = tmp % mod

ans = all - di
ans *= (mod + 1) // 2
ans %= mod

print(ans)
Buggy code:
def main():
    N = int(input())
    A_list = list(map(int, input().split()))
    mod = 10**9 + 7

    ans = 0
    A_ = sum(A_list) % mod
    for i in range(N):
        A = A_list[i]
        A_ = A_ - A
        ans = (ans + (A * A_) % mod)) % mod
    print(ans)
    return


if __name__ == '__main__':
    main()

Fixed code:
def main():
    N = int(input())
    A_list = list(map(int, input().split()))
    mod = 10**9 + 7

    ans = 0
    A_ = sum(A_list) % mod
    for i in range(N-1):
        A = A_list[i]
        A_ = A_ - A
        ans = (ans + (A * A_) % mod) % mod
    print(ans)
    return


if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
A = [int(num) for num in input().split()]

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


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

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

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


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

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

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

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

sum_tmp = sum(A)
mod = 10 ** 9 + 7
squ = 0
sum = 0

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

sum = (sum - squ) / 2
print(sum % mod)

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

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

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

answer = int(((sum - squ)  //  2 ) % mod)
print(answer)
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 = (array_sum % MOD * array_sum %MOD)%MOD

individual_square_sum = 0
for i in range(0, n, 1): 
    individual_square_sum = (individual_square_sum%MOD +((a[i]%MOD * a[i]%MOD)%MOD)%MOD)%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_square = pow(array_sum,2)

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

ans=(array_sum_square - individual_square_sum) //2
print(ans%MOD)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
add = 0
for i in range(N):
    tmp = sum(A[i+1:N])
    add += tmp * A[i]
print(add%mod

Fixed code:
N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
add = 0
tmp = sum(A)
for i in range(N):
    tmp -= A[i]
    add += tmp * A[i]
print(add%mod)
Buggy code:
mport sys
import numpy as np
import math
import collections
import copy
import decimal
import itertools
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations

# input = sys.stdin.readline
N = int(input())
An = list(map(int, input().split()))
An_l = list(itertools.accumulate(An))
An_l.insert(0, 0)
ans = 0
for i, A in enumerate(An):
    tt = An_l[-1] - An_l[i+1]
#     print(i, An_l[-1], An_l[i], tt)
    At = A * tt
#     print(A, tt, At)
    ans = (ans+At) % (10**9+7)
#     print(ans)
print(ans)



Fixed code:
import sys
import numpy as np
import math
import collections
import copy
import decimal
import itertools
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations
 
# input = sys.stdin.readline
N = int(input())
An = list(map(int, input().split()))
An_l = list(itertools.accumulate(An))
An_l.insert(0, 0)
ans = 0
for i, A in enumerate(An):
    tt = An_l[-1] - An_l[i+1]
#     print(i, An_l[-1], An_l[i], tt)
    At = A * tt
#     print(A, tt, At)
    ans = (ans+At) % (10**9+7)
#     print(ans)
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
S = [A[0]]
for i in range(1, N):
  S.append(S[i-1] + A[i])
print(S)
x = 0
for i in range(N):
  x += (A[i] * (S[-1] - S[i])) % 1000000007
x = x % 1000000007
print(x)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
S = [A[0]]
for i in range(1, N):
  S.append(S[i-1] + A[i])
x = 0
for i in range(N):
  x += (A[i] * (S[-1] - S[i])) % 1000000007
x = x % 1000000007
print(x)
Buggy code:
n = int(input())
mod = 10**9+ 7
a = list(map(int,input().split()))
ans = (sum(a)%mod)**2 - (sum[x**2 for x in a]%mod)
ans *= 5*10**8+4
ans %= mod
print(ans)

Fixed code:
n = int(input())
mod = 10**9+ 7
a = list(map(int,input().split()))
ans = (sum(a)%mod)**2 - sum([x**2%mod for x in a])
ans *= 5*10**8+4
ans %= mod
print(ans)
Buggy code:
n = int(input())
x = list(map(int, input().strip().split()))
sum=0
minsum=0
for i in range(0,n):
    minsum += x[i]
for i in range(0,n-1):
    minsum-=x[i]
    sum += x[i]*minsum
    print(sum)
    if(sum>10**9+7):
        sum%=(10**9+7)
print(sum)

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

    mod = 10**9 + 7

    tmp = [0] * N

    s = 0
    for i in range(N):
        tmp[- i - 1] = s
        s += A[-i - 1]

    print(tmp)

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

    print(ans % mod)


if __name__ == '__main__':
    main()


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

    mod = 10**9 + 7

    tmp = [0] * N

    s = 0
    for i in range(N):
        tmp[- i - 1] = s
        s += A[-i - 1]

    # print(tmp)

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

    print(ans % mod)


if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2 % x
summation2 = sum(b ** 2 for b in B) % x
summation = (summation1 - summation2) // 2 % x
print(summation)


Fixed code:
N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2
summation2 = sum(b ** 2 for b in B)
summation = ((summation1 - summation2) // 2) % x
print(summation)
Buggy code:
A = list(map(int, input().split()))

B = [0]*N

num = 0
for i in reversed(range(N)):
    B[i] = A[i] + num
    num = B[i]
    
ans = 0
for i in range(N-1):
    ans += A[i]*B[i+1] 

print(ans%1000000007)

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

B = [0]*N

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

print(ans%1000000007)
Buggy 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+(10**9+7)-sum(l))**(10**9+5))%(10**9+7))

Fixed 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+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 29 22:19:15 2020

@author: naoki
"""

N = int(input())

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

count1 = 0
count2 = 0
count = 10**9 +7
for i in A:
    count1+=i
	count1=count1%count
for j in A:
    count2 = j*(count1-j)%count + count2
    count1 = count1 -j 
    
print(count2%count)
    
    
    

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 29 22:19:15 2020

@author: naoki
"""

N = int(input())

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

count1 = 0
count2 = 0
count = 10**9 +7
for i in A:
    count1+=i

for j in A:
    count2 = (j*(count1-j) + count2)%count
    count1 = count1 -j 
    
print(count2%count)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
sm=0
mod=10**9+7
s=sum(A)
for i in range(A):
    s-=i
    sm+=i*s
    sm%=mod
print(sm)

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

Fixed code:
n = int(input())
a = [int(s) for s in input().split()]
b = []
val = 0
sum_val= 0
for i in range(0, n):
    b.append(a[i] * sum_val) 
    sum_val+= a[i] 
val = sum(b)
print(val % (10 ** 9 + 7))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
t = 0 
for i in range(len(A) - 1): 
        print(A[i] , sum(A[i + 1:]))
        t = (t + (A[i] * sum(A[i + 1:]))) % 1000000007
print(t)


Fixed code:
N = int(input())
A = list(map(int, input().split()))
t = 0 
S = sum(A)
c = 0 
for i in range(len(A) - 1): 
        S -= A[i]
        t = (t + (A[i] * S)) % 1000000007
print(t)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(len(a)):
  s += a[i]
for i in range(len(a)-1):
  s -= a[i]
  if s<0:
	s += 1e9+7
  ans += s*a[i]
  ans %= 1e9+7
print(int(ans))


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

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

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

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

ans = ans % MOD
print(ans)

Fixed code:
import math

N = int(input())
A = list(map(int ,input().split()))
MOD = math.floor(1e9+7)

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

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

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

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

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

print(ans)

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

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

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

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

mod=10**9+7

sumA=sum(A)%mod

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

ans=ans//2
print(ans%mod)
        

Fixed code:

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

mod=10**9+7

sumA=sum(A)

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

ans=ans//2
print(ans%mod)
Buggy code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
#for i in range(N):
#    A[i] = A[i] % (10**9+7)

mass = [0]*(N+1)
for i in range(N):
    mass[i+1] = mass[i] + A[i]
print(mass)
answer = 0
for i in range(N-1):
    answer += (A[i]*(mass[N]-mass[i+1]))
    print(answer)

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

Fixed code:
import sys
input = sys.stdin.readline

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

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

answer = 0
for i in range(N-1):
    answer += (A[i]*(mass[N]-mass[i+1]))


print(answer % (10**9 + 7))
Buggy code:
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr  =lambda x: stdout.write(str(x))

mod=1000000007


#main code
def findProductSum(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        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] 
    return (array_sum_square - 
            individual_square_sum) //2
n=ii()
arr=lii()
print(findProductSum(arr,n))

Fixed code:
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
stdstr =lambda: stdin.readline()
stdint =lambda: int(stdin.readline())
stdpr  =lambda x: stdout.write(str(x))

mod=1000000007


#main code
def findProductSum(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        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] 
    return (array_sum_square - 
            individual_square_sum)//2
n=ii()
arr=lii()
print(findProductSum(arr,n)%mod)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

MOD = 10**9 + 7
s = 0
for i in a:s+=i

ans = 0
for i in a:
    ans += (((i*s)-(i*i))/2)

print(int(ans%MOD))

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

MOD = 10**9 + 7
s = 0
for i in a:s+=i

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

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

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

s = sum(a)
ans = 0

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

s=0
for i in range(n-2,-1,-1):
    b[i]=b[i+1]+b[i]

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


Fixed code:
n= int(input())
mod=10**9+7
a= [int(x ) for x in input().split()]
b= a[:]

s=0
for i in range(n-2,-1,-1):
    b[i]=b[i+1]+b[i]
for i in range(n):
    s += (b[i]-a[i])*a[i]
print(s%mod)
Buggy code:
N = int(input())

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

ans = sum(A)^2

for a in A:
  ans -= a^2

ans /= 2

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

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

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

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