Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, x, m = map(int, input().split())
if x == 0:
    print(0)
    exit()
now = x
ans = x
d = defaultdict(int)
repeat = []

for i in range(n):
    now = (now**2)%m
    d[now] += 1
    repeat.append(now)
    if d[now] > 1:
        break

for g in range(len(repeat)):
    if repeat[g] == now:
        break
    else:
        ans += repeat[g]
        n -= 1
repeat = repeat[g:-1] 
n -= 1

ans += sum(repeat)*(n//len(repeat)) + sum(repeat[:n%len(repeat)])
print(ans)


Fixed submission:
from collections import defaultdict
n, x, m = map(int, input().split())
now = x
ans = x
d = defaultdict(int)
repeat = []

for i in range(n):
    now = (now**2)%m
    d[now] += 1
    repeat.append(now)
    if d[now] > 1:
        break

for g in range(len(repeat)):
    if repeat[g] == now:
        break
    else:
        ans += repeat[g]
        n -= 1

repeat = repeat[g:-1] 
n -= 1
if len(repeat) != 0:
    ans += sum(repeat)*(n//len(repeat)) + sum(repeat[:n%len(repeat)])
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, x, m = map(int, input().split())
now = x
ans = x
d = defaultdict(int)
repeat = []

for i in range(n):
    now = (now**2)%m
    d[now] += 1
    repeat.append(now)
    if d[now] > 1:
        break

for g in range(len(repeat)):
    if repeat[g] == now:
        break
    else:
        ans += repeat[g]
        n -= 1
repeat = repeat[g:-1] 
n -= 1

ans += sum(repeat)*(n//len(repeat)) + sum(repeat[:n%len(repeat)])
print(ans)

Fixed submission:
from collections import defaultdict
n, x, m = map(int, input().split())
now = x
ans = x
d = defaultdict(int)
repeat = []

for i in range(n):
    now = (now**2)%m
    d[now] += 1
    repeat.append(now)
    if d[now] > 1:
        break

for g in range(len(repeat)):
    if repeat[g] == now:
        break
    else:
        ans += repeat[g]
        n -= 1

repeat = repeat[g:-1] 
n -= 1
if len(repeat) != 0:
    ans += sum(repeat)*(n//len(repeat)) + sum(repeat[:n%len(repeat)])
print(ans)
Buggy python submission (verdict: Runtime Error):
def sieve_eratosthenes(n):
    primes = [0, 1] * (n // 2 + 1)
    if n % 2 == 0:
        primes.pop()
    primes[1] = 0
    primes[2] = 1
    for p in range(3, n + 1, 2):
        if primes[p]:
            for q in range(p * p, n + 1, 2 * p):
                primes[q] = 0
    return primes

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

ps = set()
for i,m in enumerate(sieve_eratosthenes(1000000)):
    if m == 1:
        ps.add(i)

from collections import defaultdict
import math

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
for i in range(n):
    if a[-1-i] == 1:
        a.pop()
        n -= 1
    else:
        break

a.sort()

g = a[0]
for i in range(1,n):
    g = math.gcd(g, a[i])

if g == 1:
    if n > len(ps):
        print("setwise coprime")
    else:
        d = defaultdict(int)
        for i in range(n):
            f = factorization(a[i])
            for x, y in f:
                d[x] += 1
        for i in d.values():
            if i != 1:
                print("setwise coprime")
                exit()
        print("pairwise coprime")

else:
    print("not coprime")

Fixed submission:
def sieve_eratosthenes(n):
    primes = [0, 1] * (n // 2 + 1)
    if n % 2 == 0:
        primes.pop()
    primes[1] = 0
    primes[2] = 1
    for p in range(3, n + 1, 2):
        if primes[p]:
            for q in range(p * p, n + 1, 2 * p):
                primes[q] = 0
    return primes

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

ps = set()
for i,m in enumerate(sieve_eratosthenes(1000000)):
    if m == 1:
        ps.add(i)

from collections import defaultdict
import math

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
one = False
for i in range(n):
    if a[-1] == 1:
        a.pop()
        one = True
        n -= 1
    else:
        break

if n==0 or n==1:
    print("pairwise coprime")
    exit()

a.sort()

g = a[0]
for i in range(1,n):
    g = math.gcd(g, a[i])

if g == 1:
    if n > len(ps):
        print("setwise coprime")
    else:
        d = defaultdict(int)
        for i in range(n):
            f = factorization(a[i])
            for x, y in f:
                d[x] += 1
        for i in d.values():
            if i != 1:
                print("setwise coprime")
                exit()
        print("pairwise coprime")

else:
    if one:
        print("setwise coprime")
    else:
        print("not coprime")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

dp = [[-1]*n for i in range(5000)]
for i in range(1000//a[0]+1):
    dp[i][0] = 1000-a[0]*i

for i in range(1, n):
    for g in range(5000):
        for l in range(5000):
            if dp[l][i-1] >= 0:
                if l < g:
                    dp[g][i] = max(dp[l][i-1] - a[i]*(g-l), dp[g][i])
                else:
                    dp[g][i] = max(dp[l][i-1] + a[i]*(l-g), dp[g][i])
            else:
                break

ans = 0
for m in range(5000):
    ans = max(ans, dp[m][n-1])
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split())) + [-1]

money = 1000
k = 0

for i in range(n):
    if a[i+1] > a[i]:
        k += money//a[i]
        money = money - a[i]*(money//a[i])
    elif a[i+1] <= a[i]:
        money += k*a[i]
        k = 0

print(money)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

ans_list = []
for i in range(n):
    ans=0
    N = i+1
    for x in range(1,int(n**0.5)+1):
        for y in range(1,int((n-x**2)**0.5)+1):
            for z in range(1,int((n-x**2-y**2)**0.5)+1):
                if x**2+y**2+z**2+x*y+y*z+z*x==N:
                    ans+=1
    ans_list.append(ans)

for i in range(n):
    print(ans_list[i])

Fixed submission:
n=int(input())

ans = [0]*n
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            if x**2+y**2+z**2+x*y+y*z+z*x <= n:
                ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ok = [0]*(max(a)+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(2*a[i], max(a)+1, a[i]):
            ok[g] += 2


print(ok.count(1))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
M = max(a)
ok = [0]*(M+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(a[i], M+1, a[i]):
            if g != a[i]:
                ok[g] += 2


print(ok.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ok = [0]*(max(a)+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(a[i], max(a)+1, a[i]):
            if g != a[i]:
                ok[g] += 2


print(ok.count(1))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
M = max(a)
ok = [0]*(M+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(a[i], M+1, a[i]):
            if g != a[i]:
                ok[g] += 2


print(ok.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ok = [0]*(max(a)+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(a[i], max(a)+1, a[i]):
            if g != a[i]:
                ok[g] += 2


print(ok.count(1))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
M = max(a)
ok = [0]*(M+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(a[i], M+1, a[i]):
            if g != a[i]:
                ok[g] += 2


print(ok.count(1))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
if n%2==1:
    for i in range(m):
        print(i+1, n-i-1)
else:
    if n==4:
        print(2, 3)
        exit()
    for i in range(m-1):
        print(i+1, n-i)
    print(i+3, n-i-1)

Fixed submission:
n,m=map(int,input().split())
if n%2==1:
    for i in range(m):
        print(i+1, n-i-1)
else:
    used = [False]*n
    next = [i+1 for i in range(m)][::-2]+[i+1 for i in range(m)][-2::-2]
    i=0
    now=0
    count=0
    while True:
        if used[now]==False and used[now+next[i]]==False:
            print(now+1, now+next[i]+1)
            count+=1
            if count==m:
                break
            used[now]=True
            used[now+next[i]]=True
            i+=1
            now+=1
        else:
            now+=1
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
ans=0
for i in range(1,k+1):
    for g in range(1,k+1):
        for l in range(1,k+1):
            ans+=math.gcd(math.gcd(i,g),l)
print(ans)


Fixed submission:
import math
k=int(input())
ans=0
for i in range(1,k+1):
    for g in range(1,k+1):
        for l in range(1,k+1):
            ans+=math.gcd(math.gcd(i,g),l)
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

red=0
green=0
no=0
ans=0

while True:
    if red>x-1 and green>y-1:
        break
    if no<=c-1:
        if red>x-1:
            if q[green]>=r[no]:
                ans+=q[green]
                green+=1
            else:
                ans+=r[no]
                green+=1
                no+=1
        elif green>y-1:
            if p[green]>=r[no]:
                ans+=p[red]
                red+=1
            else:
                ans+=r[no]
                red+=1
                no+=1
        else:
            if max(p[red],q[green],r[no])==p[red]:
                ans+=p[red]
                red+=1
            elif max(p[red],q[green],r[no])==q[green]:
                ans+=q[green]
                green+=1
            else:
                if p[red]>q[green]:
                    q[green]=r[no]
                else:
                    p[red]=r[no]
                no+=1
    else:
        ans+=sum(p[red:x])
        ans+=sum(q[green:y])
        break
print(ans)

Fixed submission:
import heapq

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pq=p[:x]+q[:y]
heapq.heapify(pq)

for i in range(c):
    a=heapq.heappop(pq)
    if a<r[i]:
        heapq.heappush(pq,r[i])
    else:
        heapq.heappush(pq,a)
        break

print(sum(pq))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=input()
q=int(input())

R=True
ans=deque(list(s))
count=0

for i in range(q):
    l=list(map(str,input().split()))
    if int(l[0])==1:
        if R:
            R=False
        else:
            R=True
        count+=1
    else:
        f,c=int(l[1]),l[2]
        if f==1 and R:
            ans.appendleft(c)
        elif f==2 and R:
            ans.append(c)
        elif f==1 and (not R):
            ans.append(c)
        elif f==2 and (not R):
            ans.appendleft(c)

string=""
if count%2==0:
    for i in range(len(ans)):
        string+=ans[i]
else:
    for i in range(len(ans))[::-1]:
        string+=ans[i]
print(string)

Fixed submission:
from collections import deque

s=input()
q=int(input())

R=True
ans=deque(list(s))
count=0
for i in range(q):
    l=list(map(str,input().split()))
    if int(l[0])==1:
        if R:
            R=False
        else:
            R=True
        count+=1
    else:
        f,c=int(l[1]),l[2]
        if f==1 and R:
            ans.appendleft(c)
        elif f==2 and R:
            ans.append(c)
        elif f==1 and (not R):
            ans.append(c)
        elif f==2 and (not R):
            ans.appendleft(c)

if count%2==0:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))

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

s=input()
q=int(input())

R=True
ans=deque(list(s))
count=0

for i in range(q):
    l=list(map(str,input().split()))
    if int(l[0])==1:
        if R:
            R=False
        else:
            R=True
        count+=1
    else:
        f,c=int(l[1]),l[2]
        if f==1 and R:
            ans.appendleft(c)
        elif f==2 and R:
            ans.append(c)
        elif f==1 and (not R):
            ans.append(c)
        elif f==2 and (not R):
            ans.appendleft(c)

string=""
if count%2==0:
    for i in range(len(ans)):
        string+=ans[i]
else:
    for i in range(len(ans))[::-1]:
        string+=ans[i]
print(string)

Fixed submission:
from collections import deque

s=input()
q=int(input())

R=True
ans=deque(list(s))
count=0
for i in range(q):
    l=list(map(str,input().split()))
    if int(l[0])==1:
        if R:
            R=False
        else:
            R=True
        count+=1
    else:
        f,c=int(l[1]),l[2]
        if f==1 and R:
            ans.appendleft(c)
        elif f==2 and R:
            ans.append(c)
        elif f==1 and (not R):
            ans.append(c)
        elif f==2 and (not R):
            ans.appendleft(c)

if count%2==0:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
 
n=int(input())
s=[]
 
for i in range(n):
    s.append(input())
 
d=collections.Counter(s)
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
 
for i in range(len(max_k_list)):
    print(max_k_list[i])

Fixed submission:
import collections

n=int(input())
s=[]

for i in range(n):
    s.append(input())

d=collections.Counter(s).most_common()

ans=[]
past=d[0][1]

for i,m in d:
    if past==m:
        ans.append(i)
        past=m
    else:
        break

ans.sort()
for i in range(len(ans)):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import collections

n=int(input())
s=[]

for i in range(n):
    s.append(input())

d=collections.Counter(s)
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()

for i in range(len(max_k_list)):
    print(max_k_list[i])

Fixed submission:
import collections

n=int(input())
s=[]

for i in range(n):
    s.append(input())

d=collections.Counter(s).most_common()

ans=[]
past=d[0][1]

for i,m in d:
    if past==m:
        ans.append(i)
        past=m
    else:
        break

ans.sort()
for i in range(len(ans)):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
 
dp=[0]*h
for i in range(h):
    _min = 10**10
    for g in range(n):
        if i>=ab[g][0]:
            _min = min(ab[g][1]+dp[i-ab[g][0]], _min)
        else:
            _min = min(ab[g][1], _min)
    dp[i]=_min
print(dp[-1])

Fixed submission:
h=int(input())

ans=0
i=0
while True:
    ans+=(2**i)
    h//=2
    i+=1
    if h==0:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
 
dp=[0]*h
for i in range(h):
    _min = 10**10
    for g in range(n):
        if i>=ab[g][0]:
            _min = min(ab[g][1]+dp[i-ab[g][0]], _min)
        else:
            _min = min(ab[g][1], _min)
    dp[i]=_min
print(dp[-1])

Fixed submission:
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]

dp=[0]*h
for i in range(h):
    _min = 10**10
    for g in range(n):
        if i>=ab[g][0]:
            _min = min(ab[g][1]+dp[i-ab[g][0]], _min)
        else:
            _min = min(ab[g][1], _min)
    dp[i]=_min
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60
num = [0]*60
ans = 0

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            count[g] += 1
            num[g] += i+1 - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans % mod)

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

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60

for i in range(n):
    bit = a[i]
    for g in range(60):
        count[g] += bit%2
        bit //= 2
        if bit == 0:
            break

ans = 0
num = [0]*60

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            num[g] += n - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans//2 % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 217937901270479417
for i in range(1,len(a)):
    ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)

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

ans = 217937901270479417
_sum = sum(a)
sum_1 = 0
for i in range(0,len(a)):
    sum_1 += a[i]
    sum_2 = _sum - sum_1
    ans = min(ans, abs(sum_1 - sum_2))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k,p):
	from math import factorial
	if n<0 or k<0 or n<k: return 0
	if n==0 or k==0: return 1
	a=factorial(n) %p
	b=factorial(k) %p
	c=factorial(n-k) %p
	return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  	if b==0: return 1
  	if b%2==0:
    		d=power_func(a,b//2,p)
    		return d*d %p
  	if b%2==1:
    		return (a*power_func(a,b-1,p ))%p


x,y = map(int, input().split())

mod = 10**9+7
ans_list = []

x_list = []

for i in range(0, x//2+1):
    x_list.append([i, x-2*i])

for g,l in x_list:
    if (g+2*l)==y:
    	ans_list.append([g,l])

ans=0
for g,l in ans_list:
    ans += comb(g+l, g, mod)
print(ans)

Fixed submission:
class Combination:
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv


x,y = map(int, input().split())

mod = 10**9+7
ans_list = []

x_list = []

for i in range(0, x//2+1):
    x_list.append([i, x-2*i])

for g,l in x_list:
    if (g+2*l)==y:
    	ans_list.append([g,l])

ans=0
A = Combination(10**6, mod)
for g,l in ans_list:
    ans += A(g+l,l)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sympy
n=int(input())
a = sympy.divisors(n)
ans = 11451481019191919191919
for i in a:
	ans = min(ans, i+n/i)
	
print(int(ans-2))

Fixed submission:
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)
    return divisors

n=int(input())
a = make_divisors(n)
ans = 11451481019191919191919
for i in a:
	ans = min(ans, i+n/i)
	
print(int(ans-2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))

ans = 0
now=0

for i in range(N):
    if now+1>=N:
        break
    _ans = 0
    if H[now]>=H[now+1]:
        for g in range(1145141919):
            if now+1+g>=N:
                break
            if H[now+g]>=H[now+1+g]:
                _ans+=1
            else:
                now+=g
                break
    else:
        now+=1
    ans = max(ans, _ans)

print(ans)

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

ans = 0
now=0

for i in range(N):
    if now+1>=N:
        break
    _ans = 0
    if H[now]>=H[now+1]:
        for g in range(1145141919):
            if now+1+g>=N:
                now+=g+1
                break
            if H[now+g]>=H[now+1+g]:
                _ans+=1
            else:
                now+=g+1
                break
    else:
        now+=1
    ans = max(ans, _ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = input()
t = list(input())

string = s
length = 1

for i in range(len(t)):
	if s.find(t[i])==-1:
		print(-1)
		sys.exit()
	if string.find(t[i])==-1:
		string = string + s
		length += 1
	string = string[string.find(t[i])+1 : ]
	
print(length*len(s)-len(string))

Fixed submission:
import sys

s = input()
t = list(input())

string = s
length = 1

for i in range(len(t)):
	if s.find(t[i])==-1:
		print(-1)
		sys.exit()
	if string.find(t[i])==-1:
		string = s
		length += 1
	string = string[string.find(t[i])+1 : ]
	
print(length*len(s)-len(string))

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = input()
t = list(input())

string = s
length = 1

for i in t:
	if s.find(i)==-1:
		print(-1)
		sys.exit()
	if string.find(i)==-1:
		string = string + s
		length += 1
	string = string[string.find(i)+1 : ]
	
print(length*len(s)-len(string))

Fixed submission:
import sys

s = input()
t = list(input())

string = s
length = 1

for i in range(len(t)):
	if s.find(t[i])==-1:
		print(-1)
		sys.exit()
	if string.find(t[i])==-1:
		string = s
		length += 1
	string = string[string.find(t[i])+1 : ]
	
print(length*len(s)-len(string))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
l=[tuple(map(int,input().split())) for i in range(N)]
l.sort(reverse=True)
 
h=[]
ans=0
for i in range(1,M+1):
    while l and l[-1][0]==i:
        h.append(l.pop()[1])
    if h:
        ans+=max(h)
        h.pop(h.index(max(h)))
print(ans)

Fixed submission:
import heapq
import bisect

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

ans=0
ab.sort()
_index=[i[0] for i in ab]
p=[]
heapq.heapify(p)

for i in range(1,M+1):
	for g in ab[bisect.bisect_left(_index, i) : bisect.bisect_right(_index, i)]:
		heapq.heappush(p, -g[1])
	if p!=[]:
		ans+=heapq.heappop(p)*(-1)

print(ans)