Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
num = [0 for _ in range(N)]
for i in range(1, N + 1):
    num[i % K] += 1
ans = 0
for a in range(N):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += num[a] * num[b] * num[c]
print(ans)




Fixed submission:
N, K = map(int, input().split())
num = [0 for _ in range(K)]
for i in range(1, N + 1):
    num[i % K] += 1
ans = 0
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += num[a] * num[b] * num[c]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import numpy as np
N = int(input())
A = list(map(int, input().split()))

A_diff = np.array([a - i for i, a in enumerate(A, 1)])

ans = float("inf")
for i in range(N):
    A_diff_cp = A_diff.copy()
    A_diff_cp += -1 * A_diff[i]
    ans = min(ans, sum(np.abs(A_diff_cp)))

print(ans) # O(N ** 2なので無理ぽい)

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

import numpy as np
N = int(input())
A = list(map(int, input().split()))

A_diff = np.array([a - i for i, a in enumerate(A, 1)])
my_median = np.median(A_diff)

print(int(np.sum(np.abs(A_diff * -1 + my_median))))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
nums = []
for i in range(N):
    nums.append(S[0: i].count("W") + S[i + 1:].count("E"))
print(min(nums))

Fixed submission:
N = int(input())
S = input()
for i in range(N):
    if i == 0:
        num = S[i + 1:].count("E")
        num_min = num
    else:
        if S[i - 1] == "W":
            num += 1
        if S[i] == "E":
            num -= 1
        if num < num_min:
            num_min = num
print(num_min)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
p = list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

unionfind = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    unionfind.union(x, y)
ans = 0
for i in range(N):
    if i + 1 != p[i]:
        if unionfind.same(p[i], i + 1):
            ans += 1
    else:
        ans += 1
print(ans)

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

unionfind = UnionFind(N + 1)

for _ in range(M):
    x, y = map(int, input().split())
    unionfind.union(P[x - 1], P[y - 1])

ans = 0
idx = []
for i in range(N):
    if P[i] == (i + 1):
        ans += 1
    else:
        idx.append(i)
for i in idx:
    if unionfind.same(P[i], i + 1):
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

def main():
    A_max = max(A)
    kaijo_table = [1 for _ in range(A_max + 1)]
    tmp = 1
    for i in range(1, A_max + 1):
        tmp *= i
        kaijo_table[i] = tmp
    my_max = 0
    for a in A:
        if a != A_max:
            tmp = (kaijo_table[A_max] // 
            (kaijo_table[a] * kaijo_table[A_max - a]))
            if my_max <= tmp:
                my_max = tmp
                ans = (A_max, a)
    print(" ".join(map(str, ans)))

if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_sorted = sorted(A)
    A_max = A_sorted[-1]
    A = A_sorted[:-1]
    tansaku = (A_max + 1) // 2
    ok = 0
    ng = len(A) - 1
    if A[ok] > tansaku:
        print(A_max, A[ok])
        exit()
    if A[ng] <= tansaku:
        print(A_max, A[ng])
        exit()
    while ok + 1 < ng:
        center = (ok + ng) // 2
        if A[center] <= tansaku:
            ok = center
        else:
            ng = center
    if tansaku - A[ok] <= A[ng] - tansaku:
        print(A_max, A[ok])
    else:
        print(A_max, A[ng])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n - i
        ans /= (i + 1)
    return ans

def main():
    A_max = max(A)
    my_max = 0
    for a in A:
        if a != A_max:
            if my_max <= binomial_coefficients(A_max, a):
                my_max = binomial_coefficients(A_max, a)
                ans = (A_max, a)
    print(" ".join(map(str, ans)))

if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_sorted = sorted(A)
    A_max = A_sorted[-1]
    A = A_sorted[:-1]
    tansaku = (A_max + 1) // 2
    ok = 0
    ng = len(A) - 1
    if A[ok] > tansaku:
        print(A_max, A[ok])
        exit()
    if A[ng] <= tansaku:
        print(A_max, A[ng])
        exit()
    while ok + 1 < ng:
        center = (ok + ng) // 2
        if A[center] <= tansaku:
            ok = center
        else:
            ng = center
    if tansaku - A[ok] <= A[ng] - tansaku:
        print(A_max, A[ok])
    else:
        print(A_max, A[ng])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter
s = input()
t = input()
s_cnt = sorted(Counter(s).most_common())
t_cnt = sorted(Counter(t).most_common())[::-1]
s_replaced = ""
t_replaced = ""
for k, v in s_cnt:
    s_replaced += k * v 
for k, v in t_cnt:
    t_replaced += k * v 

def judge(s, t):
    for i in range(len(s)):
        if ord(s[i]) > ord(t[i]):
            return False
        if ord(s[i]) < ord(t[i]):
            return True
    if len(s) < len(t):
        return True
    else:
        return False

if judge(s_replaced, t_replaced):
    print("Yes")
else:
    print("No")

Fixed submission:
from collections import Counter
s = input()
t = input()
s_cnt = sorted(Counter(s).most_common())
t_cnt = sorted(Counter(t).most_common())[::-1]
s_replaced = ""
t_replaced = ""
for k, v in s_cnt:
    s_replaced += k * v 
for k, v in t_cnt:
    t_replaced += k * v 

def judge(s, t):
    for i in range(min(len(s), len(t))):
        if ord(s[i]) > ord(t[i]):
            return False
        if ord(s[i]) < ord(t[i]):
            return True
    if len(s) < len(t):
        return True
    else:
        return False

if judge(s_replaced, t_replaced):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N = int(input())
# S = input()
# N, K = map(int, input().split())
P = list(map(int, input().split()))

def main():
    pre = 0
    ans = 0
    for i, p in enumerate(P, 1):
        if i == p:
            ans += 1
            P[i] = p
    print(ans)
    
if __name__ == "__main__":
    main()


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

N = int(input())
# S = input()
# N, K = map(int, input().split())
P = list(map(int, input().split()))

def main():
    ans = 0
    for i, p in enumerate(P, 1):
        if i == p:
            ans += 1
            if i != N:
                P[i] = p
    print(ans)

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

from collections import deque
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)

done = [[True for _ in range(W)] for _ in range(H)]
ans = [[-1 for _ in range(W)] for _ in range(H)]

q = deque([(0, 0, 1)])
color = 1

while q:
    x, y, color = q.pop()
    if A[color] > 0:
        ans[x][y] = color
        A[color] -= 1
    else:
        color += 1
        ans[x][y] = color
        A[color] -= 1

    for i, j in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
        x_next = x + i
        y_next = y + j
        if (0 <= x_next and x_next < H 
        and 0 <= y_next and y_next < W
        and done[x_next][y_next] is True):
            q.append((x_next, y_next, color))

[print(" ".join(map(str, a))) for a in ans]

Fixed submission:
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)

ans = [[-1 for _ in range(W)] for _ in range(H)]
color = 1

for i in range(H):
    for j in range(W):
        if A[color] == 0:
            color += 1
        A[color] -= 1
        ans[i][j] = color

for i in range(H):
    a = ans[i]
    if i % 2 == 1:
        a = a[::-1]
    print(" ".join(map(str, a)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
next = []
for i in range(N):
    next.append(int(input()))
count = 0
history = [1]
while True:
    light = next[history[-1] - 1]
    if light in history:
        print(-1)
        exit()
    count += 1
    if light == 2:
        print(count)
        exit()
    else:
        history.append(light)

Fixed submission:
N = int(input())
next = []
for i in range(N):
    next.append(int(input()))
count = 0
light = 1
for i in range(N):
    light = next[light - 1]
    count += 1
    if light == 2:
        print(count)
        exit()
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
now_next = {}
for i in range(N):
    now_next[i + 1] = int(input())
count = 0
history = [1]
while True:
    light = now_next[history[-1]]
    if light in history:
        print(-1)
        exit()
    count += 1
    if light == 2:
        print(count)
        exit()
    else:
        history.append(light)

Fixed submission:
N = int(input())
next = []
for i in range(N):
    next.append(int(input()))
count = 0
light = 1
for i in range(N):
    light = next[light - 1]
    count += 1
    if light == 2:
        print(count)
        exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import numpy as np
N, A, B = map(int, input().split())
X = np.array(list(map(int, input().split())))
diff = np.diff(X)
ans = 0
for d in diff:
    if d * A <= B:
        ans += d * A
    else:
        ans += B
print(ans)

Fixed submission:
#!/usr/bin/env python3
import numpy as np
N, A, B = map(int, input().split())
X = np.array(list(map(int, input().split())))
diff = np.diff(X)
ans = 0
for d in diff:
    if d * A <= B:
        ans += d * A
    else:
        ans += B
print(ans)
Buggy python submission (verdict: Runtime Error):
print(input()*input())

Fixed submission:
a,b = map(int,input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(int,input().split()))
prod  = 1
valid = 0
for i in arr:
    prod*=i

if(prod>1e18):   print(-1)
else:   print(prod)

Fixed submission:
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    if 0 in arr:
        return 0
    prod = 1
    max1 = 10**18
    for i in arr:
        prod*=i
        if(prod==0):
            return 0
        if(prod>max1):
            return -1
    return prod

print(main())
Buggy python submission (verdict: Runtime Error):
a,b = map(float,input().split())
print(a//b)


Fixed submission:
from decimal import Decimal
a,b = map(Decimal,input().split())
print(int(a*b))

Buggy python submission (verdict: Runtime Error):
a,b = map(float,input().split())
print(int(a/b))

Fixed submission:
from decimal import Decimal
a,b = map(Decimal,input().split())
print(int(a*b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
set1 = set([])
for _ in range():
  s = input()
  set1.add(s)
 
print(len(set1))

Fixed submission:
n = int(input())
set1 = set([])
for _ in range(n):
  s = input()
  set1.add(s)
 
print(len(set1))
Buggy python submission (verdict: Runtime Error):
import itertools

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())
    
A=list(itertools.combinations([i for i in range(1,m+1)],n))

e=0

g=[]
for v in A:
    e=0
    for i in range(q):
        
        if v[b[i]-1]-v[a[i]-1] ==c[i]:
            e += d[i]
            
        
    g += [e]
print(max(g))

Fixed submission:
import itertools

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())
    
A=list(itertools.combinations_with_replacement([i for i in range(1,m+1)],n))


g=[]
for v in A:
    e=0
    for i in range(q):
        
        if v[b[i]-1]-v[a[i]-1] ==c[i]:
            e += d[i]
            
        
    g += [e]
print(max(g))
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
List = [(input()) for i in range(a)]

x=[]

for i in List:
    if not (i in x):
        x.append(i)

    
print(len(x))

Fixed submission:
a = int(input())
List = [(input()) for i in range(a)]


import collections

c = collections.Counter(List)

print(len(c))
Buggy python submission (verdict: Runtime Error):
import math
n =int(input())
print(2*n*math.pi())

Fixed submission:
import math
n =int(input())
print(2*n*math.pi)

Buggy python submission (verdict: Runtime Error):
import math
n =int(input())
proint(2*n*math.pi)

Fixed submission:
import math
n =int(input())
print(2*n*math.pi)

Buggy python submission (verdict: Runtime Error):
import math
n =int(input())
proint(2*n*math.pi())

Fixed submission:
import math
n =int(input())
print(2*n*math.pi)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())

c=[i for i in input().split()]

print(a-sum(c) if a>=sum(c) else '-1')

Fixed submission:
a,b=map(int,input().split())
 
c=[int(i) for i in input().split()]
d=sum(c)
print(a-sum(c) if a>=sum(c) else '-1')
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=n
b=(n//k)
c=n-k*b
d=c-k

  
if abs(c)>abs(d):
    print(str(abs(d)))
else:
    print(str(abs(c)))


Fixed submission:
a,b,c=map(int,input().split())
x=c
c=b
b=a
a=x


print(a,b,c)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=n
while True:
    
    if (n-k)>0:
        n=n-k
        a=n
    else:
        b=n-k
        break
   
if abs(a)>abs(b):
    print(str(abs(b)))
else:
    print(str(abs(a)))

Fixed submission:
n,k=map(int,input().split())
a=n
b=(n//k)
c=n-k*b
d=c-k

  
if abs(c)>abs(d):
    print(str(abs(d)))
else:
    print(str(abs(c)))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())

while True:
    a=n
    if (n-k)>0:
        n=n-k
        a=n
    else:
        b=n-k
        break
   
if abs(a)>abs(b):
    print(str(abs(b)))
else:
    print(str(abs(a)))


Fixed submission:
n,k=map(int,input().split())
a=n
b=(n//k)
c=n-k*b
d=c-k

  
if abs(c)>abs(d):
    print(str(abs(d)))
else:
    print(str(abs(c)))
Buggy python submission (verdict: Runtime Error):
import math
N,M =map(int,input().split())
if N!=1:
    N1=(math.factorial(N))//(math.factorial(N-2)*2)

else:
    N1=0
    
if M !=1:
    M1=(math.factorial(M))//(math.factorial(M-2)*2)
else:
    M1=0
    
print(str(N1+M1))

Fixed submission:
import math
N,M =map(int,input().split())
if N==1 :
    N1=0
elif N==0:
    N1=0
else:
    N1=(math.factorial(N))//(math.factorial(N-2)*2)
    
if M==1:    
    M1=0
    
elif M ==0:
    M1=0
else:
    M1=(math.factorial(M))//(math.factorial(M-2)*2)
    
print(str(N1+M1))

Buggy python submission (verdict: Runtime Error):
import math
N,M =map(int,input().split())

N1=(math.factorial(N))//(math.factorial(N-2)*2)
M1=(math.factorial(M))//(math.factorial(M-2)*2)

print(str(N1+M1))

Fixed submission:
import math
N,M =map(int,input().split())
if N==1 :
    N1=0
elif N==0:
    N1=0
else:
    N1=(math.factorial(N))//(math.factorial(N-2)*2)
    
if M==1:    
    M1=0
    
elif M ==0:
    M1=0
else:
    M1=(math.factorial(M))//(math.factorial(M-2)*2)
    
print(str(N1+M1))

Buggy python submission (verdict: Runtime Error):
N,M =map(str,input().split())

N1=math.factorial(N)//(math.factorial(N-2)*2)
M1=math.factorial(M)//(math.factorial(M-2)*2)

print(N1+M1)

Fixed submission:
import math
N,M =map(int,input().split())
if N==1 :
    N1=0
elif N==0:
    N1=0
else:
    N1=(math.factorial(N))//(math.factorial(N-2)*2)
    
if M==1:    
    M1=0
    
elif M ==0:
    M1=0
else:
    M1=(math.factorial(M))//(math.factorial(M-2)*2)
    
print(str(N1+M1))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[i for i in input().split()]

print('YES' if len(set(a)==n) else 'NO')

Fixed submission:
s,t =map(str,input().split())
a,b =map(int,input().split())
u=input()
if u==s:
    print(a-1,b)
else:
    print(a,b-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[i for i in input().split()]

print('YES' if len(set(a)==n) else 'NO')

Fixed submission:
n=int(input())
a=[i for i in input().split()]

print('YES' if len(set(a))==n else 'NO')

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[i for i in input().split()]
print(len(set(a)))
print('YES' if len(set(a)==n) else 'NO')

Fixed submission:
n=int(input())
a=[i for i in input().split()]

print('YES' if len(set(a))==n else 'NO')
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

x =[1,2,3]
x = x.remove(a)
x = x.remove(b)

print(x[0])

Fixed submission:
a = int(input())
b = int(input())
 
p = list(map(int,range(1,4)))
p.remove(a)
p.remove(b)
print(p[0])
Buggy python submission (verdict: Runtime Error):
s = input()
a =['SUN','MON','TUS','WED','THU','FRI','SAT']
if s!= 'SUN':
	print(a.index(s))
else:
  print(7)

Fixed submission:
s = input()
a =['SUN','MON','TUE','WED','THU','FRI','SAT']

print(7-a.index(s))

Buggy python submission (verdict: Runtime Error):
s = input()
a =['SUN','MON','TUS','WED','THU','FRI','SAT']
if a!= 'SUN':
	print(a.index(s))
else:
  print(7)

Fixed submission:
s = input()
a =['SUN','MON','TUE','WED','THU','FRI','SAT']

print(7-a.index(s))
Buggy python submission (verdict: Runtime Error):
def main(a):
    return a + a**2 + a**3

if __name__ == "__main__":
    a = input()
    print(main(a))


Fixed submission:
def main(a):
    return a + a**2 + a**3

if __name__ == "__main__":
    a = int(input())
    print(int(main(a)))
Buggy python submission (verdict: Runtime Error):
import sys

def main(n):
    c = "abcdefghijklmnopqrstuvwxyz"
    m = {}
    for i in range(0, 26):
        m[i+1] = c[i]

    s = ""
    while n > 0:
        s = m[(n%26)] + s
        n /= 26
    return s

n = int(sys.stdin.readline().strip())
print(main(n))


Fixed submission:
import sys

def main(n):
    c = "abcdefghijklmnopqrstuvwxyz"
    m = {}
    for i in range(0, 26):
        m[i+1] = c[i]

    s = ""
    while n > 0:
        if n%26 == 0:
            t = 26
            n //= 26
            n -= 1
        else:
            t = n%26
            n //= 26
        s = m[t] + s
    return s

n = int(sys.stdin.readline().strip())
print(main(n))
Buggy python submission (verdict: Time Limit Exceeded):
import sys 

def main(n, a_n, q, bc_n):
    m = {}
    for i in range(n):
        if a_n[i] not in m:
            m[a_n[i]] = 0 
        m[a_n[i]] += 1

    s = []
    for j in range(q):
        b, c = bc_n[j]

        if b in m:
            if c not in m:
                m[c] = m[b]
            else:
                m[c] += m[b]
            del m[b]

        ts = 0 
        for k, v in m.items():
            ts += k * v 
        s.append(ts)
    return s


n = int(sys.stdin.readline().strip())
a_n = [int(x) for x in sys.stdin.readline().strip().split(" ")]
q = int(sys.stdin.readline().strip())
bc_n = []
for _ in range(q):
    b, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    bc_n.append((b, c)) 
for i in main(n, a_n, q, bc_n):
    print(i)


Fixed submission:
import sys

def main(n, a_n, q, bc_n):
    m = {}
    for i in range(n):
        if a_n[i] not in m:
            m[a_n[i]] = 0
        m[a_n[i]] += 1

    s = []
    for j in range(q):
        b, c = bc_n[j]

        diff = 0
        if b in m:
            diff = m[b] * c  - m[b] * b
            if c not in m:
                m[c] = m[b]
            else:
                m[c] += m[b]
            del m[b]

        ts = 0
        if len(s) == 0:
            for k, v in m.items():
                ts += k * v
        else:
            ts = s[-1] + diff
        s.append(ts)
    return s


n = int(sys.stdin.readline().strip())
a_n = [int(x) for x in sys.stdin.readline().strip().split(" ")]
q = int(sys.stdin.readline().strip())
bc_n = []
for _ in range(q):
    b, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    bc_n.append((b, c))
for i in main(n, a_n, q, bc_n):
    print(i)
Buggy python submission (verdict: Runtime Error):
import sys
import math
 
N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))
 
_min, _max = -math.inf, math.inf
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)

Fixed submission:
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 1, 100000
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
if _min > _max:
    print(0)
else:
    print(_max - _min + 1)

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

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = -math.inf, math.inf
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)


Fixed submission:
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 1, 100000
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
if _min > _max:
    print(0)
else:
    print(_max - _min + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

prev = set(range(1, N+1))
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    accepted = set(range(L, R+1))
    prev = prev & accepted
print(len(prev))


Fixed submission:
import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 1, 100000
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
if _min > _max:
    print(0)
else:
    print(_max - _min + 1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = map(int, input().split())

a.sort(reverse=True)

print(sum(a[::2])-sum(a[1::2]))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
 
a.sort(reverse=True)
 
print(sum(a[::2])-sum(a[1::2]))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().open(0).split())
print(sum(500*x+100*y+50*z==d for x in range(a+1) for y in range(b+1) for z in range(c+1)))

Fixed submission:
a,b,c,d = map(int, open(0))
print(sum(500*x+100*y+50*z==d for x in range(a+1) for y in range(b+1) for z in range(c+1)))

Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().open().read().split())
print(sum(500*x+100*y+50*z==d for x in range(a+1) for y in range(b+1) for z in range(c+1)))

Fixed submission:
a,b,c,d = map(int, open(0))
print(sum(500*x+100*y+50*z==d for x in range(a+1) for y in range(b+1) for z in range(c+1)))