Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    A = list(map(int,input().split()))
    N = A[0]
    X = A[1]
    Y = A[2]
    list1 = [[0 for i in range(N)] for j in range(N)]
    ans = [0 for i in range(N-1)]

    for i in range(N):
        for j in range(i+1,N):
            list1[i][j] = min(j-i,abs(X-1-i)+1+abs(j-Y+1), abs(Y-1-i)+1+abs(j-X+1))
            ans[list1[i][j]-1] += 1

    for i in ans:
        print(i)


main()

Fixed submission:
def main():
    A = list(map(int,input().split()))
    N = A[0]
    X = A[1]
    Y = A[2]
    list1 = [[0 for i in range(N)] for j in range(N)]
    ans = [0 for i in range(N-1)]

    for i in range(N):
        for j in range(i+1,N):
            list1[i][j] = min(j-i,abs(X-1-i)+1+abs(j-Y+1), abs(Y-1-i)+1+abs(j-X+1))
            ans[list1[i][j]-1] += 1

    for i in ans:
        print(i)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    A = list(map(int,input().split()))
    N = A[0]
    X = A[1]
    Y = A[2]
    list1 = [[0 for i in range(N)] for j in range(N)]
    ans = [0 for i in range(N-1)]

    for i in range(N):
        for j in range(N):
            if abs(i-j) == 1:
                list1[i][j] = 1
            elif i == X-1 and j == Y-1:
                list1[i][j] = 1
            elif i == Y-1 and j == X-1:
                list1[i][j] = 1
            else:
                list1[i][j] = N*2

    for l in range(N):
        for i in range(N):
            for j in range(N):
                list1[i][j] = min(list1[i][j], list1[i][l]+list1[l][j])

    for i in range(N):
        for j in range(i+1,N):
            if(list1[i][j] < N):
                ans[list1[i][j]-1] += 1

    for i in ans:
        print(i)


main()

Fixed submission:
def main():
    A = list(map(int,input().split()))
    N = A[0]
    X = A[1]
    Y = A[2]
    list1 = [[0 for i in range(N)] for j in range(N)]
    ans = [0 for i in range(N-1)]

    for i in range(N):
        for j in range(i+1,N):
            list1[i][j] = min(j-i,abs(X-1-i)+1+abs(j-Y+1), abs(Y-1-i)+1+abs(j-X+1))
            ans[list1[i][j]-1] += 1

    for i in ans:
        print(i)


main()
Buggy python submission (verdict: Time Limit Exceeded):

MOD = 998244353


def main():
    global A, MOD
    N,S = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [[[0 for k in range(3)] for i in range(S+1)] for j in range(N)]


    dp[0][0][0] = 1
    dp[0][0][1] = 1
    dp[0][0][2] = 1
    if A[0] <= S:
        dp[0][A[0]][1] = 1
        dp[0][A[0]][2] = 1
    for i in range(1,N):
        for j in range(S+1):
            if j + A[i] <= S:
                dp[i][j+A[i]][1] = (dp[i][j+A[i]][1] + dp[i-1][j][0] + dp[i-1][j][1])%MOD
                dp[i][j+A[i]][2] = (dp[i][j+A[i]][2] + dp[i-1][j][0] + dp[i-1][j][1])%MOD
            dp[i][j][0] = (dp[i][j][0] + dp[i-1][j][0])%MOD
            dp[i][j][1] = (dp[i][j][1] + dp[i-1][j][1] + dp[i-1][j][0])%MOD
            dp[i][j][2] = (dp[i][j][2] + dp[i-1][j][2] + dp[i-1][j][1] + dp[i-1][j][0])%MOD

    print(dp[N-1][S][2]%MOD)

main()

Fixed submission:

MOD = 998244353


def main():
    global MOD
    N,S = map(int, input().split())
    A = list(map(int, input().split()))
    dp0 = [[0 for i in range(S+1)] for j in range(N)]
    dp1 = [[0 for i in range(S+1)] for j in range(N)]
    dp2 = [[0 for i in range(S+1)] for j in range(N)]


    dp0[0][0] = 1
    dp1[0][0] = 1
    dp2[0][0] = 1
    if A[0] <= S:
        dp1[0][A[0]] = 1
        dp2[0][A[0]] = 1
    for i in range(1,N):
        for j in range(S+1):
            if j + A[i] <= S:
                dp1[i][j+A[i]] = (dp1[i][j+A[i]] + dp0[i-1][j] + dp1[i-1][j])%MOD
                dp2[i][j+A[i]] = (dp2[i][j+A[i]] + dp0[i-1][j] + dp1[i-1][j])%MOD
            dp0[i][j] = (dp0[i][j] + dp0[i-1][j])%MOD
            dp1[i][j] = (dp1[i][j] + dp1[i-1][j] + dp0[i-1][j])%MOD
            dp2[i][j] = (dp2[i][j] + dp2[i-1][j] + dp1[i-1][j] + dp0[i-1][j])%MOD

    print(dp2[N-1][S]%MOD)

main()
Buggy python submission (verdict: Time Limit Exceeded):
n,m=list(map(int,input().split()))
parents=[i for i in range(n)]
def find(a):
    if parents[a]!=a:
        return find(parents[a])
    return a
        

def union(a,b):
    a=find(a)
    b=find(b)
    if a==b:
        return 
    else:
        parents[a]=b

for i in range(m):
    h,a,b=list(map(int,input().split()))
    if h==0:
        union(a,b)
    else:
        x=find(a)
        y=find(b)
        
        print(1 if x==y else 0)
    

Fixed submission:
n,m=list(map(int,input().split()))
parents=[i for i in range(n)]
rank=[i for i in range(n)]
def find(a):
    if parents[a]!=a:
        return find(parents[a])
    return a
        

def union(a,b):
    xa=find(a)
    xb=find(b)
    if xa==xb:
        return
    if rank[xa]>rank[xb]:
        parents[xb]=xa
        
    elif rank[xa]<rank[xb]:
        parents[xa]=xb
    else:
        parents[xa]=xb
        rank[xb]+=1

for i in range(m):
    h,a,b=list(map(int,input().split()))
    if h==0:
        union(a,b)
    else:
        x=find(a)
        y=find(b)
        
        print(1 if x==y else 0)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
# your code goes here


v=defaultdict(list)
n,m=map(int,input().split())
for i in range(m):
    a,b=map(int,input().split())
    v[a-1].append(b-1)
    v[b-1].append(a-1)
    

	
	
	
    
    
vis=[0]*n

def dfs(node):
    vis[node]=1
    for j in v[node]:
        #print(j,v[node])
        if vis[j]==0:
            a.append(j+1)
            dfs(j)
ans=0      
for i in range(n):
    if vis[i]==0:
        a=[i]
        dfs(i)
        ans=max(ans,len(a))
    

print(ans)

Fixed submission:
from collections import defaultdict
# your code goes here
from heapq import heappop ,heappush
def bfs(k):
    
    q=[k]
    vis[k]=1
    #p.append(k+1)
    while len(q):
        
        
        curr=heappop(q)
        p.append(curr+1)
        #print(vis, v[curr+1])
        for c in v[curr+1]:
            #print(c)
            if vis[c-1]==0:
                a.append(c)
                
                heappush(q,c-1)
                vis[c-1]=1
            
    
n,m=map(int,input().split())
v=defaultdict(list)
vis=[0]*n
p=[]

for i in range(m):
    a,b=map(int,input().split())
    v[a].append(b)
    v[b].append(a)
ans=0      
for i in range(n):
    if vis[i]==0:
        a=[i+1]
        bfs(i)
        ans=max(ans,len(a))
        #print(a)
    

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
k=0
while n>0:
    k+=n%10
    n//=10
if k%9==0:
    print("Yes")
else:
    print('No')

Fixed submission:
n = input()
k=0
for i in n:
    k+=int(i)
    k%=9

if k%9==0:
    print("Yes")
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,k=list(map(int,input().split()))
m=list(map(int,input().split()))
r=1
for i in range(k):
    r*=m[i]
for i in range(k,n):
    p=r
    r//=m[i-k]
    r*=m[i]
    #print(p,r)
    if r>p:
        print('Yes')
    else:
        print('No')


Fixed submission:
n,k=list(map(int,input().split()))
m=list(map(int,input().split()))
r=1

for i in range(k,n):
  
    if m[i]>m[i-k]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
m=list(map(int,input().split()))
d={}
k=0
for i in range(n):
    k+=m[i]
    if m[i] in d:
        d[m[i]]+=1
    else:
        d[m[i]]=1
for x in range(int(input())):
    
    b,c=list(map(int,input().split()))

    k+=d[b]*(c-b)
    
    if c in d:
        d[c]+=d[b]
    else:
        d[c] = d[b]
    del d[b] 
    print(k)

Fixed submission:
n = int(input())
m=list(map(int,input().split()))
d={}
k=0
for i in range(n):
    k+=m[i]
    if m[i] in d:
        d[m[i]]+=1
    else:
        d[m[i]]=1
for x in range(int(input())):
    
    b,c=list(map(int,input().split()))

    
    
    if b in d:
        k+=d[b]*(c-b)
        if c in d:
            d[c]+=d[b]
        else:
            d[c] = d[b]
        del d[b] 
    print(k)
Buggy python submission (verdict: Runtime Error):

n=int(input())
m=list(map(int,input().split()))
k=10**6
p=[0]*k
m.sort()
for i in range(1,n):
    if m[i]==m[i-1]:
        p[m[i]]=1
res=0
for i in range(n):
    if p[m[i]]==0:
        res+=1
    
    for j in range(m[i]*2,k,m[i]):
        p[j]=1
print(res)
        
    
     
    

Fixed submission:

n=int(input())
m=list(map(int,input().split()))
k=10**6+1
p=[0]*k
m.sort()
for i in range(1,n):
    if m[i]==m[i-1]:
        p[m[i]]=1
res=0
for i in range(n):
    if p[m[i]]==0:
        res+=1
    
    if i!=n-1 and m[i]!=m[i+1]:
        for j in range(m[i]*2,k,m[i]):
            p[j]=1
print(res)
Buggy python submission (verdict: Time Limit Exceeded):

n,k=list(map(int,input().split()))
m=list(map(int,input().split()))
a=[]
p=1
while p not in a:
    a.append(p)
    p=m[p-1]

l=a.index(p)

if k<len(a):
    print(a[k])
else:
    k-=l
    print(a[l+k%(len(a)-l)])

            
            
        
    

Fixed submission:

n,k=list(map(int,input().split()))
m=list(map(int,input().split()))
a=[]
p=1
vis=[0]*n
while vis[p-1]==0:
    a.append(p)
    vis[p-1]=1
    p=m[p-1]

l=a.index(p)

if k<len(a):
    print(a[k])
else:
    k-=l
    print(a[l+k%(len(a)-l)])
Buggy python submission (verdict: Runtime Error):
n = int(input())
i = 0
flag = false
while(7*i<=n):
  if (n-7*i)%4 == 0:
    flag = true
    break
  i+=1
if flag:
  print("Yes")
else:
  print("No")


Fixed submission:
n = int(input())
i = 0
flag = False
while(7*i<=n):
  if (n-7*i)%4 == 0:
    flag = True
    break
  i+=1
if flag:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
i = 0
flag = False
while(7*i<=n):
  if (n-7*i)%4 == 0:
    flag = True
    break
if flag:
  print("Yes")
else:
  print("No")


Fixed submission:
n = int(input())
i = 0
flag = False
while(7*i<=n):
  if (n-7*i)%4 == 0:
    flag = True
    break
  i+=1
if flag:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
i = 0
flag = false
while(7*i<=n):
  if (n-7*i)%4 == 0:
    flag = true
    break
if flag:
  print("Yes")
else:
  print("No")


Fixed submission:
n = int(input())
i = 0
flag = False
while(7*i<=n):
  if (n-7*i)%4 == 0:
    flag = True
    break
  i+=1
if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
for i in range(3):
    arr[i] = input()
print(arr[0][0] + arr[1][1] + arr[2][2])


Fixed submission:
arr = []
for i in range(3):
    arr.append(input())
print(arr[0][0] + arr[1][1] + arr[2][2])

Buggy python submission (verdict: Runtime Error):
arr = (list(input().split('\r\n')))
print(arr[0][0] + arr[1][1] + arr[2][2])


Fixed submission:
arr = []
for i in range(3):
    arr.append(input())
print(arr[0][0] + arr[1][1] + arr[2][2])

Buggy python submission (verdict: Runtime Error):
arr = (list(input().split('\r\n')))
print('{}',arr[0][0] + arr[1][1] + arr[2][2])

Fixed submission:
arr = []
for i in range(3):
    arr.append(input())
print(arr[0][0] + arr[1][1] + arr[2][2])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from operator import itemgetter
import bisect


def solve(N: int, M: int, A: "List[int]", BC):
    A.sort()
    BC.sort(key=itemgetter(1), reverse=True)
    idx = 0
    i = 0
    while i < M:
        B, C = BC[i]
        nidx = idx+B if idx+B < len(A) else len(A) - 1
        if A[nidx] < C:
            for j in range(idx+B):
                A[j] = C
            idx += B
            i += 1
        else:
            for j in range(nidx):
                if A[j] < C:
                    A[j] = C
            break

    ans = 0
    for a in A:
        ans += a
    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    BC = []
    for _ in range(M):
        BC.append(list(map(int, input().split())))
    solve(N, M, A, BC)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from operator import itemgetter
import bisect


def solve(N: int, M: int, A: "List[int]", BC):
    A.sort()
    BC.sort(key=itemgetter(1), reverse=True)
    idx = 0
    i = 0
    for i in range(M):
        B, C = BC[i]
        nidx = idx+B if idx+B < len(A) else len(A)
        if A[nidx-1] < C:
            for j in range(idx, nidx):
                A[j] = C
            idx += B
        else:
            for j in range(idx, nidx):
                if A[j] < C:
                    A[j] = C
            break

    ans = 0
    for a in A:
        ans += a
    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    BC = []
    for _ in range(M):
        BC.append(list(map(int, input().split())))
    solve(N, M, A, BC)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**5
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range(2, N+1):
    g1.append((g1[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD//i)) % MOD)
    g2.append((g2[-1] * inv[-1]) % MOD)

def solve(N: int, M: int, K: int):
    ans = 0
    for i in range(1, M):
        ans += i * N**2 * (M-i)
        ans %= MOD
    for i in range(1, N):
        ans += i * M**2 * (N-i)
        ans %= MOD
    ans *= cmb(N*M-2, K-2, MOD)
    ans %= MOD
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, M, K)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 2*10**5
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range(2, N+1):
    g1.append((g1[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD//i)) % MOD)
    g2.append((g2[-1] * inv[-1]) % MOD)

def solve(N: int, M: int, K: int):
    ans = 0
    for i in range(1, M):
        ans += i * N**2 * (M-i)
        ans %= MOD
    for i in range(1, N):
        ans += i * M**2 * (N-i)
        ans %= MOD
    ans *= cmb(N*M-2, K-2, MOD)
    ans %= MOD
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, M, K)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    col = [-1 for _ in range(N+1)]
    G = [[] for _ in range(N+1)]
    for i in range(N-1):
        G[u[i]].append((v[i], w[i]))
        G[v[i]].append((u[i], w[i]))

    def dfs(p, c, cnt):
        if cnt == N:
            return
        for np, dis in G[p]:
            if col[np] == -1:
                cnt += 1
                if dis%2 == 0:
                    col[np] = c
                else:
                    nc = 1 - c
                    col[np] = nc
                dfs(np, nc, cnt)

    col[1] = 0
    dfs(1, 0, 0)
    for elem in col[1:]:
        print(elem)


    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N-1)  # type: "List[int]" 
    v = [int()] * (N-1)  # type: "List[int]" 
    w = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    col = [-1 for _ in range(N+1)]
    G = [[] for _ in range(N+1)]
    for i in range(N-1):
        G[u[i]].append((v[i], w[i]))
        G[v[i]].append((u[i], w[i]))

    def dfs(p, c, cnt):
        if cnt == N:
            return
        for np, dis in G[p]:
            if col[np] == -1:
                cnt += 1
                if dis%2 == 0:
                    col[np] = c
                    dfs(np, c, cnt)
                else:
                    nc = 1 - c
                    col[np] = nc
                    dfs(np, nc, cnt)

    col[1] = 0
    dfs(1, 0, 0)
    for elem in col[1:]:
        print(elem)


    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N-1)  # type: "List[int]" 
    v = [int()] * (N-1)  # type: "List[int]" 
    w = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]
D = []
set_D = set()
A.sort(reverse=True)
for a in A:
    if B[a] in set_D:
        continue
    else:
        set_D.add(B[a])
        D.append([a, B[a]])

D.sort(key=itemgetter(0), reverse=True)
dp = [-10**10]*(N+1)
dp[0] = 0
for i in range(1, N+1):
    for elem in set_D:
        if i < elem or dp[i-elem] is None:
            continue
        dp[i] = max(dp[i], dp[i-elem]+1)
ans = ''
while N > 0:
    for i in range(len(D)):
        if dp[N-D[i][1]] == dp[N]-1:
            ans += str(D[i][0])
            N -= D[i][1]
            break
print(ans)


Fixed submission:
from operator import itemgetter
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]
D = []
set_D = set()
A.sort(reverse=True)
for a in A:
    if B[a] in set_D:
        continue
    else:
        set_D.add(B[a])
        D.append([a, B[a]])

D.sort(key=itemgetter(0), reverse=True)
dp = [-10**10]*(N+1)
dp[0] = 0
for i in range(1, N+1):
    for elem in set_D:
        if i < elem or dp[i-elem] is None:
            continue
        dp[i] = max(dp[i], dp[i-elem]+1)
ans = ''
while N > 0:
    for i in range(len(D)):
        if N-D[i][1] < 0:
            continue
        if dp[N-D[i][1]] == dp[N]-1:
            ans += str(D[i][0])
            N -= D[i][1]
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
from collections import Counter
import heapq
N, K = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=itemgetter(1, 0), reverse=True)
t, d = zip(*td)

cnt_all = Counter(t)
cnt_all = cnt_all.most_common()
kind = len(cnt_all)
tmp = 0
i = 0
while tmp < K:
    tmp += cnt_all[i][1]
    i += 1
init_kind = i
S = []
heapq.heapify(S)
cnt = Counter()
for i in range(K):
    cnt[t[i]] += 1
    heapq.heappush(S, (d[i], i, t[i]))
sums = [0]*(K+1)
sums[init_kind] = sum(list(zip(*S))[0])
for i in range(init_kind, kind):
    nS = []
    heapq.heapify(nS)
    keys = cnt.keys()
    remove_flag = False
    for _ in range(K):
        tmp = heapq.heappop(S)
        if cnt[tmp[2]] == 1:
            heapq.heappush(nS, tmp)
        else:
            if remove_flag:
                heapq.heappush(nS, tmp)
            else:
                remove_flag = True
                cnt[tmp[2]] -= 1
    for j in range(N):
        if t[j] not in keys:
            heapq.heappush(nS, (d[j], j, t[j]))
            cnt[t[j]] += 1
            break
    sums[i+1] = sum(list(zip(*nS))[0])
    S = nS
for i in range(len(sums)):
    sums[i] += i**2
print(max(sums))


Fixed submission:
from operator import itemgetter
N, K = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=itemgetter(1, 0), reverse=True)
t, d = zip(*td)

s = set()
q = []
tmp = 0
now = 0
for i in range(K):
    if t[i] not in s:
        s.add(t[i])
    else:
        q.append(d[i])

    tmp += d[i]
    now += 1
kind = len(s)
sums = [-100000000000]*(kind+1)
sums[kind] = tmp
#for i in range(K, N):
#    if not q:
#        break
#    if t[i] not in s:
#        s.
while q:
    kind += 1
    tmp = q.pop()
    for i in range(now, N):
        now += 1
        if t[i] not in s:
            s.add(t[i])
            sums.append(sums[kind-1] + d[i] - tmp)
            break
for i in range(len(sums)):
    sums[i] += i**2
print(max(sums))
Buggy python submission (verdict: Runtime Error):
  S = input()
ans = 'keyence'

if S[0] == 'k':
    flag = True
    for i in range(1, 7):
        if S[i] != ans[i]:
            flag = False
            break
    if flag:
        print('YES')

    else:
        if ans[i:] == S[-len(ans[i:]):]:
            print('YES')
        else:
            print('NO')
else:
    if S[-7:] == ans:
        print('YES')
    else:
        print('NO')


Fixed submission:
S = input()
ans = 'keyence'

if S[0] == 'k':
    flag = True
    for i in range(1, 7):
        if S[i] != ans[i]:
            flag = False
            break
    if flag:
        print('YES')

    else:
        if ans[i:] == S[-len(ans[i:]):]:
            print('YES')
        else:
            print('NO')
else:
    if S[-7:] == ans:
        print('YES')
    else:
        print('NO')