Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
a = list(map(int,input().split()))
l = []
i=0
while (a[i]-1) not in l:
    l.append(i)
    i = a[i]-1 
l.append(i)

pre = l.index(a[i]-1)  
loop = len(l)-pre
if pre+loop<k:
    k=(k-pre)%loop+pre
print(l[k]+1)

Fixed submission:
n, k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*n
i=0
cnt=0
while l[i]==0:
    l[i] = a[i]
    i = a[i]-1 
    cnt += 1
start = i+1
i = 0
pre = 0
while i+1!=start:
    i = a[i]-1
    pre += 1
loop = cnt-pre
if pre+loop<k:
    k=(k-pre)%loop+pre
i = 0
for _ in range(k):
    i = a[i]-1
print(i+1)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
a = list(map(int,input().split()))
l = []
i=0
while (a[i]-1) not in l:
    l.append(i)
    i = a[i]-1 
l.append(i)

pre = l.index(a[i]-1)  
loop = len(l)-pre
if pre+loop<k:
    k=(k-pre)%loop+pre
i = 0
for _ in range(k):
    i = a[i]-1
print(i+1)

Fixed submission:
n, k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*n
i=0
cnt=0
while l[i]==0:
    l[i] = a[i]
    i = a[i]-1 
    cnt += 1
start = i+1
i = 0
pre = 0
while i+1!=start:
    i = a[i]-1
    pre += 1
loop = cnt-pre
if pre+loop<k:
    k=(k-pre)%loop+pre
i = 0
for _ in range(k):
    i = a[i]-1
print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
d=dict(zip(set(A), [0]*len(set(A))))
ans=0
for i in set(A):
    d[i]=A.count(i)
    ans+=d[i]*(d[i]-1)//2
for a in A:
    num = d[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Fixed submission:
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Buggy python submission (verdict: Runtime Error):
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in set(A):
    d[i]=A.count(i)
    ans+=d[i]*(d[i]-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Fixed submission:
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Buggy python submission (verdict: Time Limit Exceeded):
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
d=dict(zip(set(A), [0]*len(set(A))))
ans=0
for i in set(A):
    d[i]=A.count(i)
    ans+=d[i]*(d[i]-1)//2
for j in range(N):
    num = d[A[j]]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Fixed submission:
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Buggy python submission (verdict: Time Limit Exceeded):
def comb(n):
    if n<=1:return 0
    r=1
    for i in range(n,n-2,-1):
       r*=i
    return r//2
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
d=dict(zip(set(A), [0]*len(set(A))))
for i in set(A):
    d[i]=A.count(i)
for j in range(N):
    ans=0
    for k, v in d.items():
        if A[j]==k:
            ans+=comb(v-1)
        else:
            ans+=comb(v)
    print(ans)

Fixed submission:
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Buggy python submission (verdict: Time Limit Exceeded):
def comb(n):
    if n==1:return 0
    r=1
    for i in range(n,n-2,-1):
       r*=i
    return r//2
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
ans=[0]*N
for i in range(N):
    A=list(map(int,stdin[1].split()))
    A.pop(i)
    for j in set(A):
        ans[i]+=comb(A.count(j))
    print(ans[i])

Fixed submission:
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)
Buggy python submission (verdict: Time Limit Exceeded):
S = input().rstrip()
Q = int(input().rstrip())
a = -1
for _ in range(Q):
    stdin = input().rstrip()
    if int(stdin[0]) == 1:
        a = ~a
    else:
        T,F,C = stdin.split()
        if int(F) == 2+a:
            S = C + S
        else:
            S = S + C
if a == 0:
    S = S[::-1]
print(S)

Fixed submission:
S = input().rstrip()
Q = int(input().rstrip())
a = -1
before =[]
after =[]
for _ in range(Q):
    stdin = input().rstrip()
    if int(stdin[0]) == 1:
        a = ~a
    else:
        T,F,C = stdin.split()
        if int(F) == 2+a:
            before.append(C)
        else:
            after.append(C)
S = ''.join(before)[::-1] + S + ''.join(after)
if a == 0:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input().rstrip()
Q = int(input().rstrip())
for _ in range(Q):
    stdin = input().rstrip()
    if int(stdin[0]) == 1:
        S = S[::-1]
    else:
        T,F,C = stdin.split()
        if int(F) == 1:
            S = C + S
        else:
            S = S + C
print(S)

Fixed submission:
S = input().rstrip()
Q = int(input().rstrip())
a = -1
before =[]
after =[]
for _ in range(Q):
    stdin = input().rstrip()
    if int(stdin[0]) == 1:
        a = ~a
    else:
        T,F,C = stdin.split()
        if int(F) == 2+a:
            before.append(C)
        else:
            after.append(C)
S = ''.join(before)[::-1] + S + ''.join(after)
if a == 0:
    S = S[::-1]
print(S)
Buggy python submission (verdict: Runtime Error):
stdin = open(0).read().split('\n')
N, M = map(int,stdin[0].split())
if N==0:
    list=['0']
    for j in range(M):
        s, c = stdin[j+1].split()
        if list[int(s)-1]!=c:flag=False
    if flag:
        print(i)
        exit()
else:
    for i in range(10**(N-1),10**N):
        list=[str(i)]
        flag=True
        for j in range(M):
            s, c = stdin[j+1].split()
            if list[int(s)-1]!=c:flag=False
        if flag:
            print(i)
            exit()
print(-1)   

Fixed submission:
stdin = open(0).read().split('\n')
N, M = map(int,stdin[0].split())
if M ==0:
    num=['0']*N
    if N!=1:
        num[0]='1'
    ans = "".join(num)
    print(int(ans))
else:
    num=['a']*N
    flag = True
    for i in range(M):
        s, c = stdin[i+1].split()
        if N!=1 and s=='1' and c=='0':
            flag = False
            break            
        elif not num[int(s)-1].isdecimal():
            num[int(s)-1]=c
        elif num[int(s)-1]!=c:
            flag = False
            break
    if num[0]=='a':num[0]='1'
    ans = "".join(num).replace('a', '0')
    print(int(ans) if (ans[0]!='0' or N==1) and flag else -1)
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int,input().rstrip().split())
fac = [1]
for i in range(1,n+1):
    fac.append(fac[i-1]*i)
ans = 0
for i in [i for i in range(1,n+1) if (i!=a) if (i!=b)]:
    ans += fac[n]//fac[i]//fac[n-i]
print(ans)

Fixed submission:
MOD = 1_000_000_007
def calc_combi(n,k):
    frac=1
    denomi=1
    for i in range(n-k+1,n+1):
        frac=frac*i%MOD
    for i in range(1,k+1):
        denomi=denomi*i%MOD
    return frac*pow(denomi,MOD-2,MOD)

n, a, b = map(int,input().rstrip().split())
nca = calc_combi(n,a)
ncb = calc_combi(n,b)
print((pow(2,n,MOD)-1-nca-ncb)%MOD)
Buggy python submission (verdict: Runtime Error):
stdin = open(0).read().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
print('Yes' if len(A)==len(B) else'No')

Fixed submission:
stdin = open(0).read().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
B = set(A)
print('YES' if len(A)==len(B) else 'NO')
Buggy python submission (verdict: Runtime Error):
A, B = map(int,open(0).read().split('\n'))
if A!=1 and B!=1:
    print(1)
elif A!=2 and B!=2:
    print(2)
else:
    print(3)

Fixed submission:
A=int(input())
B=int(input())
if A!=1 and B!=1:
    print(1)
elif A!=2 and B!=2:
    print(2)
else:
    print(3)

Buggy python submission (verdict: Runtime Error):
A, B = map(int,open(0).read().split('\n'))
if A!=1 and B!=1:
    print(1)
elif A!=2 and B!=2:
    print(2)
else:
    print(3)

Fixed submission:
A=int(input())
B=int(input())
if A!=1 and B!=1:
    print(1)
elif A!=2 and B!=2:
    print(2)
else:
    print(3)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int,input().split())
for i in range(max(A,B),1000000001):
    if i%A==0 and i%B==0:
        print(i)
        break

Fixed submission:
A, B = map(int,input().split())
for i in range(max(A,B),0,-1):
    if A%i==0 and B%i==0:
        print(A*B//i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
tmp = [0]*61
MOD = 1_000_000_007
for i in range(n):
    for j in range(61):
        mask = 1<<j
        if a[i]&mask>0:
            tmp[j]+=1
ans = 0
for i in range(61):
    mask = 1<<i
    ans = (ans + mask*tmp[i]*(n-tmp[i])) % MOD
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
tmp = [0]*61
MOD = 1_000_000_007
for i in range(n):
    for j in range(61):
        mask = 1<<j
        if a[i]&mask>0:
            tmp[j]+=1
ans = 0
for i in range(61):
    mask = 1<<i
    ans = (ans + mask*tmp[i]*(n-tmp[i])) % MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0
MOD = 1_000_000_007
for i in range(n-1):
    for j in range(i+1,n):
        ans = (ans + (a[i]^a[j])) % MOD
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
tmp = [0]*61
MOD = 1_000_000_007
for i in range(n):
    for j in range(61):
        mask = 1<<j
        if a[i]&mask>0:
            tmp[j]+=1
ans = 0
for i in range(61):
    mask = 1<<i
    ans = (ans + mask*tmp[i]*(n-tmp[i])) % MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
ans =[0]*N
for i in range(N):
    ans[i] = A.index(i+1)+1
print(' '.join(map(str,ans)))

Fixed submission:
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
ans =[0]*N
for i in range(N):
     ans[A[i]-1] = i+1
print(' '.join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)

n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]

g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)

ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)

n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]

g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)

ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
ans = 0
for i in range(N):
    a = list(s[i][:])
    a.sort()
    for j in range(i+1,N):
        b = list(s[j][:])
        b.sort()
        if ''.join(a)==''.join(b):ans+=1
print(ans)

Fixed submission:
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
d = {}
for i in range(N):
    a = list(s[i][:])
    b = ''.join(sorted(a))
    if b in d:
        d[b]+=1
    else:
        d[b]=1
ans = 0
for j in d.values():
    ans+=j*(j-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def dictstr(s):
    d = {}
    for i in range(10):
        if s[i] in d:
            d[s[i]] += 1
        else:
            d[s[i]] = 1
    return d

stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        d = dictstr(s[i])
        flag = True
        for k in range(10):
            if s[j][k] in d:
                d[s[j][k]] -= 1
                if d[s[j][k]]<0:
                    flag = False
                    break
            else:
                flag = False
                break
        if flag:ans+=1
print(ans)

Fixed submission:
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
d = {}
for i in range(N):
    a = list(s[i][:])
    b = ''.join(sorted(a))
    if b in d:
        d[b]+=1
    else:
        d[b]=1
ans = 0
for j in d.values():
    ans+=j*(j-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int,input().rstrip().split())
ans = 2019
for i in range(L,R):
    for j in range(i+1,R+1):
        if (i*j)%2019<ans:
            ans=(i*j)%2019
print(ans)

Fixed submission:
L, R = map(int,input().rstrip().split())
if R - L >=2018:
    ans = 0
else:
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            if (i*j)%2019<ans:
                ans=(i*j)%2019
print(ans)
Buggy python submission (verdict: Runtime Error):
d = {0:1, 1:1, 2:2}
def countcombi(n):
    if n in d:
        return d[n]
    else:
        d[n] = countcombi(n-1)+countcombi(n-2)
        return d[n]
N, M = list(map(int,input().rstrip().split()))
a_now = 0
a_before = 0
ans = 1
for _ in range(M):
    a_now = int(input().rstrip())
    if a_now-a_before == 0 and a_before != 0:
        print(0)
        break
    ans = (ans * countcombi(a_now-a_before-1)) % 1_000_000_007
    a_before = a_now + 1
else:
    a_now = N
    ans = (ans * countcombi(a_now-a_before)) % 1_000_000_007
    print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
d = {0:1, 1:1, 2:2}
def countcombi(n):
    if n in d:
        return d[n]
    else:
        d[n] = countcombi(n-1)+countcombi(n-2)
        return d[n]
N, M = list(map(int,input().rstrip().split()))
a_now = 0
a_before = 0
ans = 1
for _ in range(M):
    a_now = int(input().rstrip())
    if a_now-a_before == 0 and a_before != 0:
        print(0)
        break
    ans = (ans * countcombi(a_now-a_before-1)) % 1_000_000_007
    a_before = a_now + 1
else:
    a_now = N
    ans = (ans * countcombi(a_now-a_before)) % 1_000_000_007
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int,input().rstrip().split()))
ans = 0
for i in range(1,N+1):
    p = 1/N
    if j<K:
        while i<K:
            i *= 2
            p *= 0.5
    ans += p
print(ans)

Fixed submission:
N, K = list(map(int,input().rstrip().split()))
ans = 0
for i in range(1,N+1):
    p = 1/N
    if i<K:
        while i<K:
            i *= 2
            p *= 0.5
    ans += p
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*(N-1)
for i in range(N-1):
    if S[i]=='A' and S[i+1] == 'C':
        a[i] = 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(sum(a[l-1:r-1]))

Fixed submission:
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    ans = 0
    for i in range(l-1,r-1):
        if S[i]=='A' and S[i+1] == 'C':
            ans += 1
    print(ans)

Fixed submission:
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
ans = 0
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(S[l-1:r].count('AC'))

Fixed submission:
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
j=0
for i in range(N):
  D1,D2=map(int,input().split())
  if D1==D2:
    j+=1
    if j>=3:
      J=3
  else:
    j=0
if J>=3:
  print('Yes')
else:
  print('No')

Fixed submission:
N=int(input())
j=0
J=0
for i in range(N):
  D1,D2=map(int,input().split())
  if D1==D2:
    j+=1
    if j>=3:
      J=3
  else:
    j=0
if J>=3:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
lst=list(map(int,input().split()))
A=0
for i in range(N-1):
  for j in range(i+1,N):
    A+=(lst[i]%(10**9+7))*(lst[j]%(10**9+7))
print(A%(10**9+7))

Fixed submission:
D,T,S=map(int,input().split())
if D<=T*S:
  print('Yes')
elif D>T*S:
  print('No')

Buggy python submission (verdict: Runtime Error):
N=int(input())
lst=list(map(int,input().split()))
A=0
for i in range(N-1):
  for j in range(i+1,N):
    A+=(lst[i]%(10**9+7))*(lst[j]%(10**9+7))
print(A%(10**9+7))

Fixed submission:
D,T,S=map(int,input().split())
if D<=T*S:
  print('Yes')
elif D>T*S:
  print('No')

Buggy python submission (verdict: Runtime Error):
D=int(input())
T=int(input())
S=int(input())
if D<=T*S:
  print('Yes')
elif D>T*S:
  print('No')

Fixed submission:
D,T,S=map(int,input().split())
if D<=T*S:
  print('Yes')
elif D>T*S:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
mod = 10**9+7
print ((pow(10,N,mod) - 2*pow(9,N,mod) + pow(8,N,mod)) % mod)

Fixed submission:
N = int(input())
mod = 10**9+7
print ((pow(10,N,mod) - 2*pow(9,N,mod) + pow(8,N,mod)) % mod)
Buggy python submission (verdict: Runtime Error):
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 submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
A = list(map(int, input().split()))
sm=0
mod=10**9+7
for i in itertools.combinations(A,2):
    sm+=(i[0]*i[1])%mod
    sm%=mod

print(sm)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
A = list(map(int, input().split()))
sm=0
mod=10**9+7
for i in itertools.combinations(A,2):
    sm+=i[0]*i[1]
    sm%=mod

print(sm)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
A = list(map(int, input().split()))
sm=0
mod=10**9+7
for i in itertools.combinations(A,2):
    sm+=i[0]*i[1]
    sm%=mod

print(sm)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
A = list(map(int, input().split()))
sm=0
mod=10**9+7
for i in itertools.combinations(A,2):
    sm+=(i[0]*i[1])%mod
    sm%=mod

print(sm)

Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
N = int(input())
a=0
flag=0
for i in range(1,N+1):
    a=(a*10)+7
    p=a%N
    if p==0:
        print(i)
        flag=1
        break

if flag==0:
    print(-1)


Fixed submission:
N = int(input())
a=0
flag=0
for i in range(1,N+1):
    a=(a*10+7)%N   
    if a==0:
        print(i)
        flag=1
        break

if flag==0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a=0
flag=0
for i in range(1,N+1):
    a+=(7*10**(i-1))%N
    if a>N:
        a-=N
    if a==N:
        a=0
    if a==0:
        print(i)
        flag=1
        break
if flag==0:
    print(-1)

Fixed submission:
N = int(input())
a=0
flag=0
for i in range(1,N+1):
    a=(a*10+7)%N   
    if a==0:
        print(i)
        flag=1
        break

if flag==0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a=0
flag=0
for i in range(1,10**6):
    a+=7*10**(i-1)
    if a%N==0:
        print(i)
        flag=1
        break
if flag==0:
    print(-1)

Fixed submission:
N = int(input())
a=0
flag=0
for i in range(1,N+1):
    a=(a*10+7)%N   
    if a==0:
        print(i)
        flag=1
        break

if flag==0:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = input()
S=[]
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            a=[s[i],s[j],s[k]]
            if a not in S:
                S.append(a)
print(len(S))

Fixed submission:
N = int(input())
s = input()
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a=s.find(str(i))
            if a==-1:
                continue
            b=s[a+1:].find(str(j))
            if b==-1:
                continue
            b+=a+1
            c=s[b+1:].find(str(k))
            if c==-1:
                continue
            cnt+=1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = input()
S=[]
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            a=[s[i],s[j],s[k]]
            if a not in S:
                S.append(a)
print(len(S))

Fixed submission:
N = int(input())
s = input()
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a=s.find(str(i))
            if a==-1:
                continue
            b=s[a+1:].find(str(j))
            if b==-1:
                continue
            b+=a+1
            c=s[b+1:].find(str(k))
            if c==-1:
                continue
            cnt+=1

print(cnt)