Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
K = int(input())
D = [str(i) for i in range(1, 10)]
cnt = 0
while cnt < K:
    v = D.pop(0)
    if v[-1] == "0":
        D.append(v + "0")
        D.append(v + "1")
    elif v[-1] == "9":
        D.append(v+"8")
        D.append(v+"9")
    else:
        D.append(v + str(int(v[-1]) - 1))
        D.append(v + v[-1])
        D.append(v + str(int(v[-1]) + 1))
    cnt += 1
print(v)

Fixed submission:
# coding: utf-8
from collections import deque
K = int(input())
D = [str(i) for i in range(1, 10)]
D = deque(D)
cnt = 0
while cnt < K:
    v = D.popleft()
    if v[-1] == "0":
        D.append(v + "0")
        D.append(v + "1")
    elif v[-1] == "9":
        D.append(v+"8")
        D.append(v+"9")
    else:
        D.append(v + str(int(v[-1]) - 1))
        D.append(v + v[-1])
        D.append(v + str(int(v[-1]) + 1))
    cnt += 1
print(v)
Buggy python submission (verdict: Runtime Error):
import sequtils
from strutils import split, parseInt
from math import ceil

let
  HW = map(readLine(stdin).split(), parseInt)

if HW[0] == 1 or HW[1] == 1:
  echo 1
else:
  echo int(ceil(HW[0] * HW[1] / 2))

Fixed submission:
# coding: utf-8
from math import ceil
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
else:
    ans = 0
    ans += ceil(W / 2) * ceil(H / 2)
    ans += (W // 2) * (H // 2)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        S.reverse()
    else:
        if q[1] == "1":
            S.appendleft(q[2])
        else:
            S.append(q[2])
print("".join(S))


Fixed submission:
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
ans = "".join(S)
print(ans if cnt % 2 == 0 else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        S.reverse()
    else:
        if q[1] == "1":
            S.appendleft(q[2])
        else:
            S.append(q[2])
print("".join(S))


Fixed submission:
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
ans = "".join(S)
print(ans if cnt % 2 == 0 else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S = input()
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":\
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S = q[2] + S
        else:
            S += q[2]
print(S if cnt % 2 == 0 else S[::-1])

Fixed submission:
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
ans = "".join(S)
print(ans if cnt % 2 == 0 else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S = input()
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        S = S[::-1]
    else:
        if q[1] == "1":
            S = q[2] + S
        else:
            S += q[2]
print(S)

Fixed submission:
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
ans = "".join(S)
print(ans if cnt % 2 == 0 else ans[::-1])
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if s not in d.keys():
        d[s-1] = c
        ans[s-1] = str(c)
    else:
        if d[s-1] != c:
            ans = -1
            print(ans)
            exit()
if ans[0] == "0" and 0 not in d.keys():
    ans[0] = "1"
ans = "".join(ans)
if len(str(int(ans))) != N:
    ans = -1
print(ans)

Fixed submission:
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if str(s) not in d.keys():
        d[str(s)] = c
        ans[s-1] = str(c)
    else:
        if d[str(s)] != c:
            print(-1)
            exit()
if N == 1:
    print("".join(ans))
    exit()
if "1" not in d.keys():
    ans[0] = "1"
ans = "".join(ans)
if ans[0] == "0" and N != 1:
    print(-1)
else:
    print(int(ans))

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if s not in d.keys():
        d[s] = c
        ans[s-1] = str(c)
    else:
        if d[s] != c:
            ans = -1
            print(ans)
            exit()
ans = "".join(ans)
if ans[0] == "0" and 1 not in d.keys():
    ans[0] = "1"
if len(str(int(ans))) != N:
    ans = -1
print(ans)

Fixed submission:
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if str(s) not in d.keys():
        d[str(s)] = c
        ans[s-1] = str(c)
    else:
        if d[str(s)] != c:
            print(-1)
            exit()
if N == 1:
    print("".join(ans))
    exit()
if "1" not in d.keys():
    ans[0] = "1"
ans = "".join(ans)
if ans[0] == "0" and N != 1:
    print(-1)
else:
    print(int(ans))

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if s not in d.keys():
        d[s] = c
        ans[s-1] = str(c)
    else:
        if d[s] != c:
            ans = -1
            print(ans)
            exit()
ans = "".join(ans)
if ans[0] == "0" and 0 not in d.keys():
    ans[0] = "1"
print(ans)

Fixed submission:
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if str(s) not in d.keys():
        d[str(s)] = c
        ans[s-1] = str(c)
    else:
        if d[str(s)] != c:
            print(-1)
            exit()
if N == 1:
    print("".join(ans))
    exit()
if "1" not in d.keys():
    ans[0] = "1"
ans = "".join(ans)
if ans[0] == "0" and N != 1:
    print(-1)
else:
    print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, K = map(int, input().split())
P = list(map(int, input().split()))
# P.sort(reverse=True)
l = []
for i in range(N):
    l.append((P[i]+1) / 2)
ans = 0
for i in range(N-K+1):
    ans = max(ans, sum(l[i:i+K]))
print(ans)

Fixed submission:
# coding: utf-8
N, K = map(int, input().split())
P = list(map(int, input().split()))
# P.sort(reverse=True)
l = []
for i in range(N):
    l.append((P[i]+1) / 2)
ans = 0
tmp = sum(l[:K-1])
p = l[0]
idx = 0
for i in range(K-1, N):
    tmp += l[i]
    # print(tmp)
    ans = max(ans, tmp)
    p = l[idx]
    tmp -= p
    idx += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
H, N = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
dp = [float("inf") for _ in range(H+1)] 
dp[0] = 0
for i in range(1, H+1):
    for j in range(N):
        a, b = L[j]
        if i <= a:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i-a] + b)
    # print(*dp)
print(dp[H])

Fixed submission:
# coding: utf-8
H, N = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
dp = [float("inf") for _ in range(H+1)] 
dp[0] = 0
top = 10**9
for i in range(1, H+1):
    for j in range(N):
        a, b = L[j]
        if i <= a:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i-a] + b)
    # print(*dp)
print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
H, N = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
dp = [float("inf") for _ in range(H+1)] 
dp[0] = 0
for i in range(1, H+1):
    for j in range(N):
        a, b = L[j]
        for k in range(i, min(H+1, i+a)):
            if k - a >= 0:
                dp[k] = min(dp[k], dp[i-1] + b)
            else:
                dp[k] = min(dp[k], b)
    # print(*dp)
print(dp[H])

Fixed submission:
# coding: utf-8
H, N = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
dp = [float("inf") for _ in range(H+1)] 
dp[0] = 0
top = 10**9
for i in range(1, H+1):
    for j in range(N):
        a, b = L[j]
        if i <= a:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i-a] + b)
    # print(*dp)
print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
sorted_A = sorted(A)
ans = 0
l = []
if 1 not in A:
    print(-1)
    exit()

i = 0
while True:
    if A == sorted_A:
        print(N - len(set(A)))
        exit()
        break
    if A[i] > sorted_A[i]:
        tmp = A[i]
        A.remove(tmp)
        sorted_A.remove(tmp)
        continue
    i += 1

Fixed submission:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
if 1 not in A:
    print(-1)
    exit()

target = 1
idx = 0
ans = 0
while idx < len(A):
    if A[idx] == target:
        target += 1
        ans += 1
    idx += 1
print(N - ans)
Buggy python submission (verdict: Time Limit Exceeded):
#入力値処理
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a >> i & 1) == 1:
            one += 1
    ans += one * (N - one) * 2 ** i
    ans %= mod
print(ans)


Fixed submission:
#入力値処理
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a >> i & 1) == 1:
            one += 1
    ans += one * (N - one) * 2 ** i
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
bins = [format(i, "b").zfill(60) for i in A]

keta = []
for i in range(60):
    tmp = list(map(int, [r[i] for r in bins]))
    keta.append(tmp[:])
keta.reverse()

ans = 0
for i in range(60):
    s = sum(keta[i])
    ans += s * (N - s) * 2 ** i
print(ans % mod)

Fixed submission:
#入力値処理
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a >> i & 1) == 1:
            one += 1
    ans += one * (N - one) * 2 ** i
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
bins = [format(i, "b").zfill(60) for i in A]

keta = []
for i in range(60):
    tmp = list(map(int, [r[i] for r in bins]))
    keta.append(tmp[:])
keta.reverse()

ans = 0
for i in range(60):
    s = sum(keta[i])
    ans += s * (N - s) * 2 ** i
print(ans % mod)

Fixed submission:
#入力値処理
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a >> i & 1) == 1:
            one += 1
    ans += one * (N - one) * 2 ** i
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i, a1 in enumerate(A[:-1]):
    for a2 in A[i+1:]:
        # print(a1, a2, a1&a2)
        ans += a1 ^ a2
        ans = ans % mod
print(ans)

Fixed submission:
#入力値処理
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a >> i & 1) == 1:
            one += 1
    ans += one * (N - one) * 2 ** i
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import ceil
N = int(input())
t, s = str(N)[:-2], str(N)[-2:]
# print(t, s)
if int(t) >= ceil(int(s)/5):
    print(1)
else:
    print(0)

Fixed submission:
from math import ceil
N = int(input())
if N < 100:
    print(0)
    exit()
t, s = str(N)[:-2], str(N)[-2:]
if int(t) >= ceil(int(s)/5):
    print(1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
diff = []
for i in range(1, N):
    diff.append(abs(sum(A[:i]) - sum(A[i:])))
print(min(diff))

Fixed submission:
# coding: utf-8
from math import ceil
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
half = ceil(sum(A) / 2)
tmp = 0
diff = sum(A)
for i in range(N):
    tmp += A[i]
    total -= A[i]
    if total == tmp:
        print(0)
        exit()
    diff = min(diff, abs(total - tmp))
print(diff)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * N
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

Fixed submission:
# coding: utf-8
N = int(input())
if N % 2 == 0:
    print(N // 2 - 1)
else:
    print(N // 2)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

Fixed submission:
# coding: utf-8
N = int(input())
if N % 2 == 0:
    print(N // 2 - 1)
else:
    print(N // 2)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

Fixed submission:
# coding: utf-8
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
    ans = ans%998244353

if c[0]!=1:
    ans=0
if d[0] != 0:
    ans = 0

# print(c)
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans % mod)

Fixed submission:
# coding: utf-8
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
    ans = ans%998244353

if c[0]!=1:
    ans=0
if d[0] != 0:
    ans = 0

# print(c)
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
    ans = ans%998244353

if c[0]!=1:
    ans=0
if D[0] != 0:
    ans = 0

# print(c)
print(ans)


Fixed submission:
# coding: utf-8
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
    ans = ans%998244353

if c[0]!=1:
    ans=0
if d[0] != 0:
    ans = 0

# print(c)
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import math
a, b, x = map(int, input().split())
print(90 - math.degrees(math.atan(a**3/(2*a**2*b-2*x))))

Fixed submission:
# coding: utf-8
import math
a, b, x = map(int, input().split())
if x >= a**2*b/2:
    ans = 90 - math.degrees(math.atan2(a**3, (2*a**2*b-2*x)))
else:
    # ans = 90 - math.degrees(math.atan2(2*x, (a**2*b-2*x)))
    # ans = 90 - math.degrees(math.asin((2*x*a) / (b*math.sqrt(4*x**2 + a**2*b**4))))
    ans = 90 - math.degrees(math.asin(2*x/math.sqrt(a**2*b**4 + 4*x**2)))
print(ans)
Buggy python submission (verdict: Runtime Error):
#coding: utf-8
N = int(input())
S = input()
ans = 1
for i in range(1, N-1):
    if S[i-1] != S[i]:
        ans += 1
if S[-2] != S[-1]:
    ans += 1
print(ans)

Fixed submission:
# coding: utf-8
N = int(input())
S = input()
ans = 1
for i in range(1, N):
    if S[i-1] != S[i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, M = map(int, input().split())
A = list(map(int, input().split()))
# A.sort(reverse=True)
for i in range(M):
    A.sort(reverse=True)
    A[0] //= 2
print(sum(A))

Fixed submission:
# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: -1 * x, A))
# A.sort(reverse=True)
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, -1 * (-tmp // 2))
print(-sum(A))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
ans = sum(list(range(N)))
print(ans)

Fixed submission:
# coding: utf-8
N = int(input())
ans = N*(N-1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
import streams, sequtils, strutils, algorithm, math, future, sets, tables, hashes
proc `ceilDiv`*[T](x, y: T): T = x div y + ord(x mod y != 0)
proc `//=`*(x: var SomeInteger; y: SomeInteger) = x = x div y
proc `%=`*(x: var SomeInteger; y: SomeInteger) = x = x mod y

var
    L = stdin.readLine.split.map(parseInt)
    N = L[0]
    K = L[1]
    A = stdin.readLine.split.map(parseInt)
    MOD = 10^9 + 7
    ans = 0.int64
    jun = newSeqWith(N, 0)
    inv = newSeqWith(N, 0)
for i in 0..N-1:
    for j in 0..N-1:
        if j < i:
            if A[i] < A[j]:
                jun[i] += 1
        else:
            if A[i] < A[j]:
                inv[i] += 1
for i in 0..N-1:
    ans += K * (((jun[i] * (K+1)) + (inv[i] * (K-1))) div 2)
    ans %= MOD
    # ans += (inv[i] * (K-1)) mod MOD
    # ans %= MOD
echo ans mod MOD

Fixed submission:
# coding: utf-8
N, K = map(int, input().split())
mod = 10**9 + 7
A = list(map(int, input().split()))
l = []
for i in range(N):
    tmp = [0, 0]
    for j in range(N):
        if j < i:
            if A[i] < A[j]:
                tmp[0] += 1
        else:
            if A[i] < A[j]:
                tmp[1] += 1
    l.append(tmp[:])
ans = 0
for i in range(N):
    ans += l[i][0]*K*(K+1) // 2
    ans %= mod
    ans += l[i][1] * K * (K - 1) // 2
    ans %= mod
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
AB = []
heapify(AB)
d = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [-b]
    else:
        d[a].append(-b)
ans = 0
ables = []
now = 1
while now <= M:
    if now in d.keys():
        for v in d[now]:
            heappush(ables, v)
    if len(ables) > 0:
        v = heappop(ables)
        ans += -1 * v
    now += 1
print(ans)

Fixed submission:
# coding: utf-8
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
AB = []
heapify(AB)
d = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [-b]
    else:
        d[a].append(-b)
day = M - 1
ans = 0
ables = []
while day >= 0:
    now = M - day
    if now in d.keys():
        for v in d[now]:
            heappush(ables, v)
    if len(ables) > 0:
        v = heappop(ables)
        ans += -1 * v
    day -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, M = map(int, input().split())
AB = []
d = {}
g = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    # AB.append(tmp[:])
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [b]
        g[a] = [False]
    else:
        d[a].append(b)
        g[a].append(False)
day = 0
ans = 0
for i in range(M):
    good = -1
    flag = False
    for key in list(sorted(d.keys(), reverse=True)):
        if key + day > M:
            continue
        for j in range(len(d[key])):
            if good < d[key][j] and not g[key][j]:
                good = d[key][j]
                idx = key
                jdx = j
                flag = True
    if flag:
        g[idx][jdx] = True
        ans += good
    day += 1
print(ans)

Fixed submission:
# coding: utf-8
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
AB = []
heapify(AB)
d = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [-b]
    else:
        d[a].append(-b)
day = M - 1
ans = 0
ables = []
while day >= 0:
    now = M - day
    if now in d.keys():
        for v in d[now]:
            heappush(ables, v)
    if len(ables) > 0:
        v = heappop(ables)
        ans += -1 * v
    day -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
H = list(map(int, input().split()))
flag = True
top = [-1] * N
for i in range(N):
    if i == 0:
        top[i] = H[i]
    else:
        tmp = top[:i]
        tmp.append(H[i])
        top[i] = max(tmp)
for i, h in enumerate(H):
    if top[i] - h >= 2:
        flag = False
        break
print("Yes" if flag else "No")

Fixed submission:
# coding: utf-8
N = int(input())
H = list(map(int, input().split()))
flag = True
for i in range(1, N):
    if H[i] < H[i-1]:
        flag = False
        break
    else:
        if H[i-1] < H[i]:
            H[i] -= 1
print("Yes" if flag else "No")
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    B = A[:]
    B.pop(i)
    print(max(B))


Fixed submission:
# coding: utf-8
N = int(input())
A = []#value
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
one = B[-1]
two = B[-2]
for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N = int(input())
A = [int(input()) for _ in range(N)]
for i in range(N):
    B = A[:]
    B.pop(i)
    print(max(B))

Fixed submission:
# coding: utf-8
N = int(input())
A = []#value
for i in range(N):
    A.append(int(input()))
B = A[:]
B.sort()
one = B[-1]
two = B[-2]
for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)