Problem p02865 (python)

Fixed submission:
n = int(input())
print((n-1)//2)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        #print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                #print(f'i={i},j={j}')
                if A[j] <= B[i]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    #print(f'swap:{count}')
                    #print(f'A:{A}')
                    #print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(f'A:{A}')
#print(f'B:{B}')

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        #print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                if A[j] <= B[i] and A[i] <= B[j]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    #print(f'swap:{count}')
                    #print(f'A:{A}')
                    #print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                if A[j] <= B[i] and A[i] <= B[j]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    print(f'swap:{count}')
                    print(f'A:{A}')
                    print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n-1):#scanA
        Bmin = B[i]
        swapnum = i
        for j in range(i+1,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j            
        
        if A[i] > Bmin:
            return 'No'
        elif A[i+1] > Bmin:
            B[swapnum] = B[i]
            count += 1
    
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n-1):#scanA
        Bmin = B[i]
        swapnum = i
        for j in range(i+1,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j            
        
        if A[i] > Bmin:
            return 'No'
        elif A[i+1] > Bmin:
            B[swapnum] = B[i]
            count += 1
    
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n-1):#scanA
        if A[i] > B[i]:
            return 'No'
        
        Bmin = B[i]
        swapnum = i
        for j in range(i+1,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j            
        
        #A[i+1]<=Bminでなければ入れ替える。
        if A[i+1] > Bmin:
            B[swapnum] = B[i]
            count += 1
        
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n-1):#scanA
        if A[i] > B[i]:
            return 'No'
        
        Bmin = B[i]
        swapnum = i
        for j in range(i+1,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j            
        
        #A[i+1]<=Bminでなければ入れ替える。
        if A[i+1] > Bmin:
            B[swapnum] = B[i]
            count += 1
        
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanA
        Bmin = B[i]
        swapnum = i
        
        #B[i～n-1]の最小値を探す
        for j in range(i,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j
        #最小値がA[i]より小さければ並べ変えは不可能
        if A[i] > Bmin:
            return 'No'
        
        #最小値がB[i]でなければ入れ替える。
        if swapnum != i:
            B[swapnum] = B[i]
            count += 1
        
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))