Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
if n == 1:
    for _ in range(m):
        a[0] //= 2
    print(a[0])
else:
    while m > 0:
        for i in range(0,n-1):
            if a[i] < a[i+1]:
                tmp = a[i]
                a[i] = a[i+1]
                a[i+1] = tmp
            else:
                break
        while a[0] >= a[1] and m > 0:
            a[0] //= 2
            m -= 1
    print(sum(a))


Fixed submission:
import heapq
n,m = map(int,input().split())
a = list(map(lambda x:int(x)*(-1),input().split()))

heapq.heapify(a)
for _ in range(m):
    val = heapq.heappop(a) * (-1)
    heapq.heappush(a, (val // 2) * (-1))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(m):
    buy = max(a)
    a.remove(buy)
    a.append(int(buy/2))
print(sum(a))


Fixed submission:
import heapq
n,m = map(int,input().split())
a = list(map(lambda x:int(x)*(-1),input().split()))

heapq.heapify(a)
for _ in range(m):
    val = heapq.heappop(a) * (-1)
    heapq.heappush(a, (val // 2) * (-1))
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

def add(idx, val):
    global nodes
    addnodes = [idx]
    while len(addnodes) > 0:
        n = addnodes.pop()
        nodes[n][1] += val
        for i in nodes[n][0]:
            addnodes.append(i)


for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    add(p-1, q)
op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)


Fixed submission:
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    nodes[p-1][1] += q

search_node = [0]

while len(search_node) > 0:
    n = search_node.pop()
    for i in nodes[n][0]:
        nodes[i][1] += nodes[n][1]
        search_node.append(i)


op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)

Buggy python submission (verdict: Runtime Error):
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

def add(idx, val):
    global nodes
    nodes[idx][1] += val
    for n in nodes[idx][0]:
        add(n, val)

for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    add(p-1, q)
op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)


Fixed submission:
n, q = map(int,input().split())
nodes = [[[], 0] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    nodes[a-1][0].append(b-1)
for _ in range(q):
    p, q = map(int, input().split())
    nodes[p-1][1] += q

search_node = [0]

while len(search_node) > 0:
    n = search_node.pop()
    for i in nodes[n][0]:
        nodes[i][1] += nodes[n][1]
        search_node.append(i)


op = str(nodes[0][1])
for n in range(1, len(nodes)):
    op += " {}".format(nodes[n][1])
print(op)
Buggy python submission (verdict: Runtime Error):
n, a = input(), input()
print(" ".join(["0"]*n))

Fixed submission:
from collections import deque
n = int(input())
a = list(input().split())

ball = []
for i in range(n, 0, -1):
    c = 2
    while i * c <= n:
        if a[i*c-1] == "1":
            a[i-1] = "1" if a[i-1] == "0" else "0"
        c += 1
    if a[i-1] == "1":
        ball.append(str(i))

print(len(ball))
if ball != []: print(" ".join(ball))
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())
a -= 1
e = lcm(c,d)
print(b-a-b//c-b//d+b//e+a//c+a//d-a//e)

Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x,y)
a,b,c,d = map(int,input().split())
a -= 1
e = lcm(c,d)
print(b-a-b//c-b//d+b//e+a//c+a//d-a//e)
Buggy python submission (verdict: Runtime Error):
s = input()
p = int(s[:2])
a = int(s[2:])

if 0 < p < 13 and 0 < a < 13:
    print("AMBIGUOUS")
elif 0 < p < 13 and 0 < a < 100:
    print("MMYY")
elif 0 < p < 100 and 0 < a < 13:
    print("YYMM")
else p == 0 or a == 0 or p > 12 and a > 12:
    print("NA")

Fixed submission:
s = input()
p = int(s[:2])
a = int(s[2:])

if 0 < p < 13 and 0 < a < 13:
    print("AMBIGUOUS")
elif 0 < p < 13 and 0 <= a < 100:
    print("MMYY")
elif 0 <= p < 100 and 0 < a < 13:
    print("YYMM")
else:
    print("NA")
Buggy python submission (verdict: Runtime Error):
import math, decimal

memo = [1,2,4,8,16,32,64,128,256,512,1024,2048]
def twopow(f):
    if len(memo) < f:
        return memo[f]
    else:
        repeat = f - len(memo) + 1
        for _ in range(repeat):
            memo.append(memo[len(memo)-1]*2)
        return memo[f]

n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    x = math.ceil(math.sqrt(k/i)) if k > i else 0
    per += 1/twopow(x)

print(per/n)

Fixed submission:
n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    # x = math.ceil(math.sqrt(k/i)) if k > i else 0
    x = 0
    t = i
    while t < k:
        t *= 2
        x += 1
    # per += float("{:.20g}".format(1/(2**x)))
    per += 2**-x

print(per/n)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
flag = []
for _ in range(m): flag.append(True)
for _ in range(n):
    line = list(map(int, input()))
    for i in range(line[0]): flag[line[i+1]] = False
count = 0
for j in range(m):
    if(flag[j]): count += 1
print(count)

Fixed submission:
n, m = map(int, input().split())
flag = []
for _ in range(m): flag.append(0)
for _ in range(n):
    line = list(map(int, input().split()))
    for i in range(line[0]): flag[line[i+1]-1] += 1
count = 0
for j in range(m):
    if(flag[j] == n): count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())

lis = []

for _ in range(n):
    lis.append(int(input())

lis.sort()

min = 10**10
for i in range(len(lis)-k+1):
    dist = lis[i+k-1] - lis[i]
    if min > dist: min = dist
print(min)


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

lis = []

for _ in range(n):
    lis.append(int(input()))

lis.sort()

min = 10**10
for i in range(len(lis)-k+1):
    dist = lis[i+k-1] - lis[i]
    if min > dist: min = dist
print(min)
Buggy python submission (verdict: Runtime Error):
def f(n, x):
    if n >= 0: return n//x+1
    else: return 0

a,b,x = map(int, input().split())
print(f(b,x)-f(a-1,x))


Fixed submission:
N = int(input())
lis = []
lstipt = []
cnt = 0
h = 0
while h == 0:
    x, y, h = map(int, input().split())
    if h == 0:
        lstipt.append([x,y,h])
    cnt += 1

for Cx in range(101):
    for Cy in range(101):
        Ph = abs(x-Cx) + abs(y-Cy) + h
        lis.append([Cx,Cy,Ph])

for _ in range(N-cnt):
    x, y, h = map(int, input().split())
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

for ipt in lstipt:
    x, y, h = ipt[0], ipt[1], ipt[2]
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

print(" ".join(map(str,lis[0])))
Buggy python submission (verdict: Time Limit Exceeded):
sent1 = input()
sent2 = input()

l = len(sent1)

for i in range(l-1):
    for j in range(i,l):
        if sent1[i] == sent1[j] and sent2[i] != sent2[j] or sent1[i] != sent1[j] and sent2[i] == sent2[j]:
            print("No")
            exit(0)
print("Yes")

Fixed submission:
s = input()
t = input()

s2 = []
t2 = []

sdic = {}
tdic = {}

cnt = 0
for c in s:
    if c in sdic:
        s2.append(sdic[c])
    else:
        s2.append(cnt)
        sdic[c] = cnt
        cnt += 1

cnt = 0
for c in t:
    if c in tdic:
        t2.append(tdic[c])
    else:
        t2.append(cnt)
        tdic[c] = cnt
        cnt += 1

print("Yes" if s2 == t2 else "No")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]
v = 0
if n * n / 2 > m:
    mod = [0] * m
    for i in range(len(a)):
        v += a[i]
        mod[v%m] += 1
    ans = mod[0]
    for i in range(m):
        ans += mod[i] * (mod[i]-1) / 2
    print(int(ans))
else:
    ans = 0
    for i in range(len(a)):
        v += a[i]
        t.append(v)
    for i in range(len(t)-1):
        for j in range(i+1, len(t)):
            if (t[j]-t[i]) % m == 0:
                ans += 1
    print(ans)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]
v = 0
b = {0:1}
for i in range(n):
    v = (v + a[i]) % m
    if v in b.keys():
        b[v] += 1
    else:
        b[v] = 1
ans = 0
for i in b.values():
    ans += i * (i-1) / 2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]
v = 0
if n > m:
    mod = [0] * m
    for i in range(len(a)):
        v += a[i]
        mod[v%m] += 1
    ans = mod[0]
    for i in range(m):
        ans += mod[i] * (mod[i]-1) / 2
    print(int(ans))
else:
    ans = 0
    for i in range(len(a)):
        v += a[i]
        t.append(v)
    for i in range(len(t)-1):
        for j in range(i+1, len(t)):
            if (t[j]-t[i]) % m == 0:
                ans += 1
    print(ans)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]
v = 0
b = {0:1}
for i in range(n):
    v = (v + a[i]) % m
    if v in b.keys():
        b[v] += 1
    else:
        b[v] = 1
ans = 0
for i in b.values():
    ans += i * (i-1) / 2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]
ans = 0
v = 0
for i in range(len(a)):
    v += a[i]
    t.append(v)
for i in range(len(t)-1):
    for j in range(i+1, len(t)):
        if (t[j]-t[i]) % m == 0:
            ans += 1
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
t = [0]
v = 0
b = {0:1}
for i in range(n):
    v = (v + a[i]) % m
    if v in b.keys():
        b[v] += 1
    else:
        b[v] = 1
ans = 0
for i in b.values():
    ans += i * (i-1) / 2
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
def sadden_value(a, b):
    total = 0
    for i in range(0, len(a)):
        total += abs(a[i]-b-i-1)
    return total

n = int(input())
a = list(map(int, input().split()))
b = 1 - n
now = sadden_value(a, b)
while True:
    nex = sadden_value(a, b + 1)
    if now <= nex:
        print(now)
        break
    now = nex
    b += 1


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
tmp = [a[x] - (x+1) for x in range(0,n)]
tmp.sort()
b = tmp[n // 2]
print(sum((abs(tmp[i] - b) for i in range(0,n))))
Buggy python submission (verdict: Runtime Error):
money = int(input())
six = 1
nine = 1
now = 1
kingaku = [1]
while money > now:
    if pow(6,six) < pow(9,nine):
        now = pow(6,six)
        six += 1
    else:
        now = pow(9,nine)
        nine += 1
    kingaku.append(now)
kingaku.pop()
count = 0
def check(money, lis, idx, count):
    m = lis[idx]
    if money < 0:
        return 1000000
    if idx < 0:
        return count
    if idx == 0:
        return count + money
    if money < m:
        return check(money, lis, idx-1, count)
    sho = money // m
    mini = 1000000
    for i in range(sho + 1):
        value = check(money-m*i, lis, idx-1, count+i)
        if value < mini:
            mini = value
    return mini
print(check(money, kingaku, len(kingaku)-1, 0))

Fixed submission:
n = int(input())

r = n

for i in range(n+1):
    cnt = 0
    nine = n - i
    while i > 0:
        cnt += i % 6
        i = i // 6
    while nine > 0:
        cnt += nine % 9
        nine = nine // 9
    if r > cnt: r = cnt

print(r)
Buggy python submission (verdict: Runtime Error):
i = int(input())
l = list(map(int,input().split()))
print("Four" if l.count("Y")>0 else "Three")

Fixed submission:
i = int(input())
l = input().split()
print("Four" if l.count("Y")>0 else "Three")
Buggy python submission (verdict: Runtime Error):
n = int(input())**2
print(n-int(input())

Fixed submission:
n = int(input())**2
print(n-int(input()))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
paper = []
for _ in range(n):
    x = int(input())
    if x in paper:
        paper.remove(x)
    else:
        paper.append(x)
print(len(paper))

Fixed submission:
n = int(input())
paper = {}
for _ in range(n):
    x = int(input())
    if x in paper:
        paper[x] += 1
    else:
        paper[x] = 1
count = 0
for i in paper.values():
    if i % 2 != 0: count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
ns = []
for _ in range(n):
    ns.append(int(input()))

print(lcm(ns))

Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
ns = []
for _ in range(n):
    ns.append(int(input()))

print(lcm(ns))
Buggy python submission (verdict: Runtime Error):
r = map(lambda x:int(x)-1, input().split())
print(r[0]*r[1])

Fixed submission:
r = list(map(lambda x:int(x)-1, input().split()))
print(r[0]*r[1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [[int(input())-1, False] for _ in range(n)]
a[0][1] = True
now = 0
cnt = 0
while True:
    now = a[now][0]
    if a[now][1]:
        print(f"now={now}") 
        print(-1)
        break
    a[now][1] = True
    cnt += 1
    if now == 1:
        print(cnt)
        break


Fixed submission:
n = int(input())
a = [[int(input())-1, False] for _ in range(n)]
a[0][1] = True
now = 0
cnt = 0
while True:
    now = a[now][0]
    if a[now][1]:
        print(-1)
        break
    a[now][1] = True
    cnt += 1
    if now == 1:
        print(cnt)
        break
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
flag = [False for _ in range(8)]
flex = 0
for x in a:
    if x >= 3200:
        flex += 1
    else:
        flag[int(x/400)] = True
les = flag.count(True)
if les == 0 and flex > 0:
    print("1 " + flex)
else:
    print("{} {}".format(les, les+flex))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
flag = [False for _ in range(8)]
flex = 0
for x in a:
    if x >= 3200:
        flex += 1
    else:
        flag[int(x/400)] = True
les = flag.count(True)
if les == 0 and flex > 0:
    print("1 {}".format(flex))
else:
    print("{} {}".format(les, les+flex))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
flag = [False for _ in range(8)]
flex = 0
for x in a:
    if x >= 3200:
        flex += 1
    else:
        flag[int(x/400)] = True
les = flag.count(True)
print(f"{les} {min([8,les+flex])}")

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
flag = [False for _ in range(8)]
flex = 0
for x in a:
    if x >= 3200:
        flex += 1
    else:
        flag[int(x/400)] = True
les = flag.count(True)
if les == 0 and flex > 0:
    print("1 {}".format(flex))
else:
    print("{} {}".format(les, les+flex))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a + b >= 10: print("error")
else: print(x+y)

Fixed submission:
a, b = map(int, input().split())
if a + b >= 10: print("error")
else: print(a+b)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if x + y >= 10: print("error")
else: print(x+y)

Fixed submission:
a, b = map(int, input().split())
if a + b >= 10: print("error")
else: print(a+b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

cnt = 1

increase = a[1] - a[0];
for i in range(2, len(a)):
    new_inc = a[i] - a[i-1];
    if increase * new_inc < 0:
        cnt += 1
        increase = 0
    elif increase == 0:
        increase = new_inc
print(cnt)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
if n < 3:
    print(1)
    exit(0)
cnt = 1

increase = a[1] - a[0];
for i in range(2, len(a)):
    new_inc = a[i] - a[i-1];
    if increase * new_inc < 0:
        cnt += 1
        increase = 0
    elif increase == 0:
        increase = new_inc
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, M = list(map(int, input().split()))
E = [[] for i in range(N)]

for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1; b -= 1
    E[a].append(b)
    E[b].append(a)
    
par = [-1] * N
q = [(0, 0)]

while q:
    v, p = q.pop(0)
    
    if par[v] != -1: continue
    par[v] = p
    
    for u in E[v]:
        q.append((u, v))
    
for p in par[1:]:
    if p == -1:
        print('No')
        sys.exit()
        
print('Yes')
for p in par[1:]:
    print(p+1)

Fixed submission:
import sys
input=sys.stdin.readline
from collections import deque

def main():
    N, M = list(map(int, input().split()))
    E = [deque() for i in range(N)]
    
    for i in range(M):
        a, b = list(map(int, input().split()))
        a -= 1; b -= 1
        E[a].append(b)
        E[b].append(a)
        
    par = [-1] * N
    q = deque([(0, 0)])
    c = 0
    while q:
        v, p = q.popleft()
        
        if par[v] != -1: continue
        par[v] = p+1
        c += 1
        
        for u in E[v]:
            if par[u] != -1: continue
            q.append((u, v))
        
    if c < N: print('No')
    else: 
        print('Yes')
        print('\n'.join(list(map(str, par[1:]))))
            
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import Counter

def main():
    MOD = 2019
    S = input()[::-1]
    n = 0
    x = 1
    c = Counter()
    ans = 0
    
    for s in S:
        c[n] += 1
        n += int(s) * x
        n %= MOD
        ans += c[n]
        x = x * 10 % MOD
                
    print(ans)
        
if __name__ == '__main__':
    main()  

Fixed submission:
from collections import Counter

MOD = 2019
S = input()[::-1]
n = 0
x = 1
c = Counter()
ans = 0

for s in S:
    c[n] += 1
    n += int(s) * x
    n %= MOD
    ans += c[n]
    x = x * 10 % MOD
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, M = map(int, input().split())
S = input()

ans = []
check = []

idx = N
while 0 < idx:
    for i in range(M, -1, -1):
        if idx-i < 0: continue
        if S[idx-i] == '1':
            if idx-i in check: print(-1); sys.exit()
            else: check.append(idx-i)
        else:
            ans.append(i)
            idx -= i
            break

for a in ans[::-1]: print(a)

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

def main():
    N, M = map(int, input().split())
    S = input()
    
    ans = []
    check = [False] * (N+1)
    
    idx = N
    while 0 < idx:
        f = False
        for i in range(M, 0, -1):
            if idx-i < 0: continue
            if S[idx-i] == '1':
                if check[idx-i]: print(-1); sys.exit()
                else: check[idx-i] = True
            else:
                ans.append(i)
                idx -= i
                f = True
                break
        if not f: print(-1); sys.exit()
    
    for a in ans[::-1]: print(a)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
print(sum([s == t fot s, t in zip(input(), input())]))

Fixed submission:
S = input()
T = input()

ans = 0

for s, t in zip(S, T):
    ans += s == t
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect_right

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    N = len(s)
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdeghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 0
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
        
        i = bisect_right(table[a], idx)
        
        if i != length[a]:
            idx = table[a][i]
            if idx == N:
                loop += 1
                idx = 0
        else:
            loop += 1
            idx = table[a][0]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from bisect import bisect_right

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    N = len(s)
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdefghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 0
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
        
        i = bisect_right(table[a], idx)
        
        if i != length[a]:
            idx = table[a][i]
            if idx == N:
                loop += 1
                idx = 0
        else:
            loop += 1
            idx = table[a][0]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect_left

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdeghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 1
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
            
        i = bisect_left(table[a], idx)
    
        if i == length[a]:
            loop += 1
            idx = table[a][0]
        else:
            idx = table[a][i]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from bisect import bisect_right

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    N = len(s)
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdefghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 0
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
        
        i = bisect_right(table[a], idx)
        
        if i != length[a]:
            idx = table[a][i]
            if idx == N:
                loop += 1
                idx = 0
        else:
            loop += 1
            idx = table[a][0]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [sorted(input()) for i in range(N)]
ans = 0

for i in range(N):
    for j in range(i+1, N):
        if s[i] == s[j]:
            ans += 1
print(ans)

Fixed submission:
import math

N = int(input())
s = {}
ans = 0

for i in range(N):
    tmp = ''.join(sorted(input()))
    if tmp in s:
        s[tmp] += 1
    else:
        s[tmp] = 1

x = math.factorial(2)
for n in s.values():
  	if n > 1:
	    ans += math.factorial(n) // (math.factorial(n-2) * x)
print(ans)