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

def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2


n=int(input())
a=list(map(int,input().split()))
d1=dict()
for i in a:
    if i not in d1:
        d1[i]=1
    else:
        d1[i] += 1
#print(d1)
d2={i:ABC159D(j) for i,j in d1.items()}
d3={i:ABC159D(j-1)-d2[i] for i,j in d1.items()}
#print(d2,d3)
p=sum(d2.values())
print(''.join([p+d3[i] for i in a]))

Fixed submission:
import math

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
for i in a:
    d=mycounter(d,i)
p=sum([ABC159D(i) for i in d.values()])
for i in a:
    print(p-d[i]+1)

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

def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2


n=int(input())
a=list(map(int,input().split()))
d1=dict()
for i in a:
    if i not in d1:
        d1[i]=1
    else:
        d1[i] += 1
#print(d1)
d2={i:ABC159D(j) for i,j in d1.items()}
d3={i:ABC159D(j-1)-d2[i] for i,j in d1.items()}
#print(d2,d3)
p=sum(d2.values())
for i in a:
    print(p+d3[i])
    


Fixed submission:
import math

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
for i in a:
    d=mycounter(d,i)
p=sum([ABC159D(i) for i in d.values()])
for i in a:
    print(p-d[i]+1)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c=map(int, input().split()) 
if a < 0 or b < 0 or c < 0:
  print('Yes')
else:
  if (math.sqrt(a) + math.sqrt(b)) < math.sqrt(c):
    print('Yes')
  else:
    print('No')


Fixed submission:
f = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(f[k-1])

Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
if a = 1 or b = 1:
	print(1)
else:
	print(-(-1 * a * b // 2))

Fixed submission:
f = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(f[k-1])

Buggy python submission (verdict: Runtime Error):
f = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(f[k])

Fixed submission:
f = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(f[k-1])
Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
if a = 1 or b = 1:
	print(1)
else:
	print(-(-1 * a * b // 2))

Fixed submission:
a,b=map(int, input().split())
if a == 1 or b == 1:
	print(1)
else:
	print(-(-1 * a * b // 2))

Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())
if a = 1 or b = 1:
  print(1)
else:
print(-(-1 * a * b // 2))

Fixed submission:
a,b=map(int, input().split())
if a == 1 or b == 1:
	print(1)
else:
	print(-(-1 * a * b // 2))
Buggy python submission (verdict: Runtime Error):
a = input()
if a == 'hi' or a == 'hihi' or a == 'hihihi' or a == 'hihihihi' or a == 'hihihihihi' or a == 'hihihihihi' 
  print('Yes')
else:
  print('No')

Fixed submission:
a = input()
if a == 'hi' or a == 'hihi' or a == 'hihihi' or a == 'hihihihi' or a == 'hihihihihi' or a == 'hihihihihi':
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a = input()
if a == 'hi' or a == 'hihi' or a == 'hihihi' or a == 'hihihihi' or a == 'hihihihihi' or a == 'hihihihihi' or 
  print('Yes')
else:
  print('No')

Fixed submission:
a = input()
if a == 'hi' or a == 'hihi' or a == 'hihihi' or a == 'hihihihi' or a == 'hihihihihi' or a == 'hihihihihi':
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a = input()
if a = 'hi' or a = 'hihi' or a = 'hihihi' or a = 'hihihihi' or a = 'hihihihihi' or a = 'hihihihihi' or 
  print('Yes')
else:
  print('No')

Fixed submission:
a = input()
if a == 'hi' or a == 'hihi' or a == 'hihihi' or a == 'hihihihi' or a == 'hihihihihi' or a == 'hihihihihi':
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
a = input()
if a='AAA' or a='BBB':
  print('No')
else:
  print('Yes')

Fixed submission:
a = input()
if a=='AAA' or a=='BBB':
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
r = False#ひっくり返されたか
for i in range(q):
  t=list(input().split())
  if len(t) == 1:#一つしか入力されていない
    r = not(r)
  else:
    if (t[1] == '1' and r == False):
      s = t[2] + s
    elif (t[1] == '2' and r == True):
      s = t[2] + s
    else:
      s = s + t[2]
if r:
  print(s[::-1])
else:
  print(s)

Fixed submission:
s = input()
q = int(input())
r = False#ひっくり返されたか
f = ''#in front of#逆転しているので最後に戻しましょう
b = '' #behind
for i in range(q):
  t=list(input().split())
  if len(t) == 1:#一つしか入力されていない
    r = not(r)
  else:
    if (t[1] == '1' and r == False):
      f += t[2]
    elif (t[1] == '2' and r == True):
      f += t[2]
    else:
      b += t[2]
s = f[::-1] + s + b
if r:
  print(s[::-1])
else:
  print(s)

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
r = False#ひっくり返されたか
for i in range(q):
  t=list(input().split())
  if len(t) == 1:#一つしか入力されていない
    r = not(r)
  else:
    if t[1] == '1' and r = False
      s = t[2] + s
    elif t[1] == '2' and r = True:
      s = t[2] + s
    else:
      s = s + t[2]
print(s)

Fixed submission:
s = input()
q = int(input())
r = False#ひっくり返されたか
f = ''#in front of#逆転しているので最後に戻しましょう
b = '' #behind
for i in range(q):
  t=list(input().split())
  if len(t) == 1:#一つしか入力されていない
    r = not(r)
  else:
    if (t[1] == '1' and r == False):
      f += t[2]
    elif (t[1] == '2' and r == True):
      f += t[2]
    else:
      b += t[2]
s = f[::-1] + s + b
if r:
  print(s[::-1])
else:
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
  t=list(input().split())
  if len(t) == 1:#一つしか入力されていない
    s = s[::-1]#逆にする
  else:
    if t[1] == '1':
      s = t[2] + s
    else:
      s = s + t[2]
print(s)

Fixed submission:
s = input()
q = int(input())
r = False#ひっくり返されたか
f = ''#in front of#逆転しているので最後に戻しましょう
b = '' #behind
for i in range(q):
  t=list(input().split())
  if len(t) == 1:#一つしか入力されていない
    r = not(r)
  else:
    if (t[1] == '1' and r == False):
      f += t[2]
    elif (t[1] == '2' and r == True):
      f += t[2]
    else:
      b += t[2]
s = f[::-1] + s + b
if r:
  print(s[::-1])
else:
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
d=dict()
for i in range(int(input())):
    s=input()
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
max_v = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max(d.values())]))

Fixed submission:
d=dict()
for i in range(int(input())):
    s=input()
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
max_v = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max_v]))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
b = ''
for i in range(n):
    b += (input() + ' ')
a = list(b.split())
a_count = [a.count(i) for i in a]
print('\n'.join(sorted(set([a[i] for i in range(len(a_count)) if a_count[i] == max(a_count)]))))


Fixed submission:
d=dict()
for i in range(int(input())):
    s=input()
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
max_v = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max_v]))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = []
for i in range(n):
    a.append(input())
a_count = [a.count(i) for i in a]
print('\n'.join(sorted(set([a[i] for i in range(len(a_count)) if a_count[i] == max(a_count)]))))


Fixed submission:
d=dict()
for i in range(int(input())):
    s=input()
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
max_v = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max_v]))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a = []
for i in range(n):
    a.append(input())
a_count = [a.count(i) for i in a]
print('\n'.join(sorted(set([a[i] for i in range(len(a_count)) if a_count[i] == max(a_count)])))



Fixed submission:
d=dict()
for i in range(int(input())):
    s=input()
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
max_v = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max_v]))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = []
for i in range(n):
    a.append(input())
a_count = [a.count(i) for i in a]
[print(j) for j in sorted(set([a[i] for i in range(len(a_count)) if a_count[i] == max(a_count)]))]

Fixed submission:
d=dict()
for i in range(int(input())):
    s=input()
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
max_v = max(d.values())
print(*sorted([kv[0] for kv in d.items() if kv[1] == max_v]))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
p = list(map(int, input().split()))
a = [0 for i in range(n-k+1)]
for i in range(n-k+1):
    a[i]=(sum(p[i:i+k]))
print((max(a)+k)/2)


Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
r=[0]
for i in range(n):
    r.append(r[i]+p[i])
p=0
for i in range(k,n+1):
    p=max(p,r[i]-r[i-k])
print('{:.10f}'.format((p+k)/2))

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


Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
r=[0]
for i in range(n):
    r.append(r[i]+p[i])
p=0
for i in range(k,n+1):
    p=max(p,r[i]-r[i-k])
print('{:.10f}'.format((p+k)/2))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
p = list(map(int, input().split()))
a = []
for i in range(n-k+1):
    a.append(sum(p[i:i+k]))
print((max(a)+k)/2)


Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
r=[0]
for i in range(n):
    r.append(r[i]+p[i])
p=0
for i in range(k,n+1):
    p=max(p,r[i]-r[i-k])
print('{:.10f}'.format((p+k)/2))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
p = list(map(int, input().split()))
a = []
for i in range(n-k+1):
    a.append(sum(p[i:i+k]))
print((max(a)+k)/2)


Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
r=[0]
for i in range(n):
    r.append(r[i]+p[i])
p=0
for i in range(k,n+1):
    p=max(p,r[i]-r[i-k])
print('{:.10f}'.format((p+k)/2))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=list(map(int,input().split()))
a=1
for i in range(1,n):
    if min(p[:i])>=p[i]:
        a+=1
print(a)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
a=1
f=p[0]
for i in range(1,n):
    f=min(f,p[i])
    if f>=p[i]:
        a+=1
print(a)
Buggy python submission (verdict: Runtime Error):
n,k,s=map(int,input().split())
a=[s]*k
b=[3]*(n-k)+[2]*k
p=s//2-1
for i in range(n-k):
    if i%p==0:
        a.append(s-1)
    else:
        a.append(2)
if s!=2:
    print(*a)
else:
    print(*b)

Fixed submission:
n,k,s=map(int,input().split())
a=[s]*k
b=[3]*(n-k)+[s]*k
p=max(s//2-1,1)
for i in range(n-k):
    if i%p==0:
        a.append(s-1)
    else:
        a.append(2)
if s!=2 and s!=1:
    print(*a)
else:
    print(*b)

Buggy python submission (verdict: Runtime Error):
n,k,s=map(int,input().split())
a=list()
b=[2]*(n-k)+[1]*k
while len(a)<n:
    k-=1
    a+=[1]*(s-1)+[s]
a+=[s]*k
if s!=1:
    print(*a[len(a)-n:])
else:
    print(*b)

Fixed submission:
n,k,s=map(int,input().split())
a=[s]*k
b=[3]*(n-k)+[s]*k
p=max(s//2-1,1)
for i in range(n-k):
    if i%p==0:
        a.append(s-1)
    else:
        a.append(2)
if s!=2 and s!=1:
    print(*a)
else:
    print(*b)

Buggy python submission (verdict: Runtime Error):
n,k,s=map(int,input().split())
a=list()
b=[2]*(n-k)+[1]*k
while len(a)<n:
    a+=[1]*(s-1)+[s]
if s!=1:
    print(*a[len(a)-n:])
else:
    print(*b)

Fixed submission:
n,k,s=map(int,input().split())
a=[s]*k
b=[3]*(n-k)+[s]*k
p=max(s//2-1,1)
for i in range(n-k):
    if i%p==0:
        a.append(s-1)
    else:
        a.append(2)
if s!=2 and s!=1:
    print(*a)
else:
    print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    while len(a)>i:
        if a[i]!=i+1 and a!=[]:
            a=a[:i]+a[i+1:]
        else:
            break
    if a==list(range(1,i+1)) or a==[]:
        #print('Yay!')
        break
#print(a)
print(n-len(a) if a!=[] else -1)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
p=1
for i in a:
    if i==p:
        p+=1
print(n-p+1 if p!=1 else -1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
a=0
for i in range(1000):
    t=str(i).zfill(3)
    p=0
    for j in s:
        if j==t[p]:
            p+=1
        if p==3:
            #print(t,p)
            break
    if p==3:
        a+=1
print(a)

Fixed submission:
n=int(input())
s=input()
a=0
for i in range(1000):
    t=str(i).zfill(3)
    p=0
    for j in s:
        if j==t[p]:
            p+=1
        if p==3:
            #print(t,p)
            break
    if p==3:
        a+=1
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
suma=sum(a)
p=suma
for i in range(n):
    f=sum(a[:i])
    p=min(p,abs(suma-2*f))
print(p)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
suma=sum(a)
f=0
p=suma-2*f
for i in a:
    f+=i
    p=min(p,abs(suma-2*f))
print(p)
Buggy python submission (verdict: Runtime Error):
a,b=map(int input().split())
if a<10 and b<10:
    print(a*b)
else:
    print(-1)

Fixed submission:
a,b=map(int, input().split())
if a<10 and b<10:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = ''
for i in range(1,n+1):
    ans+=(str(a.index(i)+1)+' ')
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in range(n):
    b[a[i]-1] = i+1
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = ''
for i in range(1,n+1):
    ans+=(str(a.index(i)+1)+' ')
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in range(n):
    b[a[i]-1] = i+1
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = []
for i in range(1,n+1):
    ans.append(1+a.index(i))
print(' '.join(map(str, ans)))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
for i in range(n):
    b[a[i]-1] = i+1
print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,*a=open(0).read().split()
a=[''.join(sorted(i)) for i in a]
p=0
for i,j in itertools.combinations(range(int(n)),2):
    #print(i,j)
    if a[i]==a[j]:
        p+=1
print(p)

Fixed submission:
import math

def ABC137C(i):
    if i!=1:
        return math.factorial(i)//math.factorial(i-2)//2
    else:
        return 0

n,*a=open(0).read().split()
a=[''.join(sorted(i)) for i in a]
d=dict()
p=0
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d.values():
    p+=ABC137C(i)
print(p)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
e=c//math.gcd(c,d)*d
print(b-b//c-b//d+b//e-(a-1-(a-1)//c-(a-1)//d+(a-1)//e))

Fixed submission:
def ABC162C(a,b):#from:https://atcoder.jp/contests/abc162/submissions/11871774
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return max(a,b)
    

a,b,c,d=map(int,input().split())
e=c//ABC162C(c,d)*d
print(b-b//c-b//d+b//e-(a-1-(a-1)//c-(a-1)//d+(a-1)//e))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
for i in range(c,1,-1):#cから2まで
    if c % i == 0 and d % i == 0:
        s = i
        break
s = (c // s) * (d // s) * s
print(b - a + 1 - b//c + a//c - b//d + a//d + b//s - a//s)

Fixed submission:
def ABC162C(a,b):#from:https://atcoder.jp/contests/abc162/submissions/11871774
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return max(a,b)
    

a,b,c,d=map(int,input().split())
e=c//ABC162C(c,d)*d
print(b-b//c-b//d+b//e-(a-1-(a-1)//c-(a-1)//d+(a-1)//e))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
for i in range(c,1,-1):#cから2まで
    if c % i == 0 and d % i == 0:
        s = i
        break
s = (c // s) * (d // s) * s
print(s)
print(b - a + 1 - b//c + a//c - b//d + a//d + b//s - a//s)


Fixed submission:
def ABC162C(a,b):#from:https://atcoder.jp/contests/abc162/submissions/11871774
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return max(a,b)
    

a,b,c,d=map(int,input().split())
e=c//ABC162C(c,d)*d
print(b-b//c-b//d+b//e-(a-1-(a-1)//c-(a-1)//d+(a-1)//e))
Buggy python submission (verdict: Runtime Error):
n,m,*a=map(int,open(0).read().split())
mod=10**9+7
p=[1]
a=iter(a)
b=a.__next__()
if 1==b:
    p.append(0)
    b=next(a,-1)
else:
    p.append(1)
for i in range(2,n+1):
    if i==b:
        p.append(0)
        b=next(a,-1)
        print(i)
    else:
        p.append((p[i-1]+p[i-2])%mod)
print(p[-1])

Fixed submission:
n,m,*a=map(int,open(0).read().split())
mod=10**9+7
p=[1]
a=iter(a)
b=next(a,-1)
if 1==b:
    p.append(0)
    b=next(a,-1)
else:
    p.append(1)
for i in range(2,n+1):
    if i==b:
        p.append(0)
        b=next(a,-1)
    else:
        p.append((p[i-1]+p[i-2])%mod)
print(p[-1])
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))
for i in range(h):
    l.append("#"+input()+"#")
l.append('#'*(w+2))
si=[[0 for i in j] for j in l]
sj=[[0 for i in j] for j in l]
for i in range(h+2):
    k=0
    for j in range(w+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(j-k,j):
                si[i][f]=k
            k=0
for j in range(w+2):
    k=0
    for i in range(h+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(i-k,i):
                sj[f][j]=k
            k=0
ans=0
for i in range(h+2):
    for j in range(w+2):
        ans=max(ans,sj[i][j]+si[i][j])
print(ans-1)

Fixed submission:
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))
for i in range(h):
    l.append("#"+input()+"#")
l.append('#'*(w+2))
si=[[0 for i in j] for j in l]
sj=[[0 for i in j] for j in l]
for i in range(h+2):
    k=0
    for j in range(w+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(j-k,j):
                si[i][f]=k
            k=0
for j in range(w+2):
    k=0
    for i in range(h+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(i-k,i):
                sj[f][j]=k
            k=0
ans=0
for i in range(h+2):
    for j in range(w+2):
        ans=max(ans,sj[i][j]+si[i][j])
print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l,r=map(int,input().split())
a=set(range(l,r+1))
for i in range(m-1):
    l,r=map(int,input().split())
    a.intersection_update(range(l,r+1))
print(len(a))


Fixed submission:
n,m=map(int,input().split())
ll,rr=0,n
for i in range(m):
    l,r=map(int,input().split())
    ll=max(l,ll)
    rr=min(r,rr)
print(max(rr-ll+1,0))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l,r=map(int,input().split())
a=set(range(l,r+1))
for i in range(m-1):
    l,r=map(int,input().split())
    a.intersection_update(range(l,r+1))
print(len(a))

Fixed submission:
n,m=map(int,input().split())
ll,rr=0,n
for i in range(m):
    l,r=map(int,input().split())
    ll=max(l,ll)
    rr=min(r,rr)
print(max(rr-ll+1,0))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
l=list()
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-x[1])
i=0
for b,c in l:
    for j in range(b):
        if a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
    i+=b
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
l=list()
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-x[1])
i=0
for b,c in l:
    for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
    i+=b
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
p=0
i,j=0,0
while j < n+1:
    k=i*r+j*g
    if (n-k)%b==0 and k <= n:
        #print(i,j,n-k)
        p+=1
    i+=1
    if i>n:
        i=0
        j+=1
print(p)

Fixed submission:
r,g,b,n=map(int,input().split())
p=0
i,j=0,0
while j < n+1:
    k=i*r+j*g
    if (n-k)%b==0 and k <= n:
        #print(i,j,n-k)
        p+=1
    i+=1
    if i>n:
        i=0
        j+=1
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w=map(int,input().split())
l=[]
l.append('@'*(w+2))
for i in range(h):
    l.append('@'+input()+'@')
l.append('@'*(w+2))
q=deque()
p=[[-1 for i in j] for j in l]
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='#':
            q.append([i,j])
            p[i][j]=0
while len(q)>0:
    x,y=q.popleft()
    for i,j in [[1,0],[-1,0],[0,-1],[0,1]]:
        if l[x+i][y+j]=='.' and p[x+i][y+j]==-1:
            q.append([x+i,y+j])
            p[x+i][y+j]=p[x][y]+1
a=0
for i in p:
    for j in i:
        a=max(a,j)
print(a)
#print(*p,sep='\n')

Fixed submission:
from collections import deque
h,w=map(int,input().split())
l=[]
l.append('@'*(w+2))
for i in range(h):
    l.append('@'+input()+'@')
l.append('@'*(w+2))
q=deque()
p=[[-1 for i in j] for j in l]
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='#':
            q.append([i,j])
            p[i][j]=0
while len(q)>0:
    x,y=q.popleft()
    for i,j in [[1,0],[-1,0],[0,-1],[0,1]]:
        if l[x+i][y+j]=='.' and p[x+i][y+j]==-1:
            q.append([x+i,y+j])
            p[x+i][y+j]=p[x][y]+1
a=0
for i in p:
    for j in i:
        a=max(a,j)
print(a)
#print(*p,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count('AC'))

Fixed submission:
n,q=map(int,input().split())
s = input()
a = [0,0]
for i in range(1,n):
    a.append(a[i]+(s[i-1]=="A" and s[i]=='C'))
for i in range(q):
    l,r=map(int,input().split())
    print(a[r]-a[l-1]-(s[l-2]=='A' and s[l-1]=='C'))