Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02866 (python)

Fixed submission:
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=list(map(int,np.zeros(M+1)))
ans=1

for i in D:
    countlist[i]+=1

if 0 in countlist or countlist[0]!=1 :
    print(0)
    sys.exit()
elif M<2:
    print(1)
    sys.exit()

if D[0]!=0 :
    print(0)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(ans%998244353)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=[0] * (maxD + 1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif M<2:
    print(1)
    sys.exit()

if D[0]!=0 :
    print(0)
    sys.exit()

for i in range(2,M+1):
        ans *= countlist[i-1]**countlist[i]

print(ans%998244353)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(int(ans)%998244353)

Buggy submission (verdict: Runtime Error):

import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(int(ans%998244353))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<max(D):
        ans=0
    else:
        break


print(int(ans%998244353))
Problem p02886 (python)

Fixed submission:
N = int(input())
d1 = input().split()
sum= 0

for i in range(len(d1)):
    for j in range(len(d1)): 
        if(i != j and j > i):
            sum += int(d1[i])*int(d1[j])

print(sum)

Buggy submission (verdict: Runtime Error):
for i in range(len(d1)):
    for j in range(len(d1)): 
        if(i != j and j > i):
            sum += int(d1[i])*int(d1[j])

print(sum)
Problem p03609 (python)

Fixed submission:
n, m = map(int,input().split())
ans = n - m
if ans < 0 :
  ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
m = int(input())
ans = n - m
if ans < 0 :
  ans = 0
print(ans)
Problem p02999 (python)

Fixed submission:
#coding:utf-8
X,A = map(int,input().split())

if X < A:
    print(0)

else:
    print(10)

Buggy submission (verdict: Runtime Error):
#coding:utf-8

import sys

N,X = map(int,input().split())
L = list(map(int,input().split()))

D = 0 #ジャンプする座標

for i in range(N):
    D += L[i]
    if D > X:
        print(i+1)
        sys.exit()

print(N+1)
Problem p03000 (python)

Fixed submission:
#coding:utf-8

import sys

N,X = map(int,input().split())
L = list(map(int,input().split()))

D = 0 #ジャンプする座標

for i in range(N):
    D += L[i]
    if D > X:
        print(i+1)
        sys.exit()

print(N+1)

Buggy submission (verdict: Runtime Error):
#coding:utf-8

import sys

N,X = map(int,input().split())
L = list(map(int,input().split()))

D = 0 #ジャンプする座標

for i in range(N+1):
    D += L[i]
    if D > X:
        print(i+1)
        sys.exit()

print(N+1)
Problem p03455 (python)

Fixed submission:
#coding:utf-8

a,b=map(int,input().split())

c=a*b

if c % 2 == 0:
    print("Even")

else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
#coding:utf-8

a,b=map(int,raw_input().split())

c=a*b

if c % 2 == 0:
    print("Even")

else:
    print("Odd")
Problem p03059 (python)

Fixed submission:
n = input().split()
A = int(n[0])
B = int(n[1])
T = int(n[2])

print(T//A  * B)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
T = int(input())

print(T/A * B)
Problem p02900 (python)

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

gcdv = gcd(a, b)

prime_cnt = Counter()
n = gcdv
for i in range(2, int(gcdv ** 0.5) + 2):
    while n % i == 0:
        n //= i
        prime_cnt[i] += 1

prime_cnt[n] += 1
prime_cnt[1] += 1

print(len(prime_cnt.keys()))

Buggy submission (verdict: Runtime Error):
from math import gcd, ceil
import sys
a, b = map(int, input().split())

gcdv = gcd(a, b)

if gcdv == 1:
    print(1)
    sys.exit(0)
is_so = True
sqrt_v = ceil(gcdv ** 0.5)
cnt = 1
table = [True] * (sqrt_v + 1)
for i in range(2, sqrt_v + 1):
    if table[i] and gcdv % i == 0:
        cnt += 1
        if gcd(gcdv, i) != 1:
            is_so = False
    for k in range(0, sqrt_v, i):
        table[k] = False

if is_so:
    cnt += 1
print(cnt)
Problem p02995 (python)

Fixed submission:
A, B, C, D = list(map(int, input().split()))
from fractions import gcd
e = C * D // gcd(C, D)
p1 = B-A+1
p2 = (B//C) + (B//D) - (B//e)
p3 = ((A-1)//C) + ((A-1)//D) - ((A-1)//e)
print(p1 + p3 - p2)

Buggy submission (verdict: Runtime Error):
A, B, C, D = list(map(int, input().split()))
from math import gcd
e = C * D // gcd(C, D)
p1 = B-A+1
p2 = (B//C) + (B//D) - (B//e)
p3 = ((A-1)//C) + ((A-1)//D) - ((A-1)//e)
print(p1 + p3 - p2)

Buggy submission (verdict: Runtime Error):
A, B, C, D = list(map(int, input().split()))
from functools import gcd
e = C * D // gcd(C, D)
p1 = B-A+1
p2 = (B//C) + (B//D) - (B//e)
p3 = ((A-1)//C) + ((A-1)//D) - ((A-1)//e)
print(p1 + p3 - p2)
Problem p03001 (python)

Fixed submission:
w, h, x, y = list(map(int, input().split()))
print(w * h / 2, 1 if (w==x*2) and (h==y*2) else 0)

Buggy submission (verdict: Runtime Error):
w, h, x, y = list(map(int, input().split()))
print(w * h / 2, 1 int((w==x*2) and (h==y*2)))

Buggy submission (verdict: Runtime Error):
2 2 1 1
Problem p03061 (python)

Fixed submission:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))

L = [0] * (N+1)
R = [0] * (N+1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
    R[N-i-1] = gcd(R[N-i], A[N-i-1])

max_m = 0
for i in range(N):
    m = gcd(L[i], R[i+1])
    if max_m < m:
        max_m = m
print(max_m)

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
N = int(input())
a_list = list(map(int, input().split()))

max_gcd_list = []
for i in range(N):
    new_list = a_list[:i] + (a_list[(i+1):] if i < N-1 else [])
    max_gcd = reduce(gcd, new_list[1:], new_list[0])
    max_gcd_list.append(max_gcd)
print(max(max_gcd_list))
Problem p03087 (python)

Fixed submission:
dd = input().strip().split(' ')
N, Q = tuple(map(int, dd))
S = input().strip()

ac_indicies = []
cp = S.find('AC')
while cp != -1:
    ac_indicies.append(cp)
    cp = S.find('AC', cp + 1)

min_i = 0
ac = ac_indicies + [N]
l_index = []
for i in range(N):
    if i > ac[min_i]:
        min_i += 1
    l_index.append(min_i)

total = len(ac_indicies)
for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print(l_index[r-1] - l_index[l-1])

Buggy submission (verdict: Runtime Error):
import re


dd = input().strip().split(' ')
N, Q = tuple(map(int, dd))
S = input().strip()

ac_indicies = []
cp = S.find('AC')
while cp != -1:
    ac_indicies.append(cp)
    cp = S.find('AC', cp + 1)

min_i = 0
ac = ac_indicies + [N]
l_index = []
for i in range(N):
    if i > ac[min_i]:
        min_i += 1
    l_index.append(min_i)

max_i = len(ac_indicies)
ac2 = [0] + ac_indicies
r_index = []
for i in range(N-1, -1, -1):
    if i < ac[max_i]:
        max_i -= 1
    r_index.append(max_i)
   
total = len(ac_indicies)
for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print(total - l_index[l-1] - r_index[r-1])
Problem p02882 (python)

Fixed submission:
import math

a, b, x = map(int, input().split())
if (x == a*a*b):
    ans = 0.0000000000
    print(ans)
else:
    x2 = x/a
    c = x2*2/a - b
    ans=math.atan(a/(b-c))
    ans = 90 - ans / math.pi * 180
    if c <= 0:
        c = x2*2 / b
        ans=math.atan(c/b)
        ans = 90 - ans / math.pi * 180
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())

x2 = x/a
c = x2*2/a - b
ans=math.atan(a/(b-c))
ans = 90 - ans / math.pi * 180
if c <= 0:
    c = x2*2 / b
    ans=math.atan(c/b)
    ans = 90 - ans / math.pi * 180


print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())

x2 = x/a
c = x2*2/a - b
ans=math.atan(a/(b-c))
ans = 90 - ans / math.pi * 180
if c < 0:
    c = x2*2 / b
    ans=math.atan(c/b)
    ans = 90 - ans / math.pi * 180


print(ans)
Problem p02957 (python)

Fixed submission:
a, b = map(int, input().split())
if (a + b)%2 == 0:
  k = (a + b)//2
  print(k)
else:
  print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = input().split()
for i in range(a):
  b[i] = int(b[i])
  
for i in range(a-1):
  if (b[i] > b[i+1]):
    break
if i == a-2:
  print('YES')
else:
  for j in range(a-1,i,-1):
    if (b[j] < b[j-1]):
      break
  temp = b[i]
  b[i] = b[j]
  b[j] = temp
  for k in range(a-1):
    if (b[k] > b[k+1]):
      break
  if k == a-2:
    print('YES')
  else:
    print('NO')
Problem p02853 (python)

Fixed submission:
num = input().split()
nums = []
for i in num:
  nums.append(int(i))
#print(nums)
price = [300000, 200000, 100000]
result = []

#2 3 4 5 6
for i in nums:
  if int(i) > 3:
    result.append(0)
  else:
    result.append(price[i-1])
value = result[0] + result[1]
if value == 600000:
  print("1000000")
else:
  print(value)

Buggy submission (verdict: Runtime Error):
N = input().split()
A = input().split()
a = []

if int(N[0]) >= 2 and int(N[0]) <= 200000:
  n = int(N[0])
  for i in range(n):
    if int(A[i]) >= 1 and int(A[i]) <= 2020202020:
      a.append(int(A[i]))

right = 0
left = 0
cnt = 0
herf = 0

for i in range(n):
  cnt += a[i]
herf = int(cnt/2)
for i in range(n):
  left += a[i]
  if left > herf:
    left -= a[i]
    right = cnt - left
    break
print(abs(left-right))
Problem p02853 (python)

Fixed submission:
def fun(x):
    if x==1:
        return 300000
    elif x==2:
        return 200000
    elif x==3:
        return 100000
    else:
        return 0
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
su=0
if a==b==1:
    su+=400000
su+=fun(a)
su+=fun(b)
print(su)

Buggy submission (verdict: Runtime Error):
def fun(x):
  if x==1:
    return 300000
  elif x==2:
    return 200000
  elif x==3:
    return 100000
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
su=0
if a==b==1:
    su+=400000
su+=fun(a)
su+=fun(b)
print(su)

Buggy submission (verdict: Runtime Error):
def fun(x):
  if x==1:
    return 300000
  elif x==2:
    return 200000
  elif x==3:
    return 100000
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
sum+=fun(a)
sum+=fun(b)
print(sum)
Problem p02853 (python)

Fixed submission:
s = 0
for i in map(int, input().split()):
    if i==1:
        s+=300000
    elif i==2:
        s+=200000
    elif i==3:
        s+=100000
if s==600000:
    s=1000000
print(s)

Buggy submission (verdict: Runtime Error):
sum = 0
for i in map(int, input().split()):
    if i==1:
        sum += 300000
    elif i==2:
        sum+200000
    elif i==3:
        sum += 100000
if sum == 600000:
    sum += 400000
print(s)
Problem p02921 (python)

Fixed submission:
S_list = input()
T_list = input()
count = 0

for i in range(0, 3):
  if S_list[i] == T_list[i]:
    count += 1
  else:
    pass
  
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
H_list = input().split(" ")
max_count = 0

for i in range(0, N):
    S = int(H_list[i])
    count = 0
    for j in range(i + 1, N):
        if S >= int(H_list[j]):
            S = int(H_list[j])
            count += 1
        else:
            break
    if max_count < count:
        max_count = count
    if max_count >= N - i:
        break
print(max_count)

Buggy submission (verdict: Runtime Error):
N = int(input())
H_list = input().split(" ")
H_LIST = []

for i in range(0, N):
    H_LIST.append(int(H_list[i]))
 
max_count = 0

for i in range(0, N):
    S = H_LIST[i]
    count = 0
    for j in range(i + 1, N):
        if S >= H_LIST[j]:
            S = H_LIST[j]
            count += 1
        else:
            pass
    if max_count < count:
        max_count = count

print(max_count)

Buggy submission (verdict: Runtime Error):
AB = input().split(" ")
A = int(AB[0])
B = int(AB[1])

kuti = 1
count = 0 #tap

while kuti < B:
  kuti -= 1
  kuti += A
  count += 1

print(count)
Problem p02923 (python)

Fixed submission:
N = int(input())
H_LIST = input().split(" ")
H = []

for i in H_LIST:
    H.append(int(i))
   
count = 0
max_count = 0
for i in range(0, N-1):
    if H[i] >= H[i + 1]:
        count += 1
    else:
        count = 0 #メモリの動き
        
    if max_count < count:
        max_count = count


print(max_count)

Buggy submission (verdict: Runtime Error):
N = int(input())
H_LIST = input().split(" ")
H = []

for i in H_LIST:
    H.append(int(i))
   
count = 0
max_count = 0
for i in range(0, N):
    if H[i] >= H[i + 1]:
        count += 1
    else:
        max_count = count #メモリの動き
        count = 0

print(max_count)
Problem p02946 (python)

Fixed submission:
lis = input().split(" ")

K = int(lis[0])
X = int(lis[1])

mini = X - (K - 1)
maxm = X + (K - 1)
list_a = []
for i in range(0, (K - 1) * 2 + 1):
    list_a.append(str((X - (K - 1)) + i))

print(" ".join(list_a))

Buggy submission (verdict: Runtime Error):
lis = input(" ")

K = int(lis[0])
X = int(lis[1])

mini = X - (K - 1)
maxm = X + (K - 1)
list_a = []
for i in range(0, (K - 1) * 2 + 1):
    list_a.append(str((X - (K - 1)) + i))

print(" ".join(list_a))
Problem p02952 (python)

Fixed submission:
import math
n = str(input()) 
keta = (len(n))
max = int(keta/2)+1

count = 0
t = int(n)
if(keta%2==0):
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
else:
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
    t = t - 10**(keta-1)
    count += t
    count +=1
print(count)

Buggy submission (verdict: Runtime Error):
keta = (len(n))
max = int(keta/2)+1

count = 0
t = int(n)
if(keta%2==0):
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
else:
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
    t = t - 10**(keta-1)
    count += t
    count +=1
print(count)
Problem p02945 (python)

Fixed submission:
a,b=map(int,input().split())
c=[a+b, a-b, a*b]
m=max(c)
print(m)

Buggy submission (verdict: Runtime Error):
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  s.sort()
  S.append(s)
S.sort()
S.append(["z" for i in range(11)])
cont=0
for i in range(n-1):
  t=1
  while S[i]==S[i+t]:
    cont+=1
    t+=1
print(cont)
Problem p02952 (python)

Fixed submission:
N=int(input())
if N == 10**5:
  print("90909")
elif N >= 10**4:
  resid=N-10**4+1
  print(str(9+900+resid))
elif N >= 10**3:
  print("909")
elif N >= 10**2:
  resid=N-10**2+1
  print(str(9+resid))
elif N >= 10:
  print("9")
else:
  print(str(N))

Buggy submission (verdict: Runtime Error):
N=int(input())
if N = 10**5:
  print("90909")
elif N >= 10**4:
  resid=N-10**4+1
  print(str(9+900+resid))
elif N >= 10**3:
  print("990")
elif N >= 10**2:
  resid=N-10**2+1
  print(str(9+resid))
elif N >= 10:
  print("9")
else:
  print(str(N))
Problem p02953 (python)

Fixed submission:
n=int(input())
h=list(map(int, input().split()))
h.reverse()
a=0
for i in range(len(h)-1):
  if h[i]+1 < h[i+1]:
    a+=1
    break
  elif h[i]+1==h[i+1]:
    h[i+1]=h[i+1]-1
  else:
    pass
if a==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
h=list(map(int, input().split()))
h=reversed(h)
a=0
for i in range(length(h)-1):
  if h[i]+1 < h[i+1]:
    a+=1
    break
  elif h[i]+1==h[i+1]:
    h[i+1]=h[i+1]-1
  else:
    pass
if a==0:
  print("Yes")
else:
  print("No")
Problem p02981 (python)

Fixed submission:
n,a,b=input().strip().split()
n,a,b=[int(n),int(a),int(b)]

if n*a>b:
  print(b)
else:
  print(n*a)

Buggy submission (verdict: Runtime Error):
n,a,b=int(input().strip().split())

if n*a>=b:
  print(b)
else:
  print(n*a)

Buggy submission (verdict: Runtime Error):
n,a,b=int(input().strip().split)

train=n*a
taxi=b

fare=min(taxi,train)

print(str(fare))
Problem p03087 (python)

Fixed submission:
n, q = map(int, input().split())
s = input()
count = [0]*n
for i in range(1, n):
    count[i] = count[i-1]
    if s[i - 1: i + 1] == "AC":
        count[i] += 1

for i in range(q):
    l, r = map(int, input().split())
    print(count[r-1]-count[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
S = input()
partS = []
for _ in range(q):
    l, r = map(int, input().split())
    partS .append(S[l - 1:r])
for i in range(q):
    print(partS[i].count("AC"))
Problem p03486 (python)

Fixed submission:
S = input()
T = input()
s = list(S)
t = list(T)
s.sort()
t.sort()
t.reverse()
print("Yes" if s < t else "No")

Buggy submission (verdict: Runtime Error):
s = [*input()]
t = [*input()]
s.sort()
t.sort()
t.reverse()
print("Yes" if s < t else "No")
Problem p02867 (python)

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
import operator
import numpy

def check_cycle(i_pair):
    i_orig_sorted_dict = {i_orig: i_sort for i_orig, i_sort in i_pair}
    cycle_dict = {}
    for i_orig, i_sort in i_pair:
        i_current = i_orig
        while True:
            if not i_current in cycle_dict:
                cycle_dict[i_current] = i_orig
            else:
                break
            i_current = i_orig_sorted_dict[i_current]
    return len(numpy.unique(list(cycle_dict.values())))


N, = map(int, sys.stdin.readline().rstrip().split(" "))
As = list(map(int, sys.stdin.readline().rstrip().split(" ")))
Bs = list(map(int, sys.stdin.readline().rstrip().split(" ")))
AB_sorted = list(sorted(zip(As, Bs), key=operator.itemgetter(1)))
Bs = list(map(operator.itemgetter(1), AB_sorted))
As_original = list(map(operator.itemgetter(0), AB_sorted))
A_i_pair = [(i_orig, i_sort) for i_sort, (i_orig, value) in enumerate(sorted(enumerate(As_original), key=operator.itemgetter(1)))]
As.sort()

# print(Bs)
# print(As_original)
# print(As)

A_reserve_dict = {}
last_reserve = None
for i in range(len(As)):
    if As[i] > Bs[i]:
        print("No")
        break
else:
    # for i in range(len(As)):
    #     if As[i] == As_original[i]:  # すでに一致してる = 1回減らせる
    #         print("Yes")
    #         break
    if check_cycle(A_i_pair) >= 2:
        print("Yes")
    else:
        for i in range(len(As) - 1):
            if As[i + 1] <= Bs[i]:  # i と i+1はどちらでもいい = 1回減らせる
                print("Yes")
                break
        else:
            print("No")
exit(0)

# Fails
# 1 2 3
# 2 3 1

# Fails
# 1 2 3 4
# 3 4 2 1

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
import operator

# def check_cycle

N, = map(int, sys.stdin.readline().rstrip().split(" "))
As = list(map(int, sys.stdin.readline().rstrip().split(" ")))
Bs = list(map(int, sys.stdin.readline().rstrip().split(" ")))
AB_sorted = list(sorted(zip(As, Bs), key=operator.getitem(1)))
As_original = list(map(operator.getitem(0), AB_sorted))
As.sort()

A_reserve_dict = {}
last_reserve = None
for i in range(len(As)):
    if As[i] > Bs[i]:
        print("No")
        break
else:
    for i in range(len(As)):
        if As[i] == As_original[i]: # すでに一致してる = 1回減らせる
            print("Yes")
            break
    else:
        for i in range(len(As)-1):
            if As[i+1] <= Bs[i]: # i と i+1はどちらでもいい = 1回減らせる
                print("Yes")
                break
        else:
            print("No")
exit(0)

# Fails
# 1 2 3
# 2 3 1

# Fails
# 1 2 3 4
# 3 4 2 1
Problem p03037 (python)

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, M = map(int, sys.stdin.readline().rstrip().split(" "))
Lmax, Rmin = 0, N
for _ in range(M):
    L, R = map(int, sys.stdin.readline().rstrip().split(" "))
    Lmax = max(L, Lmax)
    Rmin = min(R, Rmin)
if Rmin >= Lmax:
    print(Rmin - Lmax + 1)
else:
    print(0)
exit(0)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N,M = map(int, sys.stdin.readline().rstrip().split(" "))
Lmax, Rmin = 0, N
for _ in range(M):
    L, R = map(int, sys.stdin.readline().rstrip().split(" "))
    Lmax = max(L, Lmax)
    Rmin = min(R, Rmin)
assert Rmin >= Lmax
print(Rmin - Lmax + 1)
exit(0)
Problem p03160 (python)

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**10

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

ans = solve(costs + [INF] * 2)
assert ans < INF
print(ans)
exit(0)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**8

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

ans = solve(costs + [INF] * 2)
assert ans < INF
print(ans)
exit(0)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**8

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

print(solve(costs + [INF] * 2))
exit(0)