Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd
n, m = map(int, input().split())
H = [0] + list(map(int, input().split()))
#print(H)

dic_road = dd(set)
for i in range(m):
    a, b = map(int, input().split())
    dic_road[a].add(b)
    dic_road[b].add(a)

counter = 0
#highest = set()
not_highest = set()
for tenobo in range(1, n+1):
    if tenobo in not_highest:
        continue
    for compare in list(dic_road[tenobo]):
        if H[tenobo] <= H[compare]:
            break
    else:
        counter += 1
        not_highest = not_highest | dic_road[tenobo]

print(counter)

Fixed submission:
from collections import defaultdict as dd

n, m = map(int, input().split())
H = [0] + list(map(int, input().split()))
# print(H)

road = set()
for i in range(m):
    a, b = map(int, input().split())
    road.add((a, b))

counter = 0
not_highest = set()
for a, b in road:
    if H[a] == H[b]:
        not_highest.add(a)
        not_highest.add(b)
    elif H[a] > H[b]:
        not_highest.add(b)
    elif H[b] > H[a]:
        not_highest.add(a)

print(n - len(not_highest))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd
n = int(input())
A = list(map(int, input().split()))

dic = dd(lambda: set())
for index, val in enumerate(A):
    if val < 2 * 10**5:
        dic[val].add(index)

counter = 0
for index, val in enumerate(A):
    for val_cand in dic.keys():
         if index + val + val_cand in dic[val_cand]:
             counter += 1
print(counter)

Fixed submission:
from collections import defaultdict as dd
n = int(input())
A = list(map(int, input().split()))

L = dd(set)
R = dd(set)
for i, a in enumerate(A):
    x = i + a
    L[x].add(i)
    x = i - a
    R[x].add(i)

#print(L)
#print(R)

counter = 0
for num in list(set(L.keys()) & set(R.keys())):
    counter += len(L[num]) * len(R[num])

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
ac = [0]
for i in range(len(s)):
    char = s[i]
    digit = len(s) - i - 1
    ac.append((ac[-1] + (int(char) * 10**digit)) % 2019)
#print(ac)

C = Counter(ac)
#print(C)
ans = 0
for val in C.values():
    ans += val * (val - 1) // 2
print(ans)

Fixed submission:
from collections import Counter
s = input()
ac = [0]

def power_func(a,b,p):
    """a^b mod 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

for i in range(len(s)):
    char = s[i]
    digit = len(s) - i - 1
    ac.append((ac[-1] + (int(char) * power_func(10, digit, 2019))) % 2019)
#print(ac)

C = Counter(ac)
#print(C)
ans = 0
for val in C.values():
    ans += val * (val - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
counter = 0
for left in range(len(s)):
    mod = 0
    for right in range(left, len(s)):
        mod *= 10
        mod += int(s[right])
        mod %= 2019
        if mod == 0:
            counter += 1
print(counter)

Fixed submission:
from collections import Counter
s = input()
ac = [0]

def power_func(a,b,p):
    """a^b mod 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

for i in range(len(s)):
    char = s[i]
    digit = len(s) - i - 1
    ac.append((ac[-1] + (int(char) * power_func(10, digit, 2019))) % 2019)
#print(ac)

C = Counter(ac)
#print(C)
ans = 0
for val in C.values():
    ans += val * (val - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

counter = 0
for right in range(1, len(s)+1):
  for left in range(0, right):
    if int(s[left : right]) % 2019 == 0:
      counter += 1
print(counter)

Fixed submission:
from collections import Counter
s = input()
ac = [0]

def power_func(a,b,p):
    """a^b mod 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

for i in range(len(s)):
    char = s[i]
    digit = len(s) - i - 1
    ac.append((ac[-1] + (int(char) * power_func(10, digit, 2019))) % 2019)
#print(ac)

C = Counter(ac)
#print(C)
ans = 0
for val in C.values():
    ans += val * (val - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
from itertools import combinations as cmb
counter = 0
for i, j, k in cmb(list(range(n)), 3):
  #print(i, j, k, s[i], s[j], s[k])
  if j - i != k - j and s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
    counter += 1
    #print("OK")
print(counter)

Fixed submission:
n = int(input())
s = input()

r_total = s.count("R")
g_total = s.count("G")
b_total = s.count("B")

r_c = []
g_c = []
b_c = []

for moji in s:
  if moji == "R":
    r_total -= 1
  if moji == "G":
    g_total -= 1
  if moji == "B":
    b_total -= 1
  r_c.append(r_total)
  g_c.append(g_total)
  b_c.append(b_total)

color_dic = {"R": r_c, "G": g_c, "B": b_c}
#print(color_dic)
  
from itertools import combinations as cmb
counter = 0
RGB = set(["R", "G", "B"])
for i, j in cmb(list(range(n)), 2):
  #print(i, j, s[i], s[j])
  if s[i] != s[j]:
    rest_color = list(RGB - set([s[i], s[j]]))[0]
    #print(rest_color)
    counter += color_dic[rest_color][j]
    try:
      if s[2 * j - i] == rest_color:
        counter -= 1
    except IndexError:
      pass
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
dic = {0: input()}
left = 0
right = 0
rev = False
q = int(input())
for i in range(q):
  query = input()
  if query[0] == "1":
    #反転
    for i in range(len(dic) // 2):
      dic[left + i], dic[right - i] = dic[right - i], dic[left + i]
    if rev == True:
      rev = False
    else:
      rev = True
  elif query[0] == "2":
    #追加
    num, front, c = query.split()
    if front == "1":
      dic[left - 1] = c
      left -= 1
    elif front == "2":
      dic[right + 1] = c
      right += 1

#出力
for i in range(left, right+1):
  string = dic[i]
  if len(string) > 1 and rev == True:
    string = string[::-1]
  print(string, end="")
print()

Fixed submission:
from collections import deque
s = list(input())
moji = deque(s)

is_forward = True

q = int(input())
for i in range(q):
    query = input()
    if query[0] == "1":
        is_forward = is_forward ^ 1
    elif query[0] == "2":
        _, f, c = query.split()
        f = int(f)
        f %= 2
        is_end = f ^ is_forward
        if is_end:
            moji.append(c)
        else:
            moji.appendleft(c)

if is_forward == False:
    moji = list(moji)[::-1]
print("".join(moji))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
P = list(map(int, input().split()))

counter = 0
for i in range(n):
  for j in range(i):
    if P[i] > P[j]:
      break
  else:
    counter += 1
print(counter)

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

min_val = P[0]
counter = 0
for i in range(n):
  min_val = min(P[i], min_val)
  if min_val == P[i]:
    counter += 1
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
Robo = []
for i in range(n):
  x, leng = map(int, input().split())
  Robo.append([x - leng + 1, x + leng - 1])
Robo.sort(key=lambda x: x[1])
#print(Robo)

Robo_r = []
for robo_cand in Robo:
  l, r = robo_cand
  for robo_r in Robo_r:
    if l <= robo_r[1]:
      break
  else:
    Robo_r.append(robo_cand)
print(len(Robo_r))

Fixed submission:
n = int(input())

Robo = []
for i in range(n):
    x, l = map(int, input().split())
    Robo.append([x-l, x+l])
Robo.sort(key=lambda x: x[1])

#print(Robo)
biggest_right = 2 * -10**9 - 1
counter = 0
for left, right in Robo:
    if biggest_right <= left:
        counter += 1
        biggest_right = max(right, biggest_right)
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
S = [["#"] * (w + 2)]
for i in range(h):
  S.append(["#"] + list(input()) + ["#"])
S.append(["#"] * (w + 2))

def serch(S, x, y):
  ans = []
  cand = [[x-1, y], [x+1, y], [x, y-1], [x, y+1]]
  for pos in cand:
    a, b = pos
    if S[a][b] == ".":
      ans.append(pos)
  return ans

def length(S, i, j):
  S[i][j] = 0
  temp = serch(S, i, j)
  counter = 0
  while len(temp) != 0:
    next_temp = []
    counter += 1
    for pos in temp:
      x, y = pos
      S[x][y] = counter
      next_temp += serch(S, x, y)
    else:
      temp = next_temp
  return counter

import copy
max_l = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if S[i][j] == ".":
      T = copy.deepcopy(S)
      max_l = max(length(T, i, j), max_l)
print(max_l)

Fixed submission:
h, w = map(int, input().split())
S = [["#"] * (w + 2)]
for i in range(h):
  S.append(["#"] + list(input()) + ["#"])
S.append(["#"] * (w + 2))

def serch(S, x, y, next_temp):
  ans = []
  cand = [[x-1, y], [x+1, y], [x, y-1], [x, y+1]]
  for pos in cand:
    a, b = pos
    if S[a][b] == "." and pos not in next_temp:
      ans.append(pos)
  return ans

def length(S, i, j):
  S[i][j] = 0
  temp = serch(S, i, j, [])
  counter = 0
  while len(temp) != 0:
    next_temp = []
    counter += 1
    for pos in temp:
      x, y = pos
      S[x][y] = counter
      next_temp += serch(S, x, y, next_temp)
    else:
      temp = next_temp
  return counter

import copy
max_l = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if S[i][j] == ".":
      T = copy.deepcopy(S)
      max_l = max(length(T, i, j), max_l)
print(max_l)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
X = list(map(int, input().split()))

total = 0
min_sekisan = 1
mod = 10 ** 9 + 7
for i in range(1, n):
    min_sekisan *= i
#print(min_sekisan)

counter = 0
iter = 0
for i in range(n-1):
    iter += 1
    counter += min_sekisan
    total -= (min_sekisan * X[i]) % mod
    min_sekisan *= iter
    min_sekisan //= iter + 1
total += (X[n-1] * counter) % mod
print(total % mod)

"""
from collections import defaultdict as dd
import copy
def count(n):
    lis = [[[i for i in range(1, n + 1)], dd(int)]]
    while len(lis[0][0]) != 1:
        temp = []
        for nums, counter in lis:
            for i in range(len(nums)-1):
                new_dic = copy.deepcopy(counter)
                new_dic[nums[i]] -= 1
                new_dic[nums[i+1]] += 1
                temp.append([nums[:i] + nums[i+1:], new_dic])
        lis = temp
    return lis
#print(count(4))
#print(len(count(4)))

total = dd(int)
for lis, dic in count(7):
    for key, val in dic.items():
        total[key] += val
print(total)
"""

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

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

total = 0
min_sekisan = 1
mod = 10 ** 9 + 7
for i in range(1, n):
    min_sekisan *= i
    min_sekisan %= mod
#print(min_sekisan)

counter = 0
for i in range(n-1):
    counter += min_sekisan
    total -= (min_sekisan * X[i]) % mod
    min_sekisan *= i + 1
    min_sekisan *= mod_inv(i + 2, mod)
    min_sekisan %= mod
total += (X[n-1] * counter) % mod
print(total % mod)

"""
from collections import defaultdict as dd
import copy
def count(n):
    lis = [[[i for i in range(1, n + 1)], dd(int)]]
    while len(lis[0][0]) != 1:
        temp = []
        for nums, counter in lis:
            for i in range(len(nums)-1):
                new_dic = copy.deepcopy(counter)
                new_dic[nums[i]] -= 1
                new_dic[nums[i+1]] += 1
                temp.append([nums[:i] + nums[i+1:], new_dic])
        lis = temp
    return lis
#print(count(4))
#print(len(count(4)))

total = dd(int)
for lis, dic in count(7):
    for key, val in dic.items():
        total[key] += val
print(total)
"""
Buggy python submission (verdict: Runtime Error):
x = int(input())
dp = [False] * (x+1)
dp[0] = 1
for i in range(0, x+1):
    if dp[i]:
        try:
            dp[i + 100] = True
            dp[i + 101] = True
            dp[i + 102] = True
            dp[i + 103] = True
            dp[i + 104] = True
            dp[i + 105] = True
        except IndexError:
            pass

if dp[x]:
    print(1)
else:
    print(0)x = int(input())
dp = [False] * (x+1)
dp[0] = 1
for i in range(0, x+1):
    if dp[i]:
        try:
            dp[i + 100] = True
            dp[i + 101] = True
            dp[i + 102] = True
            dp[i + 103] = True
            dp[i + 104] = True
            dp[i + 105] = True
        except IndexError:
            pass

if dp[x]:
    print(1)
else:
    print(0)

Fixed submission:
x = int(input())
dp = [False] * (x+1)
dp[0] = 1
for i in range(0, x+1):
    if dp[i]:
        try:
            dp[i + 100] = True
            dp[i + 101] = True
            dp[i + 102] = True
            dp[i + 103] = True
            dp[i + 104] = True
            dp[i + 105] = True
        except:
            pass

if dp[x]:
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
Ans = [None] * (n + 1)

top = set()
bottom = set()
if s[0] == ">":
    top.add(0)
else:
    bottom.add(0)

for i in range(len(s)-1):
    left = s[i]
    right = s[i+1]
    if left == "<" and right == ">":
        top.add(i+1)
    elif left == ">" and right == "<":
        bottom.add(i+1)

if s[n-1] == ">":
    bottom.add(n)
else:
    top.add(n)

for b in list(bottom):
    counter = 0
    for i in range(b, n+1):
        if i in top:
            break
        else:
            Ans[i] = counter
            counter += 1

    counter = 0
    for i in range(b-1, -1, -1):
        if i in top:
            break
        else:
            Ans[i] = counter + 1
            counter += 1
#print(Ans)

for t in list(top):
    if t == 0:
        Ans[0] = Ans[1] + 1
    if t == n:
        Ans[n] = Ans[n-1] + 1
    else:
        Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)

#print(top)
#print(bottom)
print(sum(Ans))

Fixed submission:
s = input()
n = len(s)
Ans = [0] * (n + 1)

top = set()
bottom = set()
if s[0] == ">":
    top.add(0)
else:
    bottom.add(0)

for i in range(len(s)-1):
    left = s[i]
    right = s[i+1]
    if left == "<" and right == ">":
        top.add(i+1)
    elif left == ">" and right == "<":
        bottom.add(i+1)

if s[n-1] == ">":
    bottom.add(n)
else:
    top.add(n)

for b in list(bottom):
    counter = 0
    for i in range(b, n+1):
        if i in top:
            break
        else:
            Ans[i] = counter
            counter += 1

    counter = 0
    for i in range(b-1, -1, -1):
        if i in top:
            break
        else:
            Ans[i] = counter + 1
            counter += 1
#print(Ans)

for t in list(top):
    if t == 0:
        Ans[0] = Ans[1] + 1
    if t == n:
        Ans[n] = Ans[n-1] + 1
    else:
        Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)

#print(top)
#print(bottom)
print(sum(Ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def factorize(n):
    b = 2
    fct = []
    end = int(n ** (0.5)) + 2
    for b in range(2, end):
      while n % b == 0:
        n //= b
        fct.append(b)
      if n == 1:
        break
    if n > 1:
      fct.append(n)
    return fct
 
fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range((len(fact) + 1) // 2 + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print(min(dif))

Fixed submission:
n = int(input())

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print(min(dif))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def factorize(n):
    b = 2
    fct = []
    end = int(n ** (0.5)) + 2
    for b in range(2, end):
      while n % b == 0:
        n //= b
        fct.append(b)
      if n == 1:
        break
    if n > 1:
      fct.append(n)
    return fct

fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range((len(fact) + 1) // 2 + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print(min(dif))



Fixed submission:
n = int(input())

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print(min(dif))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range((len(fact) + 1) // 2 + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print(min(dif))


Fixed submission:
n = int(input())

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print(min(dif))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range(len(fact) + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print(min(dif))



Fixed submission:
n = int(input())

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print(min(dif))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = map(int, input().split())

total = 0
from itertools import combinations as cm
for pair in cm(L, 3):
  a, b, c = pair
  if a < b+c and b < c+a and c < a+b:
    total += 1
print(total)

Fixed submission:
import bisect
n = int(input())
L = sorted(list(map(int, input().split())))

counter = 0
for a_pointer in range(len(L)):
    for b_pointer in range(a_pointer+1, len(L)):
        a = L[a_pointer]
        b = L[b_pointer]
        c_left_pointer = max(bisect.bisect_left(L, b - a + 1), b_pointer + 1)
        c_right_pointer = bisect.bisect_right(L, b + a - 1)
        #print(a, b, c_left_pointer, c_right_pointer)
        counter += max(c_right_pointer - c_left_pointer, 0)
        #if c_right_pointer == len(L) and c_right_pointer == len(L):
            #break
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
a, b = map(int, input().split())
OKs = []
 
if min(a, b) == 1:
  print(1)
  sys.exit()
  
for i in range(2, min(a, b) + 1):
  if a % i != 0:
    continue
  if b % i != 0:
    continue  
  for ok in OKs:
    if i % ok == 0:
      break
  else:
    OKs.append(i)
print(len(OKs) + 1)

Fixed submission:
a, b = map(int, input().split())
from collections import defaultdict

def comdiv(n):
  end = int(n**0.5) + 2
  dic = defaultdict(lambda: 0)
  for i in range(2, end):
    while n % i == 0:
      n //= i
      dic[i] += 1
  else:
    if n > 1:
      dic[n] = 1
  return dic

A = comdiv(a).keys()
B = comdiv(b).keys()
C = set(A) & set(B)
print(len(C) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
def cf(x1,x2):
  cf=[]
  for i in range(2,min(x1,x2)+1):
    if x1 % i == 0 and x2 % i == 0:
      cf.append(i)
  return cf

Oks = []
for cand in cf(a,b):
  for div in Oks:
    if cand % div == 0:
      break
  else:
    Oks.append(cand)
print(len(Oks) + 1)

Fixed submission:
a, b = map(int, input().split())
from collections import defaultdict

def comdiv(n):
  end = int(n**0.5) + 2
  dic = defaultdict(lambda: 0)
  for i in range(2, end):
    while n % i == 0:
      n //= i
      dic[i] += 1
  else:
    if n > 1:
      dic[n] = 1
  return dic

A = comdiv(a).keys()
B = comdiv(b).keys()
C = set(A) & set(B)
print(len(C) + 1)
Buggy python submission (verdict: Runtime Error):
def main():
	inp = [int(input()) for i in range(2)]
	a = inp[0]
	s = inp[1]
	red = "red"

  if a < 3200:
    print red
  else:
    print s


Fixed submission:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print("red")

Buggy python submission (verdict: Runtime Error):
inp = [int(input()) for i in range(2)]
a = inp[0]
s = inp[1]
red = "red"

if a < 3200:
  print red
else:
  print s

Fixed submission:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print("red")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
from collections import defaultdict as dd
dic = dd(lambda: 0)

counter = 0
for i in range(n):
  s = input()
  s_s = sorted(s)
  s_s_s = str(s_s)
  counter += dic[s_s_s]
  dic[s_s_s] += 1

print(counter)

Fixed submission:
n = int(input())
from collections import defaultdict as dd
dic = dd(lambda: 0)

counter = 0
for i in range(n):
  s = input()
  s_s = sorted(s)
  s_s_s = "".join(s_s)
  counter += dic[s_s_s]
  dic[s_s_s] += 1

print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
from collections import Counter as cnt
from itertools import combinations as cm
lis = []
for i in range(n):
  count = cnt(list(input()))
  lis.append(count)
  
counter = 0
for pair in cm(lis, 2):
  if pair[0] == pair[1]:
    counter += 1
print(counter)

Fixed submission:
n = int(input())
from collections import defaultdict as dd
dic = dd(lambda: 0)

counter = 0
for i in range(n):
  s = input()
  s_s = sorted(s)
  s_s_s = "".join(s_s)
  counter += dic[s_s_s]
  dic[s_s_s] += 1

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
spotwork = []
for i in range(n):
    spotwork.append(list(map(int, input().split())))

spotwork.sort(key=lambda x: x[1], reverse=True)
#print(spotwork)

shift = [0] * m
for i in range(n):
    delay, payment = spotwork[i]
    for day in range(m - delay, -1, -1):
        if shift[day] == 0:
            shift[day] = payment
            break
print(sum(shift))

Fixed submission:
n, m = map(int, input().split())
import heapq

Work = []
for i in range(n):
    Work.append(list(map(int, input().split())))
Work.sort(key=lambda x: (x[0], x[1]), reverse=True)
#print(Work)

total = 0
job_stock = []
#-1をかけた値を格納
heapq.heapify(job_stock)
for day in range(m, -1, -1):
    allowed_delay = m - day
    try:
        while Work[-1][0] <= allowed_delay:
            delay, money = Work.pop()
            heapq.heappush(job_stock, -money)
    except:
        pass
    if len(job_stock) >= 1:
        job_today = -heapq.heappop(job_stock)
        total += job_today
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = [int(input()) for i in range(m)]
dp = [0] * (n + 1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1

for i in range(2, n+1):
  if i in A:
    dp[i] = 0
  else:
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9 + 7)
print(dp[n])

Fixed submission:
n, m = map(int, input().split())
A = set([int(input()) for i in range(m)])
dp = [0] * (n + 1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1

for i in range(2, n+1):
  if i in A:
    dp[i] = 0
  else:
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9 + 7)
print(dp[n])