Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
res={i for i in range(1,n+1)}
for i in range(m):
	l,r = map(int,input().split())
	g = { i for i in range(min(res) if l < min(res) else l,r+1)}
	res = res&g
	if res == {} :
		print(0)
		break
print(len(res))

Fixed submission:

n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
res={i for i in range(1,n+1)}
for i in range(m):
	l,r = map(int,input().split())
	g = { i for i in range(l,r+1)}
	res = res&g
	if res == {} :
		print(0)
		break
print(len(res))

Fixed submission:

n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
r={i for i in range(1,n+1)}
for i in range(m):
	l,r = map(int,input().split())
	g = { i for i in range(l,r+1)}
	r = r&g
	if r == {} :
		print(0)
		break
print(len(r))

Fixed submission:

n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
gates = []
res = 0
for i in range(m):
	l,r = map(int,input().split())
	gates.append({ i for i in range(l,r+1)})
r={i for i in range(1,n+1)}

for g in gates :
	r = r & g
print(len(r))

Fixed submission:

n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
gates = []
for i in range(m):
	l,r = map(int,input().split())
	gates.append((l,r))
res = 0
L,R = gates[0]
if len(gates) < 2 :
	for i in range(1,n+1) :
		res += 1 if L<=i<=R else 0
	print(res)
else :
	for i in range(L,R+1) :
		flag =False
		for l,r in gates[1:] :
			if l<=i<=r :
				flag =True
			else :
				flag = False
				break
		res += 1 if flag else 0
	print(res)

Fixed submission:

n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
gates = []
for i in range(m):
	l,r = map(int,input().split())
	gates.append((l,r))
res = 0
L,R = gates[0]
if len(gates) < 2 :
	for i in range(1,n+1) :
		res += 1 if L<=i<=R else 0
	print(res)
else :
	for i in range(L,R+1) :
		flag =False
		for l,r in gates[1:] :
			if l<=i<=r :
				flag =True
			else :
				flag = False
		res += 1 if flag else 0
	print(res)

Fixed submission:

n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)