Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_lst = list(map(int, input().split()))

for i in range(n):
  d = 0
  lst = a_lst[:i] + a_lst[i+1:]
  for i, elem in enumerate(lst):
    if i == 0:
      d += abs(elem)
    else:
      d += abs(elem - lst[i-1])
  d += abs(lst[-1])
  print(d)

Fixed submission:
n = int(input())
a = [0]
a += list(map(int, input().split()))
a.append(0)
d = []
for i in range(n + 1):
  d.append(abs(a[i] - a[i + 1]))
s = sum(d)
for i in range(n):
  print(s - d[i] - d[i + 1] + abs(a[i] - a[i + 2]))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input())
if n >= 2:
  if m >= 2:
    print((n-2) * (m-2)) 
  else:
    print((n-2) * m)
else:
  if m >= 2:
    print(n * (m-2)) 
  else:
    print(n * m) 

Fixed submission:
n, m = map(int, input().split())
if n >= 2:
  if m >= 2:
    print((n-2) * (m-2)) 
  else:
    print((n-2) * m)
else:
  if m >= 2:
    print(n * (m-2)) 
  else:
    print(n * m)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input())
print((n-2) * (m-2))

Fixed submission:
n, m = map(int, input().split())
if n >= 2:
  if m >= 2:
    print((n-2) * (m-2)) 
  else:
    print((n-2) * m)
else:
  if m >= 2:
    print(n * (m-2)) 
  else:
    print(n * m)
Buggy python submission (verdict: Runtime Error):
s = input()

y, m, d = s.split("/")
print("2018/" + m + "/" d)

Fixed submission:
s = input()

y, m, d = s.split("/")
print("2018/" + m + "/" + d)

Buggy python submission (verdict: Runtime Error):
s = input()

y, m, d = s.split("/")
print("2018/" m + "/" d)

Fixed submission:
s = input()

y, m, d = s.split("/")
print("2018/" + m + "/" + d)
Buggy python submission (verdict: Time Limit Exceeded):
q = int(input())
l_lst = []
r_lst = []
for i in range(q):
  l, r = map(int, input().split())
  l_lst.append(l)
  r_lst.append(r)
max_ = max(r_lst)

primes = [2]
for L in range(3, max_+1, 2):
    for L2 in primes:
        if L % L2 == 0:
            break
    else:
        primes.append(L)
        
for l, r in zip(l_lst, r_lst):
  cnt = 0
  for j in range(l, r+1):
    if j in primes and (j+1)//2 in primes:
      cnt += 1
  print(cnt)
      


Fixed submission:
flag = [False]*100001
c = [0]*100002
n = int(input())

for i in range(2,100000):
    if(not(flag[i])):
        for j in range(i+i,100000,i):
            flag[j] = True

for i in range(3,100000,2):
    if(not(flag[i]) and not(flag[(i+1)//2])):
        c[i]+=1
for i in range(3,100000):
    c[i]+=c[i-1]

while(n):
    n-=1
    l,r = map(int,input().split())
    print(c[r]-c[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
q = int(input())
primes = [2]
for L in range(3, 100000, 2):
    for L2 in primes:
        if L % L2 == 0:
            break
    else:
        primes.append(L)

for i in range(q):
  cnt = 0
  l, r = map(int, input().split())
  for j in range(l, r+1):
    if j in primes and (j+1)//2 in primes:
      cnt += 1
  print(cnt)

Fixed submission:
flag = [False]*100001
c = [0]*100002
n = int(input())

for i in range(2,100000):
    if(not(flag[i])):
        for j in range(i+i,100000,i):
            flag[j] = True

for i in range(3,100000,2):
    if(not(flag[i]) and not(flag[(i+1)//2])):
        c[i]+=1
for i in range(3,100000):
    c[i]+=c[i-1]

while(n):
    n-=1
    l,r = map(int,input().split())
    print(c[r]-c[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_lst = [int(elem) for elem in input().split()]

keys = list(set(a_lst))
cnt = 0
for k in keys:
  if a_lst.count(k) > k:
    cnt += a_lst.count(k) - k
  elif a_lst.count(k) < k:
    cnt += a_lst.count(k)
print(cnt)

Fixed submission:
import collections

n = int(input())
a_lst = [int(elem) for elem in input().split()]

c = collections.Counter(a_lst)
cnt = 0

for k in c.keys():
  if c[k] > k:
    cnt += c[k] - k
  elif c[k] < k:
    cnt += c[k]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace('?' * len(t), t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

if flag == 0:
  for i in range(0, 2 ** len(t)):
    tmp = '0' * (len(t) - len(bin(i)[2:])) + bin(i)[2:]
    lst = []
    for j, elem in enumerate(tmp):
      if elem == '0':
        lst.append('?')
      else:
        lst.append(t[j])
    tmp2 = ''.join(lst)
    if tmp2 in s:
      s = s[::-1]
      s = s.replace(tmp2[::-1], t[::-1], 1)
      s = s.replace('?', 'a')
      print(s[::-1])
      flag = 1
      break      
    
if flag == 0:
	print('UNRESTORABLE')

Fixed submission:
S,T=input(),input()
l,m=len(S),len(T)
 
for i in range(l-m+1):
  if all(c in"?"+d for c,d in zip(S[-i-m:],T)):
    S=S.replace("?","a")
    print(S[:-i-m]+T+S[l-i:])
    quit()
 
print("UNRESTORABLE")

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace((t[:i] + '?' * (len(t) - i))[::-1], t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

if flag == 0:
  for i in range(0, len(t)):
    for j in range(i+1, len(t)):
      if ('?' * i + t[i:j] + '?' * (len(t) - j)) in s:
        s = s[::-1]
        s = s.replace((t[:i] + '?' * (len(t) - i))[::-1], t[::-1], 1)
        s = s.replace('?', 'a')
        print(s[::-1])
        flag = 1
        break
    
if flag == 0:
	print('UNRESTORABLE')

Fixed submission:
S,T=input(),input()
l,m=len(S),len(T)
 
for i in range(l-m+1):
  if all(c in"?"+d for c,d in zip(S[-i-m:],T)):
    S=S.replace("?","a")
    print(S[:-i-m]+T+S[l-i:])
    quit()
 
print("UNRESTORABLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_lst = input().split()
b = []

for i, a in enumerate(a_lst):
  if i % 2 == 0:
    b.append(a)
  else:
    b = [a] + b
if n % 2 == 0:
  print(' '.join(b))
else:
  print(' '.join(list(reversed(b))))

Fixed submission:
n = int(input())
a_lst = input().split()
odd = [a for i, a in enumerate(a_lst) if i % 2 != 0]
even = [a for i, a in enumerate(a_lst) if i % 2 == 0]

if n % 2 == 0:
  b = list(reversed(odd)) + even
else:
  b = list(reversed(even)) + odd
print(' '.join(b))
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
fac_n = math.factorial(n)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
print(len(make_divisors(fac_n)) % (10**9+7))

Fixed submission:
def solve():
    n = int(input())
    keta = [0] * (n+1)
    for i in range(2, n+1):
        for j in range(2, int(pow(i, 0.5))+1):
            if i % j: continue
            ex = 0
            while i % j == 0:
                i = i // j
                ex += 1
            keta[j] += ex
        if i != 1:
            keta[i] += 1

    mod = 1000000007
    ans = 1
    for ex in keta:
        ans = ans * (ex + 1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
fac_n = math.factorial(n)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
print(len(make_divisors(fac_n)) % (10**9+7))

Fixed submission:
def solve():
    n = int(input())
    keta = [0] * (n+1)
    for i in range(2, n+1):
        for j in range(2, int(pow(i, 0.5))+1):
            if i % j: continue
            ex = 0
            while i % j == 0:
                i = i // j
                ex += 1
            keta[j] += ex
        if i != 1:
            keta[i] += 1

    mod = 1000000007
    ans = 1
    for ex in keta:
        ans = ans * (ex + 1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
fac_n = math.factorial(n)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
print(len(make_divisors(fac_n)))

Fixed submission:
def solve():
    n = int(input())
    keta = [0] * (n+1)
    for i in range(2, n+1):
        for j in range(2, int(pow(i, 0.5))+1):
            if i % j: continue
            ex = 0
            while i % j == 0:
                i = i // j
                ex += 1
            keta[j] += ex
        if i != 1:
            keta[i] += 1

    mod = 1000000007
    ans = 1
    for ex in keta:
        ans = ans * (ex + 1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
d,t,s=map(int, input().split())
if d/t <= s:
  print("Yes")
else:
  prinst("No")

Fixed submission:
d,t,s=map(int, input().split())
if d/t <= s:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N, X, T = map(int, input.split())
print((N + X - 1) / X * T)

Fixed submission:
N, X, T = map(int, input().split())
print((N + X - 1) // X * T)
Buggy python submission (verdict: Runtime Error):
l, r, d = map(int, input())
print(r // d - (l - 1) // d)

Fixed submission:
l, r, d = map(int, input().split())
print(r // d - (l - 1) // d)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
d = defaultdict(int)
A = list(map(int, input().split()))
for a in A:
    d[a] += 1
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    d[C] += d[B]
    del d[B]
    ans = 0
    for k, v in d.items():
        ans += k * v
    print(ans)

Fixed submission:
from collections import defaultdict

N = int(input())
d = defaultdict(int)
A = list(map(int, input().split()))
for a in A:
    d[a] += 1
Q = int(input())
ans = 0
for k, v in d.items():
    ans += k * v
for _ in range(Q):
    B, C = map(int, input().split())
    d[C] += d[B]
    ans -= B * d[B]
    ans += C * d[B]
    del d[B]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    ans = 0
else:
    ans = 1
    for a in A:
        ans *= a

    if ans > 10**18:
        ans = -1
print(ans)
    

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    ans = 0
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = map(int, input().split())
ans = 1
for a in A:
    ans *= a

if ans > 10**18:
    ans = -1
print(ans)
    

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    ans = 0
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
H1, M1, H2, M2, K = map(int, input().split())
ans = 60*H2+M2 - 60*H1+M1
print(ans)H1, M1, H2, M2, K = map(int, input().split())
ans = 60*H2+M2 - 60*H1+M1 - K
print(ans)

Fixed submission:
H1, M1, H2, M2, K = map(int, input().split())
ans = 60*H2+M2 - (60*H1+M1) - K
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    L = A[A[i] + i + 1:]
    for j in range(len(L)):
        if j+1 == L[j]:
            ans += 1
print(ans)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ans = 0
l = []
r = []
for i,j in enumerate(A):
    l.append(i+j)
    r.append(i-j)

b = Counter(r)
for i in l:
    ans += b.get(i,0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(Q)]
L.sort(key=lambda x: x[0])
ans = 0
for bit in range(1 << Q):
    sumnum = 0
    flag = True
    A = [0]*(N+1)
    s = set()
    for i in range(Q):
        if bit & (1 << i):
            if not L[i][0]-1 in s:
                s.add(L[i][0]-1)
            if not L[i][1]-1 in s:
                s.add(L[i][1]-1)
                A[L[i][1]-1] = A[L[i][0]-1]+L[i][2]
            if L[i][1]-1 in s:
                if A[L[i][1]-1] - A[L[i][0]-1] != L[i][2]:
                    flag = False
                    break
                else:
                    sumnum += L[i][3]
    
    if flag:
        ans = max(ans, sumnum)

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**7) 
N,M,Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int, input().split())

ans = 0
def dfs(L):
    global ans
    if len(L) == N+1:
        sumnum = 0
        for i in range(Q):
            if L[b[i]] - L[a[i]]==c[i]:
                sumnum += d[i]
        ans = max(ans, sumnum)
        return 0
    A = L.copy()
    A.append(A[-1])
    while A[-1] <= M:
        dfs(A)
        A[-1]+=1

dfs([1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
 
sum_of_digits = 0
cnts = [0]*2019
cnts[0] = 1
 
d = 1
 
for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    cnts[sum_of_digits] += 1
 
ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
 
print(ans)

Fixed submission:
s = input()[::-1]

sum_of_digits = 0
cnts = [0]*2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s = [0]*(len(S)+1)
for i in range(len(S)):
    s[i+1] = s[i] +int(S[i])
L1 = []
L2 = []
L3 = []
for i in range(len(s)):
    if s[i]%3==0:
        L1.append(i)
    if s[i]%3==1:
        L2.append(i)
    if s[i]%3==2:
        L3.append(i)

count = 0
for i in range(len(L1)):
    for j in range(i+1,len(L1)):
        if int(S[L1[i]:L1[j]])%2019 == 0:
            count += 1
for i in range(len(L2)):
    for j in range(i+1,len(L2)):
        if int(S[L2[i]:L2[j]])%2019 == 0:
            count += 1
for i in range(len(L3)):
    for j in range(i+1,len(L3)):
        if int(S[L3[i]:L3[j]])%2019 == 0:
            count += 1
print(count)

Fixed submission:
s = input()[::-1]

sum_of_digits = 0
cnts = [0]*2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
S = [input() for i in range(N)]
ans = collections.defaultdict(int)
for i in S:
  ans[i] += 1
  
max_list = [kv[0] for kv in ans.items() if kv[1] == max(ans.values())] 
max_list.sort()
for i in max_list:
  print(i)

Fixed submission:
import collections
N = int(input())
S = [input() for i in range(N)]
ans = collections.defaultdict(int)
for i in S:
  ans[i] += 1
  
max_num = max(ans.values())
max_list = [kv[0] for kv in ans.items() if kv[1] == max_num] 
max_list.sort()
for i in max_list:
  print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    s = str(i)
    num = [0]*3
    if len(s) == 1:
        num[2] = i
    elif len(s) == 2:
        num[1] = int(s[0])
        num[2] = int(s[1])
    else:
        num[0] = int(s[0])
        num[1] = int(s[1])
        num[2] = int(s[2])
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start,N):
            if num[j] == int(S[k]):
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break    
    if flag2:
        ans+=1
    
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start,N):
            if num[j] == S[k]:
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break    
    if flag2:
        ans+=1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    s = str(i)
    num = [0]*3
    if len(s) == 1:
        num[2] = i
    elif len(s) == 2:
        num[1] = int(s[0])
        num[2] = int(s[1])
    else:
        num[0] = int(s[0])
        num[1] = int(s[1])
        num[2] = int(s[2])
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start,N):
            if num[j] == int(S[k]):
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break    
    if flag2:
        ans+=1
    
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start,N):
            if num[j] == S[k]:
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break    
    if flag2:
        ans+=1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7) 

def dfs(G,v,p):
    if v != p and p != -1:
        counter[v]+=counter[p]

    for next in G[v]:
        if next == p:
            continue
        dfs(G,next,v)
    

N,Q = map(int, input().split())
counter = [0]*N
G = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

#print(subtree)
for _ in range(Q):
    p,x = map(int, input().split())
    p-=1
    counter[p]+=x
dfs(G,0,-1)
counter = map(str,counter)
print(' '.join(counter))

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

def dfs(G,v,p):
    for next in G[v]:
        if next == p:
            continue
        counter[next]+=counter[v]
        dfs(G,next,v)
    

N,Q = map(int, input().split())
counter = [0]*N
G = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

#print(subtree)
for _ in range(Q):
    p,x = map(int, input().split())
    p-=1
    counter[p]+=x
dfs(G,0,-1)
counter = map(str,counter)
print(' '.join(counter))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7) 

def dfs(G,v,p):
    for next in G[v]:
        if next == p:
            continue
        dfs(G,next,v)
    
    for c in G[v]:
        if c == p:
            continue
        subtree[v].append(c)
        subtree[v]+=subtree[c]

N,Q = map(int, input().split())
counter = [0]*N
G = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

subtree = [[] for _ in range(N)]
dfs(G,0,-1)
#print(subtree)
for _ in range(Q):
    p,x = map(int, input().split())
    p-=1
    counter[p]+=x
    for i in subtree[p]:
        counter[i]+=x
counter = map(str,counter)
print(' '.join(counter))

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

def dfs(G,v,p):
    for next in G[v]:
        if next == p:
            continue
        counter[next]+=counter[v]
        dfs(G,next,v)
    

N,Q = map(int, input().split())
counter = [0]*N
G = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

#print(subtree)
for _ in range(Q):
    p,x = map(int, input().split())
    p-=1
    counter[p]+=x
dfs(G,0,-1)
counter = map(str,counter)
print(' '.join(counter))
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x*y) // math.gcd(x,y)
A, B, C, D = map(int,input().split())
L = lcm(C,D)
#A-1以下のCorDで割り切れる個数
a = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
#B以下のCorDで割り切れる個数
b = B//C + B//D - B//lcm(C,D)
ans = B-(A-1) - (b-a)
print(ans)

Fixed submission:
import fractions
def lcm(x, y):
    return (x*y) // fractions.gcd(x,y)
A, B, C, D = map(int,input().split())
L = lcm(C,D)
#A-1以下のCorDで割り切れる個数
a = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
#B以下のCorDで割り切れる個数
b = B//C + B//D - B//lcm(C,D)
ans = B-(A-1) - (b-a)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
count = [0]*N
for i in range(M):
    L, R = map(int, input().split())
    for i in range(L, R+1):
        count[i-1] += 1
ans = 0
for i in count:
    if i == M:
        ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
maxL = 0
minR = float('inf')
for i in range(M):
    L, R = map(int, input().split())
    maxL = max(maxL, L)
    minR = min(minR, R)
if minR - maxL >= 0:
    print(minR - maxL + 1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush, heapify
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append((B, C))
heapify(A)
BC = sorted(BC, key = lambda x: -x[1])

for b, c in BC:
    for j in range(b):
        a = heappop(A)
        if a < c:
            heappush(A, c)
        else:
            heappush(A, a)

print(sum(A))

Fixed submission:
from heapq import heappop, heappush, heapify
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    B, C = map(int, input().split())
    BC.append((B, C))
heapify(A)
BC = sorted(BC, key = lambda x: -x[1])

for b, c in BC:
    for j in range(b):
        a = heappop(A)
        if a < c:
            heappush(A, c)
        else:
            heappush(A, a)
            break

print(sum(A))
Buggy python submission (verdict: Runtime Error):
N, K = map(int(input().split()))
if N >= k * 2 - 1:
  print("YES")
else:
  print("NO")

Fixed submission:
N, K = map(int, input().split())
if N >= K * 2 - 1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a, b, c = input(), input(), input()
ans = 0
for i in range(n):
  ans += len(set(a[i], b[i], c[i])) - 1
print(ans)

Fixed submission:
n = int(input())
a, b, c = input(), input(), input()
ans = 0
for i in range(n):
  ans += len(set([a[i], b[i], c[i]])) - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
if len(s) == 3:
  s.reverse()
print(s)

Fixed submission:
s = input()
if len(s) == 3:
  s = s[::-1]
print(s)
Buggy python submission (verdict: Runtime Error):
S = input()
K = input() 
if S[int(K)-1] == '1':
    ans = 1
else:
    for i in range(len(S)):
        if S[i] != '1':
            ans = int(S[i])
            break
print(ans)

Fixed submission:
S = input()
K = input() 
ans = 1
if not all([i == '1' for i in S[:int(K)]]):
    for i in range(len(S)):
        if S[i] != '1':
            ans = int(S[i])
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in C:
    index = bisect.bisect_left(B,i)
    for j in range(index):
        index2 = bisect.bisect_left(A,B[j])
        ans += index2
print(ans)

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

mid_list = [0]*N
for i in range(N):
    index = bisect.bisect_left(A,B[i])
    if i == 0:
        mid_list[i] = index
    else:
        mid_list[i] = mid_list[i-1] + index

ans = 0
for i in range(N):
    index = bisect.bisect_left(B,C[i])
    if index == 0:
        continue
    ans += mid_list[index-1]

print(ans)