Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = ["0"]*n
if(m==0 and n==1):print(0);exit()
for i in range(m):
    a, b = map(int, input().split())
    if(ans[a-1] == "0"):ans[a-1] = str(b)
    elif(int(ans[a-1]) > b):ans[a-1] = str(b)
if(ans[0] == "0"):print(-1)
else:print("".join(ans))

Fixed submission:
n = int(input())
if(n%2 == 0):print(int(n/2))
else:print(int(n/2)+1)
Buggy python submission (verdict: Runtime Error):
n, k =map(int, input().split())
data = []
for i in range(k):
    data.append(list(map(int, input().split())))
for i in range(0, 10**n):
    a = str(i)
    tmp = True
    if(len(a) != n):tmp = False
    for i in data:
        data1 = i[0]
        data2 = i[1]
        #print(data1, data2)
        if(a[data1-1] != str(data2)):
            tmp=False
    if(tmp):print(a);exit()
if(n==1):print(0)
else:print(-1)

Fixed submission:
a,b=map(int,input().split())
c2=10**a
if(a==1):c1=0
else:c1=c2//10
v = [-1]*b
for i in range(b):
  n,m=map(int,input().split())
  v[i] = [n,m]
#print(v) 

for i in range(c1,c2):
  p =str(i)
  t=True
  for j in v:
    
    if(int(p[j[0]-1]) != j[1]):
      t=False
      break
  
  if(t):print(i);exit()
  
print(-1)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = []
m = n
for i in range(n):a.append(list(map(int, input().split())))

def distant(x1, y1, x2, y2):
    return math.sqrt(abs(x1-x2)**2+abs(y1-y2)**2)

ma = 0
while(m!=0):
    for i in range(m):
        if(i != m-1):
            p = distant(a[i][0], a[i][1], a[m - 1][0], a[m - 1][1])

            #print(p)
            #print(a[i][0], a[i][1], a[m-1][0], a[m-1][1])

            ma = max(ma, p)
    m = m - 1
print(ma/2)

Fixed submission:
s = "abcdefghijklmnopqrstuvwxyz"
c = input()
print(s[s.index(c)+1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
for i in range(n):
    if((i - k) < 0):
        if(t[i] == 'r'):ans += p
        elif(t[i] == 's'):ans += r
        else:ans += s
        continue
    
    else:
        if(t[i-k] == t[i]):t = t[:i] + 'n' + t[i+1:]
        else:
            if(t[i] == 'r'):ans += p
            elif(t[i] == 's'):ans += r 
            else:ans += s
print(ans)


Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
for i in range(n):
    if ((i - k) < 0):
        if (t[i] == 'r'):
            ans += p
        elif (t[i] == 's'):
            ans += r
        else:
            ans += s
        continue

    else:
        if (t[i - k] == t[i]):
            t = t[:i] + 'n' + t[i + 1:]
        else:
            if (t[i] == 'r'):
                ans += p
            elif (t[i] == 's'):
                ans += r
            else:
                ans += s
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
for i in range(n):
    if((i - k) < 0):
        if(t[i] == 'r'):ans += p
        elif(t[i] == 's'):ans += r
        else:ans += s
        continue
    
    else:
        if(t[i-k] == t[i]):t = t[:i] + 'n' + t[i+1:]
        else:
            if(t[i] == 'r'):ans += p
            elif(t[i] == 's'):ans += r 
            else:ans += s
print(score)


Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
for i in range(n):
    if ((i - k) < 0):
        if (t[i] == 'r'):
            ans += p
        elif (t[i] == 's'):
            ans += r
        else:
            ans += s
        continue

    else:
        if (t[i - k] == t[i]):
            t = t[:i] + 'n' + t[i + 1:]
        else:
            if (t[i] == 'r'):
                ans += p
            elif (t[i] == 's'):
                ans += r
            else:
                ans += s
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
n = int(input())
temp = 1
ans = 0
a = list(map(int, input().split()))
for i in a:
    temp = lcm(temp, i)

for i in a:
    ans +=  int(temp/i)

print(temp/ans)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(x, y):
    return (x * y) // gcd(x, y)


n = int(input())
temp = 1
ans = 0
a = list(map(int, input().split()))
for i in a:
    temp = lcm(temp, i)

for i in a:
    ans +=  int(temp/i)

print(temp/ans)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
data = []
data2 = []
ans = 0
for i in range(n):
    a = input()
    p = sorted(a)
    if p not in data:
        data.append(p)
        data2.append(1)
    else:
        data2[data.index(p)] += 1

#print(data2)
for i in data2:
    ans+=int(i*(i-1)/2)
print(ans)

Fixed submission:
n = int(input())
data = []
for i in range(n):data.append(sorted(input()))
data, backup, ans, temp = sorted(data), [], 0, 1
for i in data:
    if backup==i:temp+=1
    else:ans, temp = ans + int(temp*(temp-1)/2), 1
    backup = i
ans+= int(temp*(temp-1)/2)
print(ans)
Buggy python submission (verdict: Runtime Error):
#A
#n = int(input())
#print(3*n**2)
#B
n, d = map(int, input().split())
canseerange = 2*d+1
if n % canseerange == 0:
    print(int(n/canseerange))
else:
    print(int(n/canseerange)+1
#C
#n = int(input())
#ans = 0
#most1 = 0
#most2 = 0
#ed = False
#for i in range(n):
#    t = int(input())
#    ed = False
#    if most1 <= t:
#        most2 = most1
#        most1 = t
#        ans = i
#        ed = True
#    elif most2 <= t and ed == False:
#        most2 = t
#for i in range(n):
#    if i==ans:print(most2)
#    else:print(most1)
#D


Fixed submission:
#A
n = int(input())
print(3*n**2)
#B
#n, d = map(int, input().split())
#canseerange = 2*d+1
#if n % canseerange == 0:
#    print(int(n/canseerange))
#else:
#    print(int(n/canseerange)+1
#C
#n = int(input())
#ans = 0
#most1 = 0
#most2 = 0
#ed = False
#for i in range(n):
#    t = int(input())
#    ed = False
#    if most1 <= t:
#        most2 = most1
#        most1 = t
#        ans = i
#        ed = True
#    elif most2 <= t and ed == False:
#        most2 = t
#for i in range(n):
#    if i==ans:print(most2)
#    else:print(most1)
#D
Buggy python submission (verdict: Runtime Error):
n, d = map(int, input().split())
canseerange = 2*d+1
if n % canseerange == 0:
    print(int(n/canseerange))
else:
    print(int(n/canseerange)+1

Fixed submission:
#A
#n = int(input())
#print(3*n**2)
#B
n, d = map(int, input().split())
canseerange = 2*d+1
if n % canseerange == 0:
    print(int(n/canseerange))
else:
    print(int(n/canseerange)+1)

Buggy python submission (verdict: Runtime Error):
#A
#n = int(input())
#print(3*n**2)
#B
n, d = map(int, input().split())
canseerange = 2*d+1
if n % canseerange == 0:
    print(int(n/canseerange))
else:
    print(int(n/canseerange)+1
#C
#n = int(input())
#ans = 0
#most1 = 0
#most2 = 0
#ed = False
#for i in range(n):
#    t = int(input())
#    ed = False
#    if most1 <= t:
#        most2 = most1
#        most1 = t
#        ans = i
#        ed = True
#    elif most2 <= t and ed == False:
#        most2 = t
#for i in range(n):
#    if i==ans:print(most2)
#    else:print(most1)
#D


Fixed submission:
#A
#n = int(input())
#print(3*n**2)
#B
n, d = map(int, input().split())
canseerange = 2*d+1
if n % canseerange == 0:
    print(int(n/canseerange))
else:
    print(int(n/canseerange)+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = map(int, input().split())
d = sorted(d)
l = []
now = 0
ans = 0
for i in range(n-1):
    if d[i] != d[i+1]:
        a = d.index(d[i])
        b = d.count(d[i])
        index = a+b-1
        #print(index)
        if index+1 == n/2:
            #print(d[i+1], d[i])
            ans = d[i+1]-d[i]
print(ans)

Fixed submission:
s = input()
if s[0] == s[1] == s[2] == s[3]:
    print('No')
elif s[0] == s[1] and s[2] == s[3]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = map(int, input().split())
d = sorted(d)
l = []
now = 0
ans = 0
for i in range(n-1):
    if d[i] != d[i+1]:
        a = d.index(d[i])
        b = d.count(d[i])
        index = a+b-1
        #print(index)
        if index+1 == n/2:
            #print(d[i+1], d[i])
            ans = d[i+1]-d[i]
print(ans)

Fixed submission:
n = int(input())
d = map(int,input().split())
d = sorted(d)
print(d[int(n/2)]-d[int(n/2)-1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = map(int, input().split())
d = sorted(d)
l = []
now = 0
ans = 0
for i in range(n-1):
    if d[i] != d[i+1]:
        a = d.index(d[i])
        b = d.count(d[i])
        index = a+b-1
        #print(index)
        if index+1 == n/2:
            #print(d[i+1], d[i])
            ans = d[i+1]-d[i]
print(ans)

Fixed submission:
n = int(input())
d = map(int,input().split())
d = sorted(d)
print(d[int(n/2)]-d[int(n/2)-1])
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a, b, c, d = map(int, input().split())
sa = b-a+1
a1 = int((sa + a%c)/c)
a2 = int((sa + a%d)/d)
a3 = int((sa + a%(lcm(c, d)))/(lcm(c, d)))
print(sa-a1-a2+a3)
#print(a1)
#print(a2)
#print(a3)
#print(lcm(c, d))
#31
# 12 18 24 30 36
# 16 24 32 40
#3+2-1 = 4
#9-4+1 - 4

Fixed submission:
import math
def lcm(x, y):return (x * y) // math.gcd(x, y)
a,b,c,d=map(int,input().split())

e = lcm(c,d)
print(b-a+1-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a, b = map(int, input().split())
d = list(range(a, b+1))
for i in range(m-1):
    a, b = map(int, input().split())
    src_set = set(d)
    tag_set = set(list(range(a, b+1)))
    d = list(src_set & tag_set)
print(len(d))

Fixed submission:
n,m=map(int,input().split())
max_ = 0
min_ = n+1
for i in range(m):
  a,b=map(int, input().split())
  max_ = max(max_, a)
  min_ = min(min_, b)
#print(max_, min_)
if(min_ < max_):print(0)
else:print(min_-max_+1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
d = []
for i in range(m):
    a, b = map(int, input().split())
    d.append(list(range(a, b+1)))

b = d[0]
for i in d:
    src_set = set(b)
    tag_set = set(i)
    matched_list = list(src_set & tag_set)

print(len(matched_list))

Fixed submission:
n,m=map(int,input().split())
max_ = 0
min_ = n+1
for i in range(m):
  a,b=map(int, input().split())
  max_ = max(max_, a)
  min_ = min(min_, b)
#print(max_, min_)
if(min_ < max_):print(0)
else:print(min_-max_+1)
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
data = []
for i in range(q):data.append(list(map(int, input().split())))
for i in data:print(len(s[i[0]-1:i[1]].split('AC'))-1)

Fixed submission:
s = input()
if s=='A':print('T')
elif s=='T':print('A')
elif s=='C':print('G')
elif s=='G':print('C')
Buggy python submission (verdict: Runtime Error):
x = int(input())
if x == 3 or x == 5 or X == 7:
    print('YES')
else:
    print('NO')

Fixed submission:
x = int(input())
if x == 3 or x == 5 or x == 7:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
for i in range(1, n*2+1):
  if i%2==0 and i%n==0:
    print(i)
    exit()

Fixed submission:
n=int(input())
if n % 2 == 0:print(n)
else: print(n*2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split())
x=0
s=0
l=0
c=0
for r,b in enumerate(a):
  x^=b
  s+=b
  while x<s:
    x^=a[l]
    s-=a[l]
    l+=1
  c+=r-l+1
print(c)


Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    x = 0
    s = 0
    r = 0
    res = 0
    for l in range(N):
        while N > r:
            if s & A[r] != 0: break
            s += A[r]
            r += 1

        s -= A[l]
        res += r - l

    print(res)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(a[0]+b[0]+c[0])

Fixed submission:
a, b, c = map(str, input().split())
print(a[0]+b[0]+c[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = 0

for i in range(n):
    for j in range(i,n):
        b = max(b, (abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1])))
print(b)


Fixed submission:
def get_ints():
    return list(map(int, input().split()))

n = int(input())
a,b = [],[]
for i in range(n):
    x, y = get_ints()
    a.append(x+y)
    b.append(x-y)

a.sort()
b.sort()
ans = max(a[-1]-a[0], b[-1]-b[0])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = 0

for i in range(n):
    for j in range(i,n):
        b = max(b, (abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1])))
print(b)


Fixed submission:
def get_ints():
    return list(map(int, input().split()))

n = int(input())
a,b = [],[]
for i in range(n):
    x, y = get_ints()
    a.append(x+y)
    b.append(x-y)

a.sort()
b.sort()
ans = max(a[-1]-a[0], b[-1]-b[0])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = 0
while n > 0:
    a += n % 10
    n = n //10

if a % 9 == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
n = input()
a = 0
for i in range(len(n)):
    a += int(n[i])

if a % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
n = 7
cnt = 1
while 1:
    if n % k == 0:
        print(cnt)
        exit()
    elif n % k != 0 and cnt < k +1:
        cnt += 1
        n = (n*10 + 7) % k
    elif (n % k != 0 and cnt > k + 1):
        print(-1)
        exit()


Fixed submission:
k = int(input())

def cal(k):
    n = 7
    for i in range(1,10000000):
        if n % k == 0:
            return i
        else:
            n = (n *10 + 7) % k
    return -1

print(cal(k))

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
n = 7
cnt = 1
while 1:
    if n % k == 0:
        print(cnt)
        exit()
    elif n % k != 0 and cnt <1000000:
        cnt += 1
        n = (n*10 + 7) % k
    elif n % k != 0 and cnt > 1000000:
        print(-1)
        exit()


Fixed submission:
k = int(input())

def cal(k):
    n = 7
    for i in range(1,10000000):
        if n % k == 0:
            return i
        else:
            n = (n *10 + 7) % k
    return -1

print(cal(k))
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]*(n+1)
B = [0]*(m+1)
cnt  =0

for i in range(1,n+1):
    A[i] = A[i-1] + a[i-1]
for i in range(1,m+1):
    B[i] = B[i-1] + b[i-1]

for i in range(n+1):
    for j in range(m+1):
        if A[i] + B[j] <= k:
            cnt = max(i+j, cnt)

print(cnt)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]*(n+1)
B = [0]*(m+1)
cnt  =0

for i in range(1,n+1):
    A[i] = A[i-1] + a[i-1]
for i in range(1,m+1):
    B[i] = B[i-1] + b[i-1]

j = m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] + A[i] > k:
        j -= 1
    cnt = max(cnt, i + j)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num
ans = 0

for i in range(1,n+1):
    ans += i * search_divisor_num_1(i)

print(ans)

Fixed submission:
n = int(input())
ans  = 0
for i in range(1,n+1):
    ans += (i + i*(n//i))*(n//i)/2

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
cnt=0
for i in range(n):
    for j in range(n):
        if i*j>=n:
            break
        for k in range(n):
            if i*j+k>n:
                break
            if i*j+k==n:
                cnt+=1
print(cnt)

Fixed submission:
# Python3 program to count
# number of factors
# of an array of integers
MAX = 1000005

# array to store
# prime factors
factor = [0]*(MAX + 1)

# function to generate all
# prime factors of numbers
# from 1 to 10^6


def generatePrimeFactors():
    factor[1] = 1

    # Initializes all the
    # positions with their value.
    for i in range(2, MAX):
        factor[i] = i

    # Initializes all
    # multiples of 2 with 2
    for i in range(4, MAX, 2):
        factor[i] = 2

    # A modified version of
    # Sieve of Eratosthenes
    # to store the smallest
    # prime factor that divides
    # every number.
    i = 3
    while(i * i < MAX):
        # check if it has
        # no prime factor.
        if (factor[i] == i):
            # Initializes of j
            # starting from i*i
            j = i * i
            while(j < MAX):
                # if it has no prime factor
                # before, then stores the
                # smallest prime divisor
                if (factor[j] == j):
                    factor[j] = i
                j += i
        i += 1

# function to calculate
# number of factors


def calculateNoOFactors(n):
    if (n == 1):
        return 1
    ans = 1

    # stores the smallest
    # prime number that
    # divides n
    dup = factor[n]

    # stores the count of
    # number of times a
    # prime number divides n.
    c = 1

    # reduces to the next
    # number after prime
    # factorization of n
    j = int(n / factor[n])

    # false when prime
    # factorization is done
    while (j > 1):
        # if the same prime
        # number is dividing
        # n, then we increase
        # the count
        if (factor[j] == dup):
            c += 1

        # if its a new prime factor
        # that is factorizing n,
        # then we again set c=1 and
        # change dup to the new prime
        # factor, and apply the formula
        # explained above.
        else:
            dup = factor[j]
            ans = ans * (c + 1)
            c = 1

        # prime factorizes
        # a number
        j = int(j / factor[j])

    # for the last
    # prime factor
    ans = ans * (c + 1)

    return ans
# Driver Code


if __name__ == "__main__":

    # generate prime factors
    # of number upto 10^6
    generatePrimeFactors()
    # a = [10, 30, 100, 450, 987]
    # q = len(a)
    s=0
    for i in range(1, int(input())):
        s+=(calculateNoOFactors(i))
    print(s)

# This code is contributed
# by mits.
Buggy python submission (verdict: Runtime Error):
# Segment Treeを使う。一点更新，区間最大値

N, K = map(int, input().split())

seglen = 1 << 19

segtree = [0 for _ in range(seglen * 2)]
# segtree[seglen + i] = Bの最後の値に i を使う時のlongest len

def segset(ind, val):
    segtree[ind] = val
    ind //= 2
    while ind != 0:
        segtree[ind] = max(segtree[ind*2], segtree[ind*2 + 1])
        ind //= 2
    return


def segmax(l, r):
    ret = 0

    while l < r:

        if l % 2 == 1:
            ret = max(ret, segtree[l])
            l += 1
        l //= 2

        if r % 2 == 1:
            ret = max(ret, segtree[r - 1])
            r -= 1
        r //= 2

    return ret

A = []
for _ in range(N):
    a = int(input())
    a -= 1
    A.append(a)

ans = 0

for a in A:
    a_ind = seglen + a

    l = max(seglen, a_ind - K)
    r = min(seglen + 4000000, a_ind + K + 1)

    longest = segmax(l, r)

    segset(a_ind, longest + 1)

    ans = max(ans, longest + 1)

print(ans)

Fixed submission:
# Segment Treeを使う。一点更新，区間最大値

N, K = map(int, input().split())

seglen = 1 << 19

segtree = [0 for _ in range(seglen * 2)]
# segtree[seglen + i] = Bの最後の値に i を使う時のlongest len

def segset(ind, val):
    segtree[ind] = val
    ind //= 2
    while ind != 0:
        segtree[ind] = max(segtree[ind*2], segtree[ind*2 + 1])
        ind //= 2
    return


def segmax(l, r):
    ret = 0

    while l < r:

        if l % 2 == 1:
            ret = max(ret, segtree[l])
            l += 1
        l //= 2

        if r % 2 == 1:
            ret = max(ret, segtree[r - 1])
            r -= 1
        r //= 2

    return ret

A = []
for _ in range(N):
    a = int(input())
    A.append(a)

ans = 0

for a in A:
    a_ind = seglen + a

    l = max(seglen, a_ind - K)
    r = min(seglen + 400000, a_ind + K + 1)

    longest = segmax(l, r)

    segset(a_ind, longest + 1)

    ans = max(ans, longest + 1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
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]

print(ans % 1000000007)

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

S = sum(A)
S_2 = sum(map(lambda x: x*x, A))

ans = (S*S - S_2)//2 #切り捨て除算にしないと結果をfloatで返してきやがるので

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

Buggy python submission (verdict: Time Limit Exceeded):
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]

print(ans % 1000000007)

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

S = sum(A)
S_2 = sum(map(lambda x: x*x, A))

ans = (S*S - S_2)//2 #切り捨て除算にしないと結果をfloatで返してきやがるので

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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0

for i in range(0,N-1):
    for j in range(i+1, N):
        product = (A[i] * A[j])
        #print(product)
        ans += product
print(ans%(10**9 + 7))

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

S = sum(A)
S_2 = sum(map(lambda x: x*x, A))

ans = (S*S - S_2)//2 #切り捨て除算にしないと結果をfloatで返してきやがるので

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