Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from itertools import product
A,B,Q = map(int,input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(input())
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])  
        if 0 <= r1 <= ab[i]-1:
            cand1.add(st[r1])
        if 0 <= r1+1 <= ab[i]-1:
            cand1.add(st[r1+1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)
        
        
    

Fixed submission:
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = map(int,input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(input())
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])  
        if 0 <= r1 <= ab[i]-1:
            cand1.add(st[r1])
        if 0 <= r1+1 <= ab[i]-1:
            cand1.add(st[r1+1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
array2 = [0 for i in range(M+1)]
for i in range(N):
  array = list(map(int,input().split()))
  array.pop[0]
  for j in array:
    array2[j] += 1
c = 0
for k in array2:
  if k == N:
    c += 1
print(c)
  

Fixed submission:
N,M = map(int,input().split())
array2 = [0 for i in range(M+1)]
for i in range(N):
  array = list(map(int,input().split()))
  array.pop(0)
  for j in array:
    array2[j] += 1
c = 0
for k in array2:
  if k == N:
    c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(set(map(int,input().split())))
num = {}
num2 = [0,2,5,5,4,5,6,3,7,6]
for i in range(1,10):
    if i in A:
        num[i] = num2[i]
num3 = sorted(list(num.items()),key = lambda x:x[1])
A = [str(i[0]) for i in num3]
num = [i[1] for i in num3]
minum = num[0]
dp = [[0 for i in range(N+1)] for j in range(N//minum+1)]
dp[0][0] = '1'
for i in range(1,N//minum+1):
    for j in range(N+1):
        for k in range(len(num)):
            if j-num[k] >= 0 and dp[i-1][j-num[k]] != 0:
                if dp[i][j] != 0:
                    if dp[i-1][j] == 0:
                        dp[i][j] = str(max(int(dp[i][j]),int(''.join(sorted(list(dp[i-1][j-num[k]]+A[k]),reverse=True)))))
                    else:
                        dp[i][j] = str(max(int(dp[i][j]),int(dp[i-1][j]),int(''.join(sorted(list(dp[i-1][j-num[k]]+A[k]),reverse=True)))))
                else:
                    if dp[i-1][j] == 0:
                        dp[i][j] = ''.join(sorted(list(dp[i-1][j-num[k]]+A[k]),reverse=True))
                    else:
                        dp[i][j] = str(max(int(dp[i-1][j]),int(''.join(sorted(list(dp[i-1][j-num[k]]+A[k]),reverse=True)))))
            else:
                if dp[i-1][j] != 0:
                    if dp[i][j] != 0:
                        dp[i][j] = str(max(int(dp[i][j]),int(dp[i-1][j])))
                    else:
                        dp[i][j] = dp[i-1][j]
print(dp[-1][-1][:-1])


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

def lenmax(a,b):
    if len(a) > len(b):
        return a
    elif len(a) < len(b):
        return b
    return max(a,b)

dp = ['-' for i in range(10**4+10)]
dp[0] = ''
for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+num[a]] = lenmax(dp[i+num[a]],dp[i]+str(a))
print(dp[N])
Buggy python submission (verdict: Runtime Error):
lista = []
for i in range(3):
  a,b = map(int,input().split()))
  lista.append(a)
  lista.append(b)
l1 = 0
l2 = 0
l3 = 0
l4 = 0
for j in lista:
  if j == 1:
    l1 += 1
  if j == 2:
    l2 += 1
  if j == 3:
    l3 += 1
  if j == 4:
    l4 += 1
c = l1%2 + l2%2 + l3%2 + l4%2
if c%2 == 0:
  print('YES')
else:
  print('NO')
  


Fixed submission:
lista = []
for i in range(3):
  a,b = map(int,input().split())
  lista.append(a)
  lista.append(b)
l1 = 0
l2 = 0
l3 = 0
l4 = 0
for j in lista:
  if j == 1:
    l1 += 1
  if j == 2:
    l2 += 1
  if j == 3:
    l3 += 1
  if j == 4:
    l4 += 1
c = (l1)%2 + (l2)%2 + (l3)%2 + (l4)%2
if c <= 2:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    K,A,B = map(int,input().split())
    if A +2 >= B:
        print(K+1)
    else:
        
        dp = [1,2]+[0 for i in range(K-1)]
        for i in range(2,K+1):
            if dp[i-2] == -1:
                if dp[i-1] >= A:
                    dp[i] =-1
                else:
                    dp[i] = dp[i-1]+1
            else:
                if dp[i-2] >= A:
                    dp[i] = dp[i-2]-A+B
                elif dp[i-1] >= A:
                    dp[i] = -1
                else:
                    dp[i] = dp[i-1]+1

        if dp[-1] == -1:
            print(dp[-2]+1)
        else:
            print(dp[-1])
main()


Fixed submission:
def main():
    K,A,B = map(int,input().split())
    sum = K+1
    
    if A + 2>= B or K <= A:
        print(K+1)
    else:
        if (K-A+1)%2 == 0:
            sum = (((K-A+1)//2)-1)*(B-A)+B
        else:
            sum = (((K-A+1)//2)-1)*(B-A)+1+B
        print(sum)
main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
Larray = list(map(int,input().split()))
lmax = max(Larray)
Larray.remove(lmax)
ltot = 0
for i in range(Larray):
  ltot += i
if lmax > ltot:
  print('Yes')
else:
  print('No')


Fixed submission:
N = int(input())
Larray = list(map(int,input().split()))
lmax = max(Larray)
Larray.remove(lmax)
ltot = 0
for i in Larray:
  ltot += i
if lmax < ltot:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    dp = [0]*N
    array = []
    sum = 0
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)
    num = [[0,0,0] for z in range(N)]
    dp[0] = max(array[0][n] for n in range(3))
    for m in range(3):
        if dp[0] == array[0][m]:
            num[0][m] = 1
    
    
    for z in range(3):
        if num[0][z] == 1:
            dp[1] = max(dp[1],max(array[1][1],array[1][2])+dp[0])
            num[1][z] = 1
    

    for j in range(2,N):
        dpj = []
        for z in range(3):
            if 1 == num[j-1][z]:
                num[j][z] = 1
                dpj.append(max(array[j][1],array[j][2])+dp[j-1])
        dp[j] = max(dpj)
    
    print(dp[-1])
    
main()

Fixed submission:
def main():
    N = int(input())
    
    array = []
    
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)

    num = [[0,0,0] for z in range(N)]
    for m in range(3):
        num[0][m] = array[0][m]

    

    for j in range(1,N):
        
        for z in range(3):
            if z == 0:
                num[j][z] = array[j][z]+max(num[j-1][1],num[j-1][2])
                    
            if z == 1:
                num[j][z] =array[j][z]+max(num[j-1][0],num[j-1][2])
            if z == 2:
                num[j][z] =array[j][z]+max(num[j-1][1],num[j-1][0])
        
    
    print(max(num[-1]))
    
main()

Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    dp = [0]*N
    array = []
    sum = 0
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)
    num = [[0,0,0] for z in range(N)]
    dp[0] = max(array[0][n] for n in range(3))
    for m in range(3):
        if dp[0] == array[0][m]:
            num[0][m] = 1
    
    
    for z in range(3):
        if num[0][z] == 1:
            dp[1] = max(dp[1],max(array[1][1],array[1][2])+dp[0])
            num[1][z] = 1
    
    print(num)
    for j in range(2,N):
        dpj = []
        for z in range(3):
            if 1 == num[j-1][z]:
                num[j][z] = 1
                dpj.append(max(array[j][1],array[j][2])+dp[j-1])
        dp[j] = max(dpj)
    
    print(dp[-1])
    
main()

Fixed submission:
def main():
    N = int(input())
    
    array = []
    
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)

    num = [[0,0,0] for z in range(N)]
    for m in range(3):
        num[0][m] = array[0][m]

    

    for j in range(1,N):
        
        for z in range(3):
            if z == 0:
                num[j][z] = array[j][z]+max(num[j-1][1],num[j-1][2])
                    
            if z == 1:
                num[j][z] =array[j][z]+max(num[j-1][0],num[j-1][2])
            if z == 2:
                num[j][z] =array[j][z]+max(num[j-1][1],num[j-1][0])
        
    
    print(max(num[-1]))
    
main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
dp = [[0 for i in range(len(s)+1)] for j in range(len(t)+1)]
for i in range(len(t)):
    for j in range(len(s)):
        if s[j] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

ans = ''
i = len(t)
j = len(s)
while i >= 1 and j >= 1:
    if dp[i][j] == dp[i-1][j]:
        i -= 1    
    elif dp[i][j] == dp[i][j-1]:
        j -= 1    
    else:
        ans = s[j-1] + ans
        i -= 1
        j -= 1
print(ans)

Fixed submission:
s = input()
t = input()
dp = [[0 for i in range(len(s)+1)] for j in range(len(t)+1)]
for i in range(len(t)):
    for j in range(len(s)):
        if s[j] == t[i]:
            dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

ans = ''
i = len(t)
j = len(s)
while i >= 1 and j >= 1:
    if dp[i][j] == dp[i-1][j]:
        i -= 1    
    elif dp[i][j] == dp[i][j-1]:
        j -= 1    
    else:
        ans = s[j-1] + ans
        i -= 1
        j -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
if N == 1:
    print(P)
else:
    for i in range(int(P**(0.5))+1,0,-1):
        if P%(i**N) == 0:
            print(i)
            break

Fixed submission:
from collections import Counter
N,P = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
p = Counter(prime_factorize(P))
ans = 1
for k,v in p.items():
    if v >= N:
        ans *= k**(v//N)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,P = map(int,input().split())
if N == 1:
    print(P)
else:
    for i in range(int(P**(0.5))+1,0,-1):
        if P%(i**N) == 0:
            print(i)
            break

Fixed submission:
from collections import Counter
N,P = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
p = Counter(prime_factorize(P))
ans = 1
for k,v in p.items():
    if v >= N:
        ans *= k**(v//N)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
def gcd(a,b):
    if a >= b:
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    else:
        if a == 0:
            return b
        else:
            return gcd(a,b%a)
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
else:
    flag = True
    L = int((N//gcd(N,M))*M)
    m = L//M
    n = L//N
    for i in range(min(N,M)):
        if i*m <= N-1 and i*n <= M-1:
            if S[i*m*L//N] != T[i*n*L//M]:
                flag = False
                break
    if flag:
        print(L)
    else:
        print(-1)


Fixed submission:
N,M = map(int,input().split())
def gcd(a,b):
    if a >= b:
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    else:
        if a == 0:
            return b
        else:
            return gcd(a,b%a)
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
else:
    flag = True
    L = int((N//gcd(N,M))*M)
    m = L//M
    n = L//N
    for i in range(max(N,M)):
        if i*m <= N-1 and i*n <= M-1:
            if S[i*m] != T[i*n]:
                flag = False
                break
    if flag:
        print(L)
    else:
        print(-1)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
def gcd(a,b):
    if a >= b:
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    else:
        if a == 0:
            return b
        else:
            return gcd(a,b%a)
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
else:
    flag = True
    if N//M >= 2:
        for i in range(M):
            x = (N*i)//M
            if T[x*(L//M)+1] != S[i*(L//N)+1]:
                flag = False
    if M//N >= 2:
        for i in range(N):
            y = (N*i)//M
            if T[i*(L//M)+1] != S[y*(L//N)+1]:
                flag = False
    if flag:
        print(int((N//gcd(N,M))*M))
    else:
        print(-1)


Fixed submission:
N,M = map(int,input().split())
def gcd(a,b):
    if a >= b:
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    else:
        if a == 0:
            return b
        else:
            return gcd(a,b%a)
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
else:
    flag = True
    L = int((N//gcd(N,M))*M)
    m = L//M
    n = L//N
    for i in range(max(N,M)):
        if i*m <= N-1 and i*n <= M-1:
            if S[i*m] != T[i*n]:
                flag = False
                break
    if flag:
        print(L)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
ct = [list(map(int,input().split())) for i in range(N)]
ct = sorted([i for i in ct if i[1]<= T])
print(ct[0][0])

Fixed submission:
N,T = map(int,input().split())
ct = [list(map(int,input().split())) for i in range(N)]
ct = sorted([i for i in ct if i[1]<= T])
if ct:
    print(ct[0][0])
else:
    print('TLE')
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
if N > M//2+1:
    print(1)
else:
    maxa = 1
    for i in range(N,M//2+1):
        if M%i == 0:
            maxa = M//i
            break
    print(maxa)

Fixed submission:
N,M = map(int,input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
div = sorted(make_divisors(M))
div = [i for i in div if M//i >= N]
print(div[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
for i in range(n-k+1):
    x2 = x[i:i+k]
    if x2[0]*x2[-1] < 0:
        left = 2*abs(x2[0])+abs(x2[-1])
        right = 2*abs(x2[-1])+abs(x2[0])
        ans= min(ans,min(left,right))
    else:
        ans = min(ans,max(abs(x2[0]),abs(x2[-1])))
print(ans)

Fixed submission:
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
for i in range(n-k+1):
    if x[i]*x[i+k-1] < 0:
        left = 2*abs(x[i])+abs(x[i+k-1])
        right = 2*abs(x[i+k-1])+abs(x[i])
        ans= min(ans,min(left,right))
    else:
        ans = min(ans,max(abs(x[i]),abs(x[i+k-1])))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
for i in range(n-k+1):
    x2 = x[i:i+k]
    if x2[0]*x2[-1] < 0:
        left = 2*abs(x2[0])+abs(x2[-1])
        right = 2*abs(x2[-1])+abs(x2[0])
        ans= min(ans,min(left,right))
    else:
        ans = min(ans,max(abs(x2[0]),abs(x2[-1])))
print(ans)

Fixed submission:
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
for i in range(n-k+1):
    if x[i]*x[i+k-1] < 0:
        left = 2*abs(x[i])+abs(x[i+k-1])
        right = 2*abs(x[i+k-1])+abs(x[i])
        ans= min(ans,min(left,right))
    else:
        ans = min(ans,max(abs(x[i]),abs(x[i+k-1])))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = []
for i in range(n-k+1):
    x2 = x[i:i+k]
    if x2[0]*x2[-1] < 0:
        left = 2*abs(x2[0])+abs(x2[-1])
        right = 2*abs(x2[-1])+abs(x2[0])
        ans.append(min(left,right))
    else:
        ans.append(max(abs(x2[0]),abs(x2[-1])))
print(min(ans))

Fixed submission:
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
for i in range(n-k+1):
    if x[i]*x[i+k-1] < 0:
        left = 2*abs(x[i])+abs(x[i+k-1])
        right = 2*abs(x[i+k-1])+abs(x[i])
        ans= min(ans,min(left,right))
    else:
        ans = min(ans,max(abs(x[i]),abs(x[i+k-1])))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = []
for i in range(n-k+1):
    x2 = x[i:i+k]
    if x2[0]*x2[-1] < 0:
        left = 2*abs(x2[0])+abs(x2[-1])
        right = 2*abs(x2[-1])+abs(x2[0])
        ans.append(min(left,right))
    else:
        ans.append(max(abs(x2[0]),abs(x2[-1])))
print(min(ans))

Fixed submission:
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10**9
for i in range(n-k+1):
    if x[i]*x[i+k-1] < 0:
        left = 2*abs(x[i])+abs(x[i+k-1])
        right = 2*abs(x[i+k-1])+abs(x[i])
        ans= min(ans,min(left,right))
    else:
        ans = min(ans,max(abs(x[i]),abs(x[i+k-1])))
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
lr = [list(map(int,input().split())) for i in range(M)]
for l,r in lr:
    num[l-1][r-1] += 1

for j in range(N):
    for i in range(N-1,0,-1):
        num[i-1][j] += num[i][j]
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
pq = [list(map(int,input().split())) for i in range(M)]
for p,q in pq:
    print(num[p-1][q-1])


Fixed submission:
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    l,r = list(map(int,input().split()))
    l -= 1
    r -= 1
    num[l][r] += 1
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
for i in range(N-1,0,-1):
    for j in range(N):
        num[i-1][j] += num[i][j]
for i in range(Q):
    p,q = map(int,input().split())
    print(num[p-1][q-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q = map(int,input().split())
LR = []
num = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    l,r = list(map(int,input().split()))
    l -= 1
    r -= 1
    num[l][r] += 1
    LR.append([l,r])
LR.sort()
pq = []
for i in range(Q):
    p,q=list(map(int,input().split()))
    p -= 1
    q -= 1
    ans = 0
    for i in range(N-1,p-1,-1):
        ans += sum(num[i][:q+1])
    print(ans)
    


Fixed submission:
N,M,Q = map(int,input().split())
num = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    l,r = list(map(int,input().split()))
    l -= 1
    r -= 1
    num[l][r] += 1
for i in range(N):
    for j in range(N-1):
        num[i][j+1] += num[i][j]
for i in range(N-1,0,-1):
    for j in range(N):
        num[i-1][j] += num[i][j]
for i in range(Q):
    p,q = map(int,input().split())
    print(num[p-1][q-1])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N,M = map(int,input().split())
A = list(map(int,input().split()))
As = [0] + list(accumulate(A))
As = [i%M for i in As]
count = [0 for i in range(M)]
ans = 0
for i in As:
    ans += count[i]
    count[i] += 1
print(ans)

Fixed submission:
from itertools import accumulate
N,M = map(int,input().split())
A = list(map(int,input().split()))
As = [0]
for i in accumulate(A):
    As.append(i%M)
count = {}
ans = 0
for i in As:
    if i not in count:
        count[i] = 1
    else:
        ans += count[i]
        count[i] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
ab = []
dp = [0 for i in range(N)]
for i in range(M):
    a,b = list(map(int,input().split()))
    ab.append([a-1,b-1])
ab.sort(key = lambda ab:ab[1])
count = 0
while ab:
    a,b = ab.pop(0)
    for i in range(len(ab)-1,-1,-1):
        if ab[i][0] < b:
            ab.remove(ab[i])
    count += 1
print(count)

Fixed submission:
N,M = map(int,input().split())
ab = []
for i in range(M):
    ab.append(list(map(int,input().split())))
ab.sort(key = lambda ab:ab[1])
count = 0
now = 0
for a,b in ab:
    if a >= now:
        count += 1
        now = b
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
dp = [[float('inf') for i in range(N+1)] for j in range(4)]
dp[0][0] = 0
dp[3] = [i for i in range(N+1)]
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(nine,0,-1):
    dp[1][9**i] = 1
    x= (9**i)
    for j in range(x,N+1):
        dp[1][j] = min(dp[1][j],dp[1][j-x]+1)
for i in range(1,six+1):
    dp[2][6**i] = 1
    x= (6**i)
    for j in range(N+1):
        if j >= 9:
            dp[2][j] = min(dp[2][j],dp[2][j-x]+1)
        if j >= x:
            dp[2][j] = min(dp[2][j],dp[1][j-x]+1)
for i in range(1,6):
    dp[3][-1] = min(dp[3][-1],dp[2][N-i]+i)
print(dp[-1][-1])


Fixed submission:
N = int(input())
dp = [float('inf') for i in range(N+1)]
dp[0] = 0
if N >= 6:
    dp[6] = 1
def below_power(n,a):
    "n以下になるa**xのxの最大値を求める"
    x = 0
    while n >= a**x:
        x += 1
    return x-1
nine = below_power(N,9)
six = below_power(N,6)
for i in range(six,0,-1):
    for j in range(N+1):
        if j - 6**i >= 0:
            dp[j] = min(dp[j],dp[j-6**i]+1)
for i in range(nine,0,-1):
    for j in range(N+1):
        if j - 9**i >= 0:
            dp[j] = min(dp[j],dp[j-9**i]+1)       
ans = dp[N]
for i in range(1,min(N+1,6)):
    ans = min(ans,dp[N-i]+i)
print(ans)