Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#ライブラリインポート
from collections import defaultdict
import queue

#入力受け取り
def getlist():
	return list(map(int, input().split()))

INF = float("inf")

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = queue.Queue()
		self.Q.put(s)
		self.pre = [None] * N
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				self.pre[i] = v
				self.Q.put(i)

#処理内容
def main():
	N, M = getlist()
	D = defaultdict(int)
	G = Graph()
	for i in range(N - 1 + M):
		A, B = getlist()
		G.add_edge(A - 1, B - 1)
		D[B - 1] += 1
	s = 0
	for i in range(N):
		if D[i] == 0:
			s = i
			break

	BF = BFS(G, s, N)
	ans = BF.pre
	for i in ans:
		if i == None:
			print(0)
		else:
			print(i + 1)

if __name__ == '__main__':
	main()

Fixed submission:
from collections import defaultdict, deque

#入力受け取り
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
outE = defaultdict(list)
inE = defaultdict(int)

for i in range(N + M - 1):
	u, v = getlist()
	outE[u - 1].append(v - 1)
	inE[v - 1] += 1

Q = deque()
for i in range(N):
	if inE[i] == 0:
		Q.append(i)
top = []
while Q:
	v1 = Q.popleft()
	top.append(v1)
	for v2 in outE[v1]:
		inE[v2] -= 1
		if inE[v2] == 0:
			Q.append(v2)

parent = [0] * N
for i in top:
	for j in outE[i]:
		parent[j] = i + 1
for i in range(N):
	print(parent[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, P = list(map(int, input().split()))

prime = []
numL = [i for i in range(2, 1000001)]
while True:
	p = numL[0]
	if p >= 1000:
		prime += numL
		break
	prime.append(p)
	numL = [i for i in numL if i % p != 0]

ans = 1
for i in prime:
	c = 0
	while True:
		if P % i == 0:
			c += 1
			P = int(P // i)
		else:
			break
	if c >= N:
		ans = ans * (i ** int(c // N))

print(ans)

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

prime = [2, 3, 5]
numL = [i for i in range(2, 1000001) if i % 2 != 0 and i % 3 != 0 and i % 5 != 0]
while True:
	p = numL[0]
	if p >= 1000:
		prime += numL
		break
	prime.append(p)
	numL = [i for i in numL if i % p != 0]

if N == 1:
	print(P)

else:
	ans = 1
	for i in prime:
		c = 0
		while True:
			if P % i == 0:
				c += 1
				P = int(P // i)
			else:
				break
		if c >= N:
			ans = ans * (i ** int(c // N))
	print(ans)
Buggy python submission (verdict: Runtime Error):
D = int(input())
if D = 25:
	print("Christmas")
elif D = 24:
	print("Christmas Eve")
elif D = 23:
	print("Christmas Eve Eve")
else:
	print("Christmas Eve Eve Eve")

Fixed submission:
D = int(input())
if D == 25:
	print("Christmas")
elif D == 24:
	print("Christmas Eve")
elif D == 23:
	print("Christmas Eve Eve")
else:
	print("Christmas Eve Eve Eve")
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

ave = sum(a) / N

aa =[abs(a[i] - ave) for i in range(N)]

x = min(aa)

print(aa.find(x))

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

ave = sum(a) / N

aa =[abs(a[i] - ave) for i in range(N)]

x = min(aa)

print(aa.index(x))
Buggy python submission (verdict: Runtime Error):
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

for i in range(N):
	x[i] -= X
if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a

print(abs(a))

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

for i in range(N):
	x[i] -= X
if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	print(abs(a))
Buggy python submission (verdict: Runtime Error):
a, b = list(map(int, input()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))


Fixed submission:
a, b = list(map(int, input().split()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = []
for i in range(N):
	a = i + 1
	b = N - i - 1
	s = sum(list(map,(int, list(str(a))))) + sum(list(map,(int, list(str(b)))))
	L.append(s)
print(min(L))

Fixed submission:
N = int(input())
L = []
for i in range(N - 1):
	a = list(str(i + 1))
	b = list(str(N - i - 1))
	asum = sum(list(map(int, a)))
	bsum = sum(list(map(int, b)))
	
	L.append(asum + bsum)
print(min(L))
Buggy python submission (verdict: Runtime Error):
A, B, C, K = list(map(int, input().split()))
if K % 2 == 0:
	print(A - B)
else:
	print(A - B) * (-1)

Fixed submission:
A, B, C, K = list(map(int, input().split()))
if K % 2 == 0:
	print(A - B)
else:
	print((A - B)  * (-1))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
N = len(s)

slist = []
for i in range(N):
    for j in range(i + 1, N + 1):
        slist.append(s[i:j])

slist = sorted(slist)

if K == 1:
    print(slist[0])
else:
    c = 1
    ss = slist[0]
    for i in range(1, N ** 2):
        if ss != slist[i]:
            c += 1

        if K == c:
            print(slist[i])
            break

        ss = slist[i]

Fixed submission:
s = input()
N = len(s)
K = int(input())
L = []
for i in range(N):
	for j in range(5):
		if i + j < N:
			L.append(s[i:i + j + 1])

L = sorted(L)

sub = ""
x = 0
for i in L:
	if sub != i:
		sub = i
		x += 1
	
	if x == K:
		print(sub)
		break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

x = 0

for i in range(N):
	s = A[i]
	if s == 0:
		x += 1
	for j in range(i + 1, N):
		s += A[j]
		if s == 0:
			x += 1

print(x)

Fixed submission:
from collections import defaultdict

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

d = defaultdict(int)
s = 0
d[0] += 1
for i in range(N):
	s += A[i]
	d[s] += 1

ans = 0
for key in d:
	if d[key] <= 1:
		pass
	else:
		ans += int(d[key] * (d[key] - 1) / 2)

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

#処理内容
def main():
	N = int(input())
	S = []
	for i in range(N):
		s = input()
		S.append(s)
	ans = 0
	for k in range(N):
		judge = "Yes"
		for i in range(N):
			for j in range(N):
				if S[i][(j + k) % N] != S[j][(i + k) % N]:
					judge = "No"
					break
		if judge == "Yes":
			ans += 1
	print(ans * N)

if __name__ == '__main__':
	main()

Fixed submission:
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = []
	for i in range(N):
		s = input()
		S.append(s)
	ans = 0
	for k in range(N):
		judge = "Yes"
		for i in range(N):
			for j in range(N):
				if S[i][(j + k) % N] != S[j][(i + k) % N]:
					judge = "No"
					break
		if judge == "Yes":
			ans += 1
	print(ans * N)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(N):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) == 1:
                c += 1
            else:
                break
        print(S[:26 - c] + S[-1])


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

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(26):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) >= 1:
                c += 1
            else:
                break
        s = sorted(list(S[26 - c:]))
        for i in s:
            if ord(i) > ord(S[-c]):
                key = i
                break

        print(S[:26 - c] + key)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(map(int, input().split()))
y = 0
for i in range(N):
	if S[i] == "Y":
		y = 1
if y == 0:
	print("Three")
else:
	print("Four")

Fixed submission:
N = int(input())
S = list(input().split())
y = 0
for i in range(N):
	if S[i] == "Y":
		y = 1
if y == 0:
	print("Three")
else:
	print("Four")
Buggy python submission (verdict: Time Limit Exceeded):
import queue

H, W = list(map(int, input().split()))
ans = H * W
L = []
for i in range(H):
	s = list(input())
	ans -= s.count("#")
	L.append(s)

length = [[float("inf") for i in range(W)] for j in range(H)]
length[0][0] = 0

def breadth(H, W, q, L, length, goal):
	while True:
		m = q.get()
		x = m[0]
		y = m[1]
		if [x, y] == goal:
			break

		if y - 1 >= 0:
			if length[y - 1][x] > length[y][x] + 1:
				if L[y - 1][x] == ".":
					length[y - 1][x] = length[y][x] + 1
					q.put([x, y - 1])
		if y + 1 <= H - 1:
			if length[y + 1][x] > length[y][x] + 1:
				if L[y + 1][x] == ".":
					length[y + 1][x] = length[y][x] + 1
					q.put([x, y + 1])
		if x - 1 >= 0:
			if length[y][x - 1] > length[y][x] + 1:
				if L[y][x - 1] == ".":
					length[y][x - 1] = length[y][x] + 1
					q.put([x - 1, y])
		if x + 1 <= W - 1:
			if length[y][x + 1] > length[y][x] + 1:
				if L[y][x + 1] == ".":
					length[y][x + 1] = length[y][x] + 1
					q.put([x + 1, y])
	return length[-1][-1]

q = queue.Queue()
q.put([0, 0])
goal = [W - 1, H - 1]
goal_len = breadth(H, W, q, L, length, goal)

if length[H - 1][W - 1] == float("inf"):
	print(-1)
else:
	print(ans - goal_len - 1)


Fixed submission:
import queue

H, W = list(map(int, input().split()))
ans = H * W
L = []
for i in range(H):
	s = list(input())
	ans -= s.count("#")
	L.append(s)

length = [[float("inf") for i in range(W)] for j in range(H)]
length[0][0] = 0

def breadth(H, W, q, L, length, goal):
	while not q.empty():
		m = q.get()
		x = m[0]
		y = m[1]
		if [x, y] == goal:
			break

		if y - 1 >= 0:
			if length[y - 1][x] > length[y][x] + 1:
				if L[y - 1][x] == ".":
					length[y - 1][x] = length[y][x] + 1
					q.put([x, y - 1])
		if y + 1 <= H - 1:
			if length[y + 1][x] > length[y][x] + 1:
				if L[y + 1][x] == ".":
					length[y + 1][x] = length[y][x] + 1
					q.put([x, y + 1])
		if x - 1 >= 0:
			if length[y][x - 1] > length[y][x] + 1:
				if L[y][x - 1] == ".":
					length[y][x - 1] = length[y][x] + 1
					q.put([x - 1, y])
		if x + 1 <= W - 1:
			if length[y][x + 1] > length[y][x] + 1:
				if L[y][x + 1] == ".":
					length[y][x + 1] = length[y][x] + 1
					q.put([x + 1, y])
	return length[-1][-1]

q = queue.Queue()
q.put([0, 0])
goal = [W - 1, H - 1]
goal_len = breadth(H, W, q, L, length, goal)

if length[H - 1][W - 1] == float("inf"):
	print(-1)
else:
	print(ans - goal_len - 1)
Buggy python submission (verdict: Runtime Error):
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

#val = 0

def DFS(G, anstenna, edge_num, have, visit, node):
	cnt = 0
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, anstenna, edge_num, have, visit, i)
			if have[i] == 1:
				cnt += 1
				anstenna[node] += anstenna[i]

	if cnt < edge_num[node] - 1:
		anstenna[node] += edge_num[node] - 1 - cnt
	if anstenna[node] >= 1:
		have[node] = 1

#処理内容
def main():
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)

	if N == 2:
		print(1)
		return

	#DFS
	anstenna = [0] * (N + 1)
	have = [0] * (N + 1)
	edge_num = [len(G.graph[i]) - 1 for i in range(N + 1)]
	visit = ["No"] * (N + 1)
	visit[N] = "Yes"
	s = None
	for i in range(N):
		if edge_num[i] >= 1:
			s = i
			break
	G.add_edge(N, s)
	G.add_edge(s, N)
	edge_num[s] += 1

	DFS(G, anstenna, edge_num, have, visit, N)
	ans = anstenna[N]
	if edge_num[s] == 2:
		cnt = 0
		for i in G.graph[s]:
			if have[i] == 1:
				cnt += 1
		if cnt <= 2:
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

#val = 0

def DFS(G, anstenna, edge_num, have, visit, node):
	cnt = 0
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, anstenna, edge_num, have, visit, i)
			if have[i] == 1:
				cnt += 1
				anstenna[node] += anstenna[i]

	if cnt < edge_num[node] - 1:
		anstenna[node] += edge_num[node] - 1 - cnt
	if anstenna[node] >= 1:
		have[node] = 1

#処理内容
def main():
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		G.add_edge(a, b)
		G.add_edge(b, a)

	if N == 2:
		print(1)
		return

	#DFS
	anstenna = [0] * (N + 1)
	have = [0] * (N + 1)
	edge_num = [len(G.graph[i]) - 1 for i in range(N + 1)]

	if max(edge_num) <= 1:
		print(1)
		return

	visit = ["No"] * (N + 1)
	visit[N] = "Yes"
	s = None
	for i in range(N):
		if edge_num[i] >= 1:
			s = i
			break
	G.add_edge(N, s)
	G.add_edge(s, N)
	edge_num[s] += 1

	DFS(G, anstenna, edge_num, have, visit, N)
	ans = anstenna[N]
	if edge_num[s] == 2:
		cnt = 0
		for i in G.graph[s]:
			if have[i] == 1:
				cnt += 1
		if cnt <= 2:
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
S = list(input())
S[3] = 8
print("".join(S))

Fixed submission:
S = list(input())
S[3] = "8"
print("".join(S))
Buggy python submission (verdict: Runtime Error):
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)

for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_left(p2017, r)
	if p2017[b] == r:
		b += 1
	print(b - a)

Fixed submission:
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)


for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_right(p2017, r)
	print(b - a)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

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

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			X.append(l)
			judge = "y"
		else:
			judge == "y"
			Y.append(l)
			judge = "x"
		l =0

if judge == "x":
	X.append(l)
else:
	Y.append(l)


dx = defaultdict(int)
dx[X[0]] = 1
X.remove(X[0])
for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] >= 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D

dy = defaultdict(int)
dy[Y[0]] = 1
dy[-Y[0]] = 1
Y.remove(Y[0])
for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] >= 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")

Fixed submission:
from collections import defaultdict

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

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			if l != 0:
				X.append(l)
			judge = "y"
		else:
			if l != 0:
				Y.append(l)
			judge = "x"
		l = 0

if judge == "x":
	if l != 0:
		X.append(l)
else:
	if l != 0:
		Y.append(l)

jj = "bad"
if len(s) >= 2:
	if s[0] == "T":
		jj = "good"


dx = defaultdict(int)
if X != []:
	if jj == "good":
		dx[X[0]] = 1
		dx[-X[0]] = 1
	else:
		dx[X[0]] = 1
	X.remove(X[0])
else:
	dx[0] = 1

for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] == 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D


dy = defaultdict(int)
if Y != []:
	dy[Y[0]] = 1
	dy[-Y[0]] = 1
	Y.remove(Y[0])
else:
	dy[0] = 1

for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] == 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
judge = "YES"
for i in range(M):
	if D.count(T[i]) >= 1:
		D.remove(T[i])
	else:
		judge = "NO"
		break

print(judge)

Fixed submission:
from collections import defaultdict

d = defaultdict(int)

N = int(input())
D = list(map(int, input().split()))

for key in D:
	d[key] += 1

M = int(input())
T = list(map(int, input().split()))

judge = "YES"
for key in T:
	if d[key] >= 1:
		d[key] -= 1
	else:
		judge = "NO"
		break

print(judge)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for i in range(N):
	A = input()
	if L.count(A) == 0:
		L.append(A)
	else:
		L.remove(A)

print(len(L))

Fixed submission:
N = int(input())
A = []
for i in range(N):
	A.append(int(input()))

A = sorted(A)

x = A[0]
s = 0
c = 0
for i in range(N):
	if A[i] == x:
		c += 1
	else:
		x = A[i]
		if c % 2 == 1:
			s += 1
		c = 1

if c % 2 == 1:
	s += 1

print(s)
Buggy python submission (verdict: Runtime Error):
H, W = list(map(int, input().split()))
N = int(input())
A = []
a = list(map(int, input().split()))
for i in range(N):
    A += [a[i]] * (i + 1)

L = [[0 for i in range(W)] for j in range(H)]
for i in range(H * W):
    if int((i // W)) % 2 == 0:
        L[int((i // W))][i % W] = A[i]
    else:
        L[int((i // W))][-1 - i % W] = A[i]

for i in range(H):
    L[i] = list(map(str, L[i]))


for i in range(H):
    print(" ".join(L[i]))

Fixed submission:
H, W = list(map(int, input().split()))
N = int(input())
A = []
a = list(map(int, input().split()))
for i in range(N):
    A += [i + 1] * a[i]

L = [[0 for i in range(W)] for j in range(H)]
for i in range(H * W):
    if int((i // W)) % 2 == 0:
        L[int((i // W))][i % W] = A[i]
    else:
        L[int((i // W))][-1 - i % W] = A[i]

for i in range(H):
    L[i] = list(map(str, L[i]))


for i in range(H):
    print(" ".join(L[i]))
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

if N == 1:
	x = a
else:
	a = A[0]
	for i in range(N - 1):
		b = A[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	x = a

if K % x == 0 and max(A) >= K:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

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

if N == 1:
	x = A[0]
else:
	a = A[0]
	for i in range(N - 1):
		b = A[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	x = a

if K % x == 0 and max(A) >= K:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	# k番目の値にxを加算
	def add(self, k, x):
		k += self.N0 - 1
		self.data[k] += x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, K = getlist()
	A = []
	for i in range(N):
		a = int(input())
		A.append(a)

	# K引く
	for i in range(N):
		A[i] -= K
	
	# 累積和
	B = [0]
	for i in range(N):
		B.append(B[-1] + A[i])

	# 座圧
	C = list(set(B))
	C.sort()
	D = defaultdict(int)
	for i in range(len(C)):
		D[C[i]] = i

	# 座標変換
	for i in range(N + 1):
		B[i] = D[B[i]]

	# セグ木
	ans = 0
	Seg = SegmentTree(N)
	for i in range(N + 1):
		b = B[i]
		val = Seg.query(0, b)
		ans += val
		Seg.add(b, 1)

	print(ans)


if __name__ == '__main__':
	main()

Fixed submission:
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	# k番目の値にxを加算
	def add(self, k, x):
		k += self.N0 - 1
		self.data[k] += x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, K = getlist()
	A = []
	for i in range(N):
		a = int(input())
		A.append(a)

	# K引く
	for i in range(N):
		A[i] -= K
	
	# 累積和
	B = [0]
	for i in range(N):
		B.append(B[-1] + A[i])

	# 座圧
	C = list(set(B))
	C.sort()
	D = defaultdict(int)
	for i in range(len(C)):
		D[C[i]] = i

	# 座標変換
	for i in range(N + 1):
		B[i] = D[B[i]]

	# セグ木
	ans = 0
	Seg = SegmentTree(N + 1)
	for i in range(N + 1):
		b = B[i]
		val = Seg.query(0, b)
		ans += val
		Seg.add(b, 1)

	print(ans)


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
L = []
for i in range(N):
	a, b = list(map(int, input().split()))
	for j in range(b):
		L.append(a)
L = sorted(L)
print(L[K - 1])

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

L = []
for i in range(100000):
	L.append(0)

for i in range(N):
	a, b = list(map(int, input().split()))
	L[a - 1] += b

sm = 0
for i in range(100000):
	sm += L[i]
	if sm >= K:
		print(i + 1)
		break