Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=-m[0]//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[1]):
  ans+=-m[i]
print(ans)

Fixed submission:
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=(-1*m[0])//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[0]):
  ans+=-m[i]

print(ans)

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

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [(-x, x) for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=m[0][1]//2
  heapq.heappop(m)
  heapq.heappush(m, (-x, x))
  
ans=0

for i in range(n[1]):
  ans+=m[i][1]
  
print(ans)

Fixed submission:
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=(-1*m[0])//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[0]):
  ans+=-m[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=list(map(int,input().split()))
m=list(map(int,input().split()))
maxm=sum(m)
for i in range(n[1]):
  m[m.index(max(m))]=m[m.index(max(m))]//2
 
print(sum(m))

Fixed submission:
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=(-1*m[0])//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[0]):
  ans+=-m[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))

a,b = 0, abs(h[0]-h[1])

for i in range(len(h)):
    if i > 1:
        a,b = b, min(abs(h[i-2]-h[i])+a, abs(h[i-1]-h[i])+b)
    
print(b)

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

a,b = 0, abs(h[0]-h[1])

for i in range(len(h)):
    if i > 1:
        a,b = b, min(abs(h[i-2]-h[i])+a, abs(h[i-1]-h[i])+b)
    
print(b)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))

a,b = 0, abs(h[0]-h[1])

for i in range(len(h)):
    if i > 1:
        a,b = b, min(abs(h[i-2]-h[i])+a, abs(h[i-1]+h[i])+b)
    
print(b)

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

a,b = 0, abs(h[0]-h[1])

for i in range(len(h)):
    if i > 1:
        a,b = b, min(abs(h[i-2]-h[i])+a, abs(h[i-1]-h[i])+b)
    
print(b)
Buggy python submission (verdict: Runtime Error):
print(input().count()*3 +700)

Fixed submission:
print((input().count("o"))*100+700)
Buggy python submission (verdict: Runtime Error):
N,A = map(int, input().split())
if N%500=< A:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
A = int(input())

if N%500 <= A:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N,A = map(int, input().split())
if N%500<= A:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
A = int(input())

if N%500 <= A:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N,A = map(int, input().split())
if N%500< A:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
A = int(input())

if N%500 <= A:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N,A = map(int, input().split())
if N%500< A:
    print("YES")
else:
    print("NO")

Fixed submission:
N = int(input())
A = int(input())

if N%500 <= A:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,y = map(int,input().split())
flag = True

for i in range(y//10000 + 1):
    for j in range((y - i*10000)//5000 + 1):
        for k in range((y - i*10000-j*5000)//1000 + 1):
            if i*10000+j*5000+k*1000 == y:
                if i+j+k == n:
                    print(i,j,k)
                    flag = False
                    break
        if flag:
            continue
        else:
            break
    if flag:
        continue
    else:
        break            
else:
    print("-1 -1 -1")

Fixed submission:
n,y = map(int,input().split())
flag = True

for i in range(y//10000 + 1):
    for j in range((y - i*10000)//5000 + 1):
        k = (y - 10000*i - 5000*j)//1000        
        if i + j + k == n:
            print(i,j,k)
            flag = False
            break
    if flag:
        continue
    else:
        break            
else:
    print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
s = sorted(set(input()))
if len(s) ==26:
    print("None")
else:
    for i,k in enumerate("abcdefghijklmnopqrstuvwxyz"):
        if k != s[i]:
            print(k)
            break

Fixed submission:
s = set(input())

if len(s) == 26:
    print("None")
else:
    print(sorted("".join(set("abcdefghijklmnopqrstuvwxyz") - s))[0])
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0

for i in range(k+1):
    if i == s:
        count += 1
        break

    for j in range(k+1):
        if (i+j) == s:
            count += 1
            break

        for t in range(k+1):
            if (i+j+t) == s:
                count += 1
                break

print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0

for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if z >= 0 and z <= k:
            count += 1

print(count)

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

for i in range(k+1):
    for j in range(k+1):
        for t in range(k+1):
            if (i+j+t) == s:
                count += 1
                break

print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0

for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if z >= 0 and z <= k:
            count += 1

print(count)

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

if 3*k < s:
    print(0)
else:
    for i in range(k+1):
        for j in range(k+1):
            for t in range(k+1):
                if (i+j+t) == s:
                    count += 1
    print(count)    


Fixed submission:
k,s = map(int,input().split())
count = 0

for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if z >= 0 and z <= k:
            count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
        for t in range(k+1):
            if (i+j+t) == s:
                count += 1
print(count)

Fixed submission:
k,s = map(int,input().split())
count = 0

for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if z >= 0 and z <= k:
            count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))
c = Counter(A)
result = 0
piyo = []
for k, v in c.items():
    if v > 1:
        piyo.append(k)
        A.remove(k)
for a in A:
    flag = False
    for hoge in piyo:
        if a % hoge == 0:
            flag = True
            break
    if not flag:
        piyo.append(a)
        result += 1
print(result)

Fixed submission:
def main():
    from collections import Counter
    n = int(input())
    A = sorted(list(map(int, input().split())))
    c = Counter(A)
    result = 0
    flag = [True] * (A[-1] + 1)
    for i in A:
        if flag[i]:
            result += 1
            for j in range(2*i, A[-1] + 1, i):
                flag[j] = False
    for k, v in c.items():
        if v > 1:
            if flag[k]:
                result -= v
    print(result)
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))
c = Counter(A)
result = 0
piyo = []
for k, v in c.items():
    if v > 1:
        piyo.append(k)
        A.remove(k)
for a in A:
    flag = False
    for hoge in piyo:
        if a % hoge == 0:
            flag = True
            break
    if not flag:
        piyo.append(a)
        result += 1
print(result)

Fixed submission:
def main():
    from collections import Counter
    n = int(input())
    A = sorted(list(map(int, input().split())))
    c = Counter(A)
    result = 0
    flag = [True] * (A[-1] + 1)
    for i in A:
        if flag[i]:
            result += 1
            for j in range(2*i, A[-1] + 1, i):
                flag[j] = False
    for k, v in c.items():
        if v > 1:
            if flag[k]:
                result -= v
    print(result)
main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    if n == 1:
        print(0)
        return
    def eratos(n):
        flag = [True] * (n + 1)
        for i in range(2, int(n**0.5) + 1):
            if flag[i]:
                for j in range(2*i, n + 1, i):
                    flag[j] = False
        return [i for i, x in enumerate(flag) if x and i >= 2]
    p = eratos(10**6)
    work = []
    for i in p:
        piyo = 0
        while n % i == 0:
            n //= i
            piyo += 1
        if piyo > 0:
            work.append(piyo)
        if n == 1:
            break
    if len(work) == 0:
        print(1)
        break
    else:
        result = 0
        for i in work:
            for j in range(1, 10**6):
                i -= j
                if i <0:
                    break
                result += 1
    if n != 1:
        result += 1
    print(result)
main()

Fixed submission:
def main():
    n = int(input())
    if n == 1:
        print(0)
        return
    def eratos(n):
        flag = [True] * (n + 1)
        for i in range(2, int(n**0.5) + 1):
            if flag[i]:
                for j in range(2*i, n + 1, i):
                    flag[j] = False
        return [i for i, x in enumerate(flag) if x and i >= 2]
    p = eratos(10**6)
    work = []
    for i in p:
        piyo = 0
        while n % i == 0:
            n //= i
            piyo += 1
        if piyo > 0:
            work.append(piyo)
        if n == 1:
            break
    if len(work) == 0:
        print(1)
        return
    else:
        result = 0
        for i in work:
            for j in range(1, 10**6):
                i -= j
                if i <0:
                    break
                result += 1
    if n != 1:
        result += 1
    print(result)
main()
Buggy python submission (verdict: Runtime Error):
def main()
    n, m, x = map(int, input().split())
    ca = []
    for _ in range(n):
        ca.append(list(map(int, input().split())))
    result = 10**9
    for i in range(1, 2**n+1):
        work = 0
        j = 0
        temp = [0] * m
        for flag in bin(i)[2:].zfill(n):
            if flag == "1":
                work += ca[j][0]
                for k in range(1, m+1):
                    temp[k-1] += ca[j][k]
            j += 1
        flag = True
        for t in temp:
            if t < x:
                flag = False
                break
        if flag:
            result = min(result, work)
    if result == 10**9:
        print(-1)
    else:
        print(result)
main()

Fixed submission:
def main():
    n, m, x = map(int, input().split())
    ca = []
    for _ in range(n):
        ca.append(list(map(int, input().split())))
    result = 10**9
    for i in range(1, 2**n+1):
        work = 0
        j = 0
        temp = [0] * m
        for flag in bin(i)[2:].zfill(n):
            if flag == "1":
                work += ca[j][0]
                for k in range(1, m+1):
                    temp[k-1] += ca[j][k]
            j += 1
        flag = True
        for t in temp:
            if t < x:
                flag = False
                break
        if flag:
            result = min(result, work)
    if result == 10**9:
        print(-1)
    else:
        print(result)
main()
Buggy python submission (verdict: Runtime Error):
result = []
def calc(a, b, c, i):
    if i >= N:
        if a < 0 or b < 0 or c < 0:
            return False
        return True
    command = s[i]
    if command == "AB":
        if calc(a+1, b-1, c, i+1):
            result.append("A")
            return True
        if calc(a-1, b+1, c, i+1):
            result.append("B")
            return True
        return False
    elif command == "AC":
        if calc(a+1, b, c-1, i+1):
            result.append("A")
            return True
        if calc(a-1, b, c+1, i+1):
            result.append("C")
            return True
        return False
    elif command == "BC":
        if calc(a, b-1, c+1, i+1):
            result.append("C")
            return True
        if calc(a, b+1, c-1, i+1):
            result.append("B")
            return True
        return False
def main():
    global N, s
    N, A, B, C = map(int, input().split())
    s = [input() for _ in range(N)]
    if calc(A, B, C, 0):
        print("Yes")
        for c in result[::-1]:
            print(c)
    else:
        print("No")
main()

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
result = []
def calc(a, b, c, i):
    if a < 0 or b < 0 or c < 0:
        return False
    if i >= N:
        return True
    command = s[i]
    if command == "AB":
        if calc(a+1, b-1, c, i+1):
            result.append("A")
            return True
        if calc(a-1, b+1, c, i+1):
            result.append("B")
            return True
        return False
    elif command == "AC":
        if calc(a+1, b, c-1, i+1):
            result.append("A")
            return True
        if calc(a-1, b, c+1, i+1):
            result.append("C")
            return True
        return False
    elif command == "BC":
        if calc(a, b-1, c+1, i+1):
            result.append("C")
            return True
        if calc(a, b+1, c-1, i+1):
            result.append("B")
            return True
        return False
def main():
    global N, s
    N, A, B, C = map(int, input().split())
    s = [input() for _ in range(N)]
    if calc(A, B, C, 0):
        print("Yes")
        for c in result[::-1]:
            print(c)
    else:
        print("No")
main()
Buggy python submission (verdict: Time Limit Exceeded):
x,y,a,b,c = map(int, input().split())
result=sorted(list(map(int, input().split())), reverse=True)[:x]
result+=sorted(list(map(int, input().split())), reverse=True)[:y]
r=sorted(list(map(int, input().split())), reverse=True)
s = sum(result)
for el in r:
    t = el - min(result)
    if t>0:
        s += t
print(s)


Fixed submission:
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
result = p[:x] + q[:y] + r
result = sorted(result, reverse=True)
print(sum(result[:x+y]))

Buggy python submission (verdict: Time Limit Exceeded):
x,y,a,b,c = map(int, input().split())
result=sorted(list(map(int, input().split())), reverse=True)[:x]
result+=sorted(list(map(int, input().split())), reverse=True)[:y]
r=sorted(list(map(int, input().split())), reverse=True)
for el in r:
    temp = min(result)
    if el > temp:
        result.remove(temp)
        result.append(el)
print(sum(result))


Fixed submission:
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
result = p[:x] + q[:y] + r
result = sorted(result, reverse=True)
print(sum(result[:x+y]))

Buggy python submission (verdict: Time Limit Exceeded):
x,y,a,b,c = map(int, input().split())
p=sorted(list(map(int, input().split())), reverse=True)
q=sorted(list(map(int, input().split())), reverse=True)
r=sorted(list(map(int, input().split())), reverse=True)
result = []
for el in p[:x]:
    result.append(el)
for el in q[:y]:
    result.append(el)
for el in r:
    temp = min(result)
    if el > temp:
        result.remove(temp)
        result.append(el)
print(sum(result))


Fixed submission:
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
result = p[:x] + q[:y] + r
result = sorted(result, reverse=True)
print(sum(result[:x+y]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = [0]*(n+1)
count = 0
for el in set(a):
    temp = d[el] = a.count(el)
    count += temp*(temp-1)
count //= 2
for el in a:
    print(count - d[el] + 1)

Fixed submission:
n, m = map(int, input().split())
result = (n+m)*(n+m-1)//2 - n*m
print(result)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
for el in a:
    count += a.count(el)-1
count //= 2
for el in a:
    print(count - a.count(el)+1)

Fixed submission:
n, m = map(int, input().split())
result = (n+m)*(n+m-1)//2 - n*m
print(result)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
L = len(a)
for el in a:
    count += a.count(el)-1
count //= 2
for el in a:
    print(count - a.count(el)+1)

Fixed submission:
n, m = map(int, input().split())
result = (n+m)*(n+m-1)//2 - n*m
print(result)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(len(a)):
    count += a.count(a[i])
count /= 2
for i in range(len(a)):
    print(count - a.count(a[i])+1)

Fixed submission:
n, m = map(int, input().split())
result = (n+m)*(n+m-1)//2 - n*m
print(result)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(len(a)):
    count += a.count(a[i])
count /= 2
for i in range(len(a)):
    print(count - a.count(a[i])+1)

Fixed submission:
n, m = map(int, input().split())
result = (n+m)*(n+m-1)//2 - n*m
print(result)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [(1/num)*(num)*(num+1)/2 for num in p]
d = deque(p[:k])
result = deque()
append = result.append
for el in p[k:]:
    d.popleft()
    d.append(el)
    append(sum(d))
print(max(result))


Fixed submission:
from collections import deque
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [(1/num)*(num)*(num+1)/2 for num in p]
d = deque(p[:k])
result = temp = sum(d)
popleft = d.popleft
dappend = d.append
for el in p[k:]:
    temp -= popleft()
    dappend(el)
    temp += el
    if result < temp:
        result = temp
print(result)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())
work = []
for i in range(n):
    a = int(input())
    work.append([list(map(int, input().split())) for i in range(a)])
result = 0
for i in range(n):
    count = 0
    d = deque([work[i]])
    honest = deque([i])
    unkind = deque()
    while len(d) > 0:
        human = d.popleft()
        for x, y in human:
            if y == 1:
                if x not in honest:
                    d.append(work[x-1])
                    honest.append(x)
            else:
                if x not in unkind:
                    unkind.append(x)
    finish = False
    while not finish:
        finish = True
        for i in range(1, n+1):
            if i not in honest and i not in unkind:
                flag = True
                for x, y in work[i-1]:
                    if y == 1 and x in unkind:
                        flag = False
                        break
                    elif y == 0 and x in honest:
                        flag = False
                        break
                    elif x not in honest+unkind:
                        finish = False
                if flag:
                    honest.append(i)
                else:
                    unkind.append(i)
    if len(set(honest) & set(unkind)) == 0:
        count = n - len(unkind)
        result = result if result > count else count
print(result)

Fixed submission:
from collections import deque
n = int(input())
work = []
for i in range(n):
    a = int(input())
    work.append([list(map(int, input().split())) for i in range(a)])
result = 0
for i in range(2**n):
    state = bin(i)[2:].zfill(n)
    honest = []
    unkind = []
    for j in range(n):
        if state[j] == "0":
            unkind.append(j+1)
        else:
            honest.append(j+1)
    flag = True
    for human in honest:
        for x, y in work[human-1]:
            if y == 1 and x in unkind:
                flag = False
                break
            elif y == 0 and x in honest:
                flag = False
                break
        if not flag:
            break
    if flag:
        result = result if result>len(honest) else len(honest)
print(result)
Buggy python submission (verdict: Runtime Error):
def cmb(n, r, p):
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 4*10**5  # N は必要分だけ用意する
N = 2*n
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    if i <= n:
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    result = 0
else:
    result = cmb((X+Y)//3, Y-(X+Y)//3, p)
print(result)


Fixed submission:
def cmb(n, r, p):
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 7*10**5  # N は必要分だけ用意する
N = 2*n
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    if i <= n:
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    result = 0
else:
    n = Y-(X+Y)//3
    m = X-(X+Y)//3
    if n<0 or m<0:
        result = 0
    else:
        result = cmb(n+m, n, p)
print(result)
Buggy python submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
if (a**2)*b/2 < x:
    s = math.degrees(math.atan(2*a/(3*(b-(x/(a**2))))))
else:
    s = math.degrees(math.atan(2*x/(a*b**2)))
print(90-s)

Fixed submission:
import math
a, b, x = map(int, input().split())
if a**2*b == x:
    s = 90
elif (a**2)*b/2 < x:
    s = math.degrees(math.atan(a/(2*(b-(x/(a**2))))))
else:
    s = math.degrees(math.atan(2*x/(a*b**2)))
print(90-s)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
s = [Counter(input()) for i in range(n)]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            count += 1
print(count)

Fixed submission:
from collections import Counter
n = int(input())
s = [str(sorted(input())) for i in range(n)]
d = dict()
for el in s:
    if d.get(el) == None:
        d[el] = 1
    else:
        d[el] += 1
count = 0
for el in d.values():
    count += el*(el-1)//2
print(count)
Buggy python submission (verdict: Runtime Error):
from math import gcd
def func(n):
    return n - (n//C + n//D - n//(C*D//gcd(C, D)))
A, B, C, D = map(int, input().split())
print(func(B) - func(A-1))

Fixed submission:
from fractions import gcd
def func(n):
    return n - (n//C + n//D - n//(C*D//gcd(C, D)))
A, B, C, D = map(int, input().split())
print(func(B) - func(A-1))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
array = [list(map(int, input().split())) for i in range(m)]
result = set([i for i in range(1, n+1)])
for el in array:
    L, R = el[0], el[1]
    work = set([i for i in range(L, R+1)])
    result = work & result
print(len(result))

Fixed submission:
n, m = map(int, input().split())
array = [list(map(int, input().split())) for i in range(m)]
result = [1, n]
for el in array:
    if el[0] > result[1] or result[0] > el[1]:
        result = [1, 0]
        break
    else:
        work = sorted(result + el)
        result = [work[1], work[2]]
print(result[1]-result[0]+1)