Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors



n=int(input())


l=list(make_divisors(n))

l.sort()

for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
else:
  print(ans)


Fixed submission:
n=int(input())
import math
ans=10**12
i=0
while i*i<=n:
  i+=1
  if n%i!=0:
    continue
  j=n/i
  ans=min(ans, i+j-2)
if ans ==10**12:
  print(n-1)
else:
  print(int(ans))

Buggy python submission (verdict: Runtime Error):
def get_divisors(n):
    if n < 1:
        return
    i = 1
    while i * i <= n:
        if n % i == 0:
            yield i
            if i * i != n:
                yield round(n / i)
        i = i + 1



n=int(input())


l=list(get_divisors(n))

l.sort()

for i,ll in enumerate(l):
  if i!=len(l)-1 and ll*l[i+1]==n:
    ans=ll+l[i+1]-2
if n==1:
  print(0)
else:
  print(ans)





Fixed submission:
n=int(input())
import math
ans=10**12
i=0
while i*i<=n:
  i+=1
  if n%i!=0:
    continue
  j=n/i
  ans=min(ans, i+j-2)
if ans ==10**12:
  print(n-1)
else:
  print(int(ans))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int(input().split())))

ans=0

for hh in h:
  if hh>=k:
    ans+=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

ans=0

for hh in h:
  if hh>=k:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int(input().split()))

ans=0

for hh in h:
  if hh>=k:
    ans+=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

ans=0

for hh in h:
  if hh>=k:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map,int(input().split()))

ans=0

for hh in h:
  if hh>=k:
    ans+=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))

ans=0

for hh in h:
  if hh>=k:
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):


n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(1,n+1):
  print(a.index(i)+1 , end=' ')


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[x for x in range(n)]
for i in range(n):
  ans[(a[i] - 1)] = i + 1
for aaa in ans:
  print(aaa)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(1,n+1):
  ans.append(a.index(i)+1)

print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[x for x in range(n)]
for i in range(n):
  ans[(a[i] - 1)] = i + 1
for aaa in ans:
  print(aaa)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
c=a

a=sorted(a)
for ia in a:
  print(c.index(ia)+1, end=' ')

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[x for x in range(n)]
for i in range(n):
  ans[(a[i] - 1)] = i + 1
for aaa in ans:
  print(aaa)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
c=a

a=sorted(a3)
for ia in a:
  print(c.index(ia)+1, end='')

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[x for x in range(n)]
for i in range(n):
  ans[(a[i] - 1)] = i + 1
for aaa in ans:
  print(aaa)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=list(map(int,input().split()))
a=[]
for i in range(q):
  a.append(int(input()))
#p=[k for _ in range(n)]
w=q-k+1
for i in range(n):
  if a.count(i+1) >= w:
    print('Yes')
  else:
    print('No')


Fixed submission:
n,k,q=list(map(int,input().split()))
a=[0 for _ in range(n)]
for i in range(q):
  x=int(input())
  a[x-1] += 1
w=q-k+1
for i in range(n):
  if a[i] >= w:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=list(map(int,input().split()))
a=[]
for i in range(q):
  a.append(int(input()))
p=[k for _ in range(n)]
w=q-k+1
for i in range(n):
  if a.count(i+1) >= w:
    print('Yes')
  else:
    print('No')


Fixed submission:
n,k,q=list(map(int,input().split()))
a=[0 for _ in range(n)]
for i in range(q):
  x=int(input())
  a[x-1] += 1
w=q-k+1
for i in range(n):
  if a[i] >= w:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[]
for i in range(n):
  a=int(input())
  l.append(1/a)

print(1/sum(l))

Fixed submission:
n=int(input())
l=list(map(int,input().split()))

ll=[1/x for x in l]

print(1/sum(ll))

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[]
for i in range(n):
  a=int(input())
  l.append(1/a)

print(sum(l))

Fixed submission:
n=int(input())
l=list(map(int,input().split()))

ll=[1/x for x in l]

print(1/sum(ll))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

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

mul = int(reduce(lambda x, y: x * y, A[:K]))

res = [mul]

for i in range(K, N):
    res.append(res[-1]*A[i]//A[i-K])
    print('Yes' if res[-2] < res[-1] else 'No')


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

for i in range(K, N):
    print('Yes' if A[i-K] < A[i] else 'No')
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A <= B:
    print("NO")
    exit()



diff = max(A, B) - min(A, B)

speed = V - W

if diff / speed <= T:
    print("YES")
else:
    print("NO")

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V <= W:
    print("NO")
    exit()



diff = max(A, B) - min(A, B)

speed = V - W

if diff / speed <= T:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
N = int(input())
A = map(int, input().split())

mul = reduce(lambda x, y: x*y, A)

if mul > 10**18:
    print('-1')
else:
    print(mul)

Fixed submission:
from functools import reduce
from math import log10

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

mul = 1

for a in A:
    mul *= a
    if mul > 10**18:
        print('-1')
        break
else:
    print(mul)
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) : 
    for j in range(S + 1) : 
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod 
        if j + A[i] <= S : 
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= mod
print(dp[N][S])


Fixed submission:
N, S = map(int, input().split())
A = map(int, input().split())
 
def solve(length, target, nums):
  
  dp = [[0]*(target+1) for i in range(length+1)]
  dp[0][0] = 1
  for i, n in enumerate(nums):
    for j, comb_num in enumerate(dp[i]):
      sub = j - n
      dp[i + 1][j] += comb_num * 2
      #print(i, j, sub, dp[i])
      if sub >= 0:
        dp[i + 1][j] += dp[i][sub]
      dp[i + 1][j] %= 998244353
  #print(dp)
  print(dp[length][target])
  
solve(N, S, A)

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = map(int, input().split())
 
def solve(length, target, nums):
  
  dp = [[0]*(target+1) for i in range(length+1)]
  dp[0][0] = 1
  for i, n in enumerate(nums):
    for j, comb_num in enumerate(dp[i]):
      sub = j - n
      dp[i + 1][j] += comb_num * 2
      #print(i, j, sub, dp[i])
      if sub >= 0:
        dp[i + 1][j] += dp[i][sub]
      dp[i + 1][j] %= 998244353
  #print(dp)
  print(dp[length][target])
  
solve(N, S, A)

Fixed submission:
N, S = map(int, input().split())
A = map(int, input().split())
 
def solve(length, target, nums):
  
  dp = [[0]*(target+1) for i in range(length+1)]
  dp[0][0] = 1
  for i, n in enumerate(nums):
    for j, comb_num in enumerate(dp[i]):
      sub = j - n
      dp[i + 1][j] += comb_num * 2
      #print(i, j, sub, dp[i])
      if sub >= 0:
        dp[i + 1][j] += dp[i][sub]
      dp[i + 1][j] %= 998244353
  #print(dp)
  print(dp[length][target])
  
solve(N, S, A)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import deque
import heapq

def countposdoc(string):
    return string.count('D') + string.count('PD')

T = input()

queue = deque([T])

res = (0, '')
#heapq.heapify(res)

while queue:
    string = queue.pop()
    if '?' not in string:
        #heapq.heappush(res, (countposdoc(string), string))
        res = max(res, (countposdoc(string), string))
    else:
        queue.append(string.replace('?', 'P', 1))
        queue.append(string.replace('?', 'D', 1))
print(res[1])

Fixed submission:
T = input()

print(T.replace('?', 'D'))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import deque
import heapq

def countposdoc(string):
    return string.count('D') + string.count('PD')

T = input()

queue = deque([T])


res = []
heapq.heapify(res)

while queue:
    string = queue.pop()

    if '?' not in string:
        heapq.heappush(res, (countposdoc(string), string))
    else:
        queue.append(string.replace('?', 'P', 1))
        queue.append(string.replace('?', 'D', 1))
print(heapq.nlargest(1, res)[0][1])

Fixed submission:
T = input()

print(T.replace('?', 'D'))
Buggy python submission (verdict: Runtime Error):
from math import ceil
A, B = map(int, input())
print(ceil(B/A))

Fixed submission:
from math import ceil
A, B = map(int, input().split())
if B == 1:
    print(0)
else:
    print(int(ceil((B-1)/(A-1))))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
return max(A+B, max(A-B, A*B))

Fixed submission:
A, B = map(int, input().split())
print(max(A+B, max(A-B, A*B)))
Buggy python submission (verdict: Runtime Error):
K, X = input().split()
K, X = int(K), int(X)
print(' '.join([i for i in range(X-K+1, X+K)]))

Fixed submission:
K, X = map(int, input().strip().split())
print(' '.join([str(i) for i in range(X-K+1, X+K)]))

Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
print(' '.join([i for i in range(X-K+1, X+K)]))

Fixed submission:
K, X = map(int, input().strip().split())
print(' '.join([str(i) for i in range(X-K+1, X+K)]))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
for i in range(M):
    B, num = map(int, input().strip().split())
    for j in range(B):
        A[A.index(min(map(lambda x: x - num, nums))+num)] = max(num,x)
print(sum(A))

Fixed submission:
A, B = map(int, input().strip().split())
if A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B // 2)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().strip().split())
if A >= 13:
  return B
elif 6 <= A <= 12:
  return B // 2
else:
  return 0

Fixed submission:
A, B = map(int, input().strip().split())
if A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B // 2)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().aplit())
boolean = False
for i in range(N+1):
    for j in range(N+1-i):
        if (Y - 10000 * i + 5000 * j) // 1000 == (N - i - j):
            boolean = True
            break

if boolean:
    print(i, j, N - i - j)
else:
    print(-1, -1, -1)

Fixed submission:
N, Y = map(int, input().split())
boolean = False
for i in range(N+1):
    if boolean:
        break
    for j in range(N+1-i):
        if (Y - 10000 * i - 5000 * j) / 1000 == (N - i - j):
            boolean = True
            print(i, j, N - i - j)
            break

if not boolean:
    print(-1, -1, -1)

Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().aplit())
boolean = False
for i in range(N+1):
    for j in range(N+1-i):
        if (Y - 10000 * i + 5000 * j) // 1000 == (N - i - j):
            boolean = True

if boolean:
    print(i, j, N - i - j)
else:
    print(-1, -1, -1)

Fixed submission:
N, Y = map(int, input().split())
boolean = False
for i in range(N+1):
    if boolean:
        break
    for j in range(N+1-i):
        if (Y - 10000 * i - 5000 * j) / 1000 == (N - i - j):
            boolean = True
            print(i, j, N - i - j)
            break

if not boolean:
    print(-1, -1, -1)

Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().aplit())
boolean = False
for i in range(N+1):
    for j in range(N+1-i):
        if (Y - 10000 * i + 5000 * j) % 1000 == N:
            boolean = True

if boolean:
    print(i, j, N - i - j)
else:
    print(-1, -1, -1)

Fixed submission:
N, Y = map(int, input().split())
boolean = False
for i in range(N+1):
    if boolean:
        break
    for j in range(N+1-i):
        if (Y - 10000 * i - 5000 * j) / 1000 == (N - i - j):
            boolean = True
            print(i, j, N - i - j)
            break

if not boolean:
    print(-1, -1, -1)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                count += 1
print(count)

Fixed submission:
K, S = map(int, input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - i - j and S - i - j <= K:
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
S = int(input())

def dfs(res, depth, path, S):
    res.append(path)
    if depth == len(S) - 1:
        return
    for i in range(depth + 1, len(S)):
        dfs(res, i, int(S[depth:i+1]), S)

res = []

dfs(res, -1, [], S)
print(sum(res))


Fixed submission:
from functools import reduce
S = input()

def dfs(res, depth, path, S):
    if len(''.join(path)) == len(S):
        res.append(path)
    for i in range(depth + 1, len(S) + 1):
        dfs(res, i, path + [S[depth:i]], S)

res = []

dfs(res, 0, [], S)

print(sum(int(num) for nums in res for num in nums))
Buggy python submission (verdict: Time Limit Exceeded):
n,x,m=map(int,input().split())
A=[x]
ans=0
for i in range(min(n,m)):
  a_i=(A[i]**2)%m
  if i ==n-1:
    print(sum(A))
    exit()
  if a_i==0:
    print(sum(A))
    exit()
  if a_i in A:
    k=A.index(a_i)+1
    l=len(A)
    roop=A[k-1:l]
    many=(n-k+1)//(l-k+1)
    ans+=sum(A[:k-1])
    ans+=sum(roop)*many
    ans+=sum(roop[:(n-k+1)%(l-k+1)])
    print(ans)
    exit()
  A.append(a_i)

Fixed submission:
N, X, M = map(int, input().split())
flag = [False for _ in range(M)]
record = list()
record.append(X)
flag[X] = 1

An = X

for i in range(M + 1):
    An = pow(An, 2, M)
    if flag[An]:
        start = flag[An]
        cnt = i + 2 - start
        cost = record[-1] - record[start - 2] if start > 1 else record[-1]
        break

    else:
        record.append(An + record[-1])
        flag[An] = i + 2

if start >= N:
    print(record[N - 1])
else:
    print(((N - start) // cnt) * cost
                + record[(N - start) % cnt + start - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
list1=[]
ans=0
for i in range(n):
  ans+=(a[i]*sum(a[i+1:n]))%(10**9+7)
print(ans%(10**9+7))

Fixed submission:
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 python submission (verdict: Runtime Error):
x = int(input())
if x>=30:
  print(Yes)
else:
  print(No)

Fixed submission:
x = int(input())
if x>=30:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
list_score = [1]*(N-K+1)
for i in range(len(list_score)):
  for j in range(K):
    list_score[i] *=A[i+j]
    
for i in range(1, len(list_score)):
  if list_score[i] > list_score[i-1]:
    print('Yes')
  else:
    print('No')

Fixed submission:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
for i in range(N-K):
  if A[i] >= A[i+K]:
    print('No')
  else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%1000==0:
  print(0)
elif:
  print(1000-n%1000)

Fixed submission:
n=int(input())
if n%1000==0:
  print(0)
else:
  print(1000-n%1000)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ac=0
wa=0
tle=0
re=0
for i range(n):
  x = input()
  if x =='AC':
    ac+=1
  if x =='WA':
    wa+=1
  if x =='TLE':
    tle+=1
  if x =='RE':
    re+=1
    
print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))

Fixed submission:
n = int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  x = input()
  if x =='AC':
    ac+=1
  if x =='WA':
    wa+=1
  if x =='TLE':
    tle+=1
  if x =='RE':
    re+=1
    
print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))
Buggy python submission (verdict: Runtime Error):
def py():
  x, n = map(int, input().split())
  p = list(map(int, input().split()))
  if p == []:
    print(x)
    return
  list0=[]
  for i in range(1,101):
    list0.append(i)
  for j in p:
    list0.remove(j)
  list1=[]
  for i in list0:
    list1.append(abs(x-i))
  if x-min(list1) in list0:
    print(x-min(list1))
  else:
    print(x+min(list1))
    
py()
  

Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))

for i in range(100):
    if not((x - i) in p):
        print (x - i)
        exit ()
    elif not((x + i) in p):
        print (x + i)
        exit()
Buggy python submission (verdict: Runtime Error):
def pyn():
	n = int(input())
	a = list(map(int, input().split()))
    if 0 in a:
      print(0)
      return
    
	ans=1
	for i in a:
 	 	ans *= i
		if ans>10**18:
  			print(-1)
            return
	print(ans)


Fixed submission:
def pyn():
  n = int(input())
  a = list(map(int, input().split()))
  if 0 in a:
    print(0)
    return
    
  ans=1
  for i in a:
    ans *= i
    if ans>10**18:
      print(-1)
      return
  print(ans)

pyn()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans=1
for i in a:
  ans *= i
if ans>10**18:
  ans=-1
print(ans)


Fixed submission:
def pyn():
  n = int(input())
  a = list(map(int, input().split()))
  if 0 in a:
    print(0)
    return
    
  ans=1
  for i in a:
    ans *= i
    if ans>10**18:
      print(-1)
      return
  print(ans)

pyn()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int, input().split()))
for i in range(1,n+1):
  print(a.count(i))

Fixed submission:
n=int(input())
a=list(map(int, input().split()))
b= [0]*n
for i in a:
  b[i-1]+=1
for i in b:
  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
while n >abs(k-n):
  n= abs(k-n)
print(n)

Fixed submission:
n, k = map(int, input().split())
if n>k:
  n= n-(n//k)*k
while n >abs(k-n):
  n= abs(k-n)
print(n)
Buggy python submission (verdict: Runtime Error):
n= int(input())
x= list(map(int,input().split()))
m= mean(x)
g= int(m)
if m-g<g+1-m:
  print(g)
else:
  print(g+1)
  

Fixed submission:
n= int(input())
x= list(map(int,input().split()))
m= sum(x)/len(x)
g= int(m)
ans=0
if m-g<g+1-m:
  ans=g
else:
  ans=g+1
aaa=0
for i in x:
  aaa+= (ans-i)**2
print(aaa)
Buggy python submission (verdict: Runtime Error):
import math
x = int(input())
ans =x
while True:
  for i in range(2,math.sqrt(x)+1):
    if x%i=0:
      print(x)
      exit()
  x+=1
  


Fixed submission:
import math
x = int(input())
ans =x

for j in range(x,2*x):
  flag=1
  for i in range(2,int(math.sqrt(x))+1):
    if x%i==0:
      flag=0
  if flag==1:
    print(x)
    exit(0)
  x+=1
Buggy python submission (verdict: Time Limit Exceeded):
n,m =map(int,input().split())
a=[1]*n
b=[0]*n
for i in range(m):
  l,r=map(int,input().split())
  if l==1:
    a[r:]=b[r:]
  else:
    a[:l-1]=b[:l-1]
    a[r:]=b[r:]
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
l,r=1,n
for i in range(m):
    L,R=map(int,input().split())
    l=max(l,L)
    r=min(r,R)
if l>r:
    print(0)
else:   
    print(r-l+1)
Buggy python submission (verdict: Runtime Error):
S= input()
count=0
if S[0]!='A':
  print('WA')
  return
S.lower(0)
for i in range(3,len(S)-1):
  if S[i]=='C':
    count+=1
    S.lower(i)
if count==1 && S.islower():
  print('AC')

Fixed submission:
s = input()
flag = False

if s[0]=="A":
	if s[2:-1].count("C")==1:
		if (s[1:s.index("C")].islower() and s[s.index("C")+1:].islower()):
			flag = True
print("AC" if flag else "WA")
Buggy python submission (verdict: Runtime Error):
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 submission:
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 python submission (verdict: Runtime Error):
from sympy import sieve

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

ans = 0

if len(A) > 2:
    for i in range(len(A)):
        if A[i] in sieve:
            ans += 1
            continue
        for j in range(i+1):
            if A[i] % A[j] == 0:
                if j != i:
                    break
        else:
            ans += 1

print(ans)

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

dp = [True]*(A[-1]+1)

ans = 0

for i in range(len(A)):
    if dp[A[i]]:
        if (i == len(A)-1) or (A[i] != A[i+1]):
            ans += 1
    try:
        k = 1
        while(True):
            dp[k*A[i]] = False
            k += 1
    except:
        pass

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(set(map(int, input().split()))))

ans = 0

if len(A) > 2:
    for i in range(N):
        for j in range(i):
            if j == i:
                continue
            if A[i] % A[j] == 0:
                break
        else:
            ans += 1

print(ans)

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

dp = [True]*(A[-1]+1)

ans = 0

for i in range(len(A)):
    if dp[A[i]]:
        if (i == len(A)-1) or (A[i] != A[i+1]):
            ans += 1
    try:
        k = 1
        while(True):
            dp[k*A[i]] = False
            k += 1
    except:
        pass

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):
    for j in range(N):
        if j == i:
            continue
        if A[i] % A[j] == 0:
            break
    else:
        ans += 1

print(ans)

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

dp = [True]*(A[-1]+1)

ans = 0

for i in range(len(A)):
    if dp[A[i]]:
        if (i == len(A)-1) or (A[i] != A[i+1]):
            ans += 1
    try:
        k = 1
        while(True):
            dp[k*A[i]] = False
            k += 1
    except:
        pass

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

E = [0]*N
W = [0]*N

for i in range(N):
    if S[i] == "E":
        E[i] = 1
    else:
        W[i] = 1

min = N

for i in range(N):
    S = sum(W[0:i])+sum(E[i+1:N])
    if S < min:
        min = S
    
print(min)

Fixed submission:
N = int(input())
S = input()

E = [0]*(N+1)
W = [0]*(N+1)

for i in range(N):
    if S[i] == "E":
        E[i+1] = E[i] + 1
        W[i+1] = W[i]
    else:
        E[i+1] = E[i]
        W[i+1] = W[i] + 1

min = N

for i in range(N):
    S = W[i]-W[0] + E[N]-E[i+1]
    if S < min:
        min = S
    
print(min)