Problem:


Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes



Sample input:
3
1 3 2
1 2 3


Sample output:
Yes

Submission status: Runtime Error

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    n = I()
    print(n // 2 - 1 if n % 2 == 0 else n // 2)
    return


# B
def B():
    n = I()
    d = LI()
    if d[0] != 0:
        print(0)
        return
    d.sort()
    if d[1] == 0:
        print(0)
        return
    cnt = []
    prenum = 1
    for i in range(1, max(d) + 1):
        num = bisect.bisect_right(d, i)
        if num - prenum == 0:
            print(0)
            return
        else:
            cnt.append(num - prenum)
            prenum = num
    ans = 1
    for i in range(1, max(d)):
        ans *= cnt[i - 1] ** cnt[i]
    print(ans % 998244353)
    return


# C
def C():
    n = I()
    a = LI()
    b = LI()
    l = [list(e) for e in zip(b,a)]
    l = sorted(l)
    ans = 0

    def sol(l, ans):
        num = l[0][0]
        rem = 0
        if len(l) == 1:
            if l[0][1] > num:
                print("No")
                return -1
            else:
                return ans
        if l[0][1] > num:
            for i in range(1, len(l)):
                if l[i][1] <= num and l[0][1] <= l[i][0]:
                    l[i][1] = l[0][1]
                    ans += 1
                    sol(l[1:], ans)
                elif l[i][1] <= num and l[0][1] > l[i][0]:
                    rem = i
            if (rem == 0):
                return -1
            else:
                t = l[rem][1]
                l[rem][1] = l[0][1]
                l[0][1] = t
                sol(l, ans)
        else:
            sol(l[1:], ans)

    a = sol(l, ans)
    if a == -1:
        print("No")
    elif a <= n - 2:
        print("Yes")
    else:
        print("Yes")

    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    C()
    return


# Solve
if __name__ == "__main__":
    C()

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
# import math


def main():
    n = getN()
    anums = getList()
    bnums = getList()

    asort = sorted(copy.copy(anums))
    bsort = sorted(copy.copy(bnums))

    for a, b in zip(asort, bsort):
        if a > b:
            print("No")
            return

    yaba_index = [-1]
    tmpyaba = 0
    for a, b in zip(asort[1:], bsort):
        if a > b:
            yaba_index.append(tmpyaba)
        else:
            yaba_index.append(yaba_index[-1])
        tmpyaba += 1

    print(yaba_index)


    for a,b in zip(anums, bnums):
        if a <= b:
            # 変えなくてよい
            aidx = bisect.bisect_left(asort, a)
            bidx = bisect.bisect_left(bsort, b)

            if aidx > yaba_index[bidx]:
                print("Yes")
                print(aidx,bidx)
                # return

    for a, b in zip(anums, bnums):
        bidx = bisect.bisect_left(bsort, b)
        atugi = anums.index(asort[bidx])
        atugitugi = bisect.bisect_left(bsort(atugi))
        if a == asort[atugitugi]:
            print("Yes")
            return
    print("No")



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:


# unionfind木構造
# unionfindについてはここhttps://www.slideshare.net/chokudai/union-find-49066733
# グループに属するかの判定(find)や、グループ結合(union)に強い

from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    ### 重み付き
    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = - w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] =  w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
As  = list(map(int, input().split()))
Bs  = list(map(int, input().split()))
As_ind = [(a,i) for i,a in enumerate(As)]
Bs_ind = [(b,i) for i,b in enumerate(Bs)]
As_ind.sort()
Bs_ind.sort()



uf = UnionFind(N)
d_list = defaultdict(list)
cnt = 0
for A,B in zip(As_ind,Bs_ind):
    # print(A,B)
    if A[0] > B[0]:
        print("No")
        exit()
    uf.union(A[1],B[1])
    if len(d_list[uf.find[A[1]]]) > 0:
        if A[0] in d_list[uf.find[A[1]]]:
        cnt += 1 
    else: d_list[uf.find(A[1])].append(A[0])


d_ans = defaultdict(int)

for i in range(N):
    root = uf.find(i)
    d_ans[root] += 1
if len(d_ans) >= 2:
    print("Yes")
else:
    if cnt > 1:
        print("Yes")
        exit()
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_ = []
b_ = []
for i in range(n):
    a_.append([a[i], i])
    b_.append([b[i], i])

a_.sort()
b_.sort()
for i in range(n):
    if a[i][0] == b[i][0]:
        print('Yes')
        exit()
print('No')

Submission status: Runtime Error

Solution code:
import Levenshtein as Ln
n=int(input())
a=list(input())
b=list(input())
del a[1]
del a[2]
del b[1]
del b[2]
c=a
d=b
c.sort()
d.sort()
if Ln.distance(str(a),str(c))<=n+2:
    if a!=b:
         if c==d:
             print("Yes")
         else:
             print("No")
    else:
        print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
# import math


def main():
    n = getN()
    anums = getList()
    bnums = getList()

    asort = sorted(copy.copy(anums))
    bsort = sorted(copy.copy(bnums))

    for a, b in zip(asort, bsort):
        if a > b:
            print("No")
            return

    yaba_index = [-1]
    tmpyaba = 0
    for a, b in zip(asort[1:], bsort):
        if a > b:
            yaba_index.append(tmpyaba)
        else:
            yaba_index.append(yaba_index[-1])
        tmpyaba += 1

    print(yaba_index)


    for a,b in zip(anums, bnums):
        if a <= b:
            # 変えなくてよい
            aidx = bisect.bisect_left(asort, a)
            bidx = bisect.bisect_left(bsort, b)

            if aidx > yaba_index[bidx]:
                print("Yes")
                print(aidx,bidx)
                # return

    for a, b in zip(anums, bnums):
        bidx = bisect.bisect_left(bsort, b)
        atugi = anums.index(asort[bidx])
        atugitugi = bisect.bisect_left(bsort(atugi))
        if a == asort[atugitugi]:
            print("Yes")
            return
    print("No")



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import Levenshtein as Ln
n=int(input())
a=list(input())
b=list(input())
del a[1]
del a[2]
del b[1]
del b[2]
c=a
d=b
c.sort()
d.sort()
if Ln.distance(str(a),str(c))<=n-2:
    if a!=b:
         if c==d:
             print("Yes")
         else:
             print("No")
    else:
        print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
B = input().split()

A = [int(s) for s in A]
B = [int(s) for s in B]

limit = 0

def aikata(current):
	# current -= 1
	hikaku = current
	# print(current)
	for hikaku in range(hikaku, len(A)):
		# print(hikaku)
		# print(current)
		# print(A[hikaku] < A[current])
		# print(B[current] < A[current])
		# print(B[current] < A[hikaku])
		if (A[hikaku] < A[current] and B[current] < A[hikaku]) :
			A[current], A[hikaku] = swap(A[current],A[hikaku])
			# print(A)
			return A
	return 'No'



def swap (a,b):
	tmp = a
	a = b
	b = tmp
	return a,b


result = 'Yes'

for current in A :
	if (A[current] > B[current]) :
		result = aikata(current)
		if (result == 'No'):
			# print("no")
			break
		else :
			if (limit == N) :
				# print("limit")
				break
			N+=1
			# print("yes?")

if (result != 'No'):
	current = 0
	for current2 in A :
		if (A[current] > B[current]) :
			result = 'No'
		else :
			result = 'Yes'

print (result)

Submission status: Runtime Error

Solution code:
import os

N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
n=0
for i in range(N):
  if A[i]>B[i]:
    n+=1
if n>N-2:
  print('No')
else:  
  m=max(max(A),max(B))
  a=[0]*m
  b=[0]*m
  for i in range(N):
    a[A[i]-1]+=1
    b[B[i]-1]+=1
  a_count=0
  b_count=0
  flag=True
  for i in range(m):
    a_count+=a[i]
    b_count+=b[i]
    if a[i]<b[i] and a_count<b_count:
      print('No')
      flag=False
      break
  if flag:
    print('Yes')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_new=sorted(a)
b_new=sorted(b)
for i in range(0,n):
  if a_new[i]>b_new[i]:
    ans='No'
    break
if a_new[-1]<=b_new[-2]:
  ans='Yes'
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
B = input().split()

A = [int(s) for s in A]
B = [int(s) for s in B]

limit = 0

def aikata(current):
	# current -= 1
	hikaku = current
	# print(current)
	for hikaku in range(hikaku, len(A)):
		# print(hikaku)
		# print(current)
		print(A[hikaku] < A[current])
		print(B[current] < A[current])
		# print(B[current] < A[hikaku])
		if (A[hikaku] < A[current] and B[current] < A[hikaku]) :
			A[current], A[hikaku] = swap(A[current],A[hikaku])
			print(A)
			return A
	return 'No'



def swap (a,b):
	tmp = a
	a = b
	b = tmp
	return a,b


result = 'Yes'

for current in A :
	if (A[current] > B[current]) :
		result = aikata(current)
		if (result == 'No'):
			# print("no")
			break
		else :
			if (limit == N) :
				print("limit")
				break
			N+=1
			# print("yes?")

if (result != 'No'):
	current = 0
	for current2 in A :
		if (A[current] > B[current]) :
			result = 'No'
		else :
			result = 'Yes'

print (result)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
cnt=0
i=B.index(max(B)); j=A.index(max(A))
while cnt <= N-2:
	if B[i] < A[j]:
		print('No')
		exit()
	else:
		B.pop(i); A.pop(j)
		cnt+=1
		i=B.index(max(B)); j=A.index(max(A))
ch=0
for i in B:
	if i < A[ch]:
		print('No')
		exit()
	cn+=1
print('Yes')

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        exit()

AI = [(a, i) for i, a in enumerate(A)]
BI = [(b, i) for i, b in enumerate(B)]
AI.sort()
BI.sort()

orderA = [-1] * N
orderB = [-1] * N

for k, ((_, i), (_, j)) in enumerate(zip(AI, BI)):
    orderA[i] = k
    orderB[j] = k

aToI = {a : i for i, a in enumerate(A)}

cnt = 0
visited = [False] * N
for i, a in enumerate(A):
    if visited[i]:
        continue
    visited[i] = True

    leng = 0
    now = i
    while True:
        b = B[i]
        now = aToI[b]
        if visited[now]:
            break
        leng += 1
        visited[now] = True
    cnt += leng

if cnt <= N - 2:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A = sorted(enumerate(A), key=lambda x: x[1])
B = sorted(enumerate(B), key=lambda x: x[1])

flag = False
for i in range(N):
  if A[i][1] > B[i][1]:
    print('No')
    braek
  elif A[i][0] == B[i][0]:
    flag = True
  elif i > 0 and A[i][1] <= B[i-1][1]:
    flag = True
else:
  if flag:
    print('Yes')
  else:
    print('No')

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import bisect as bi
import numpy as np
import sys
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = np.array(a)
b = np.array(b)
b.sort()
ab = np.dstack([a,b])
ab = [flatten for inner in ab for flatten in inner]
ab.sort(key=itemgetter(1))

tmplist = []
#tmp = 0
cnt = 0

for i in range(n):
    if ab[i][0] > ab[i][1]:
        index = bi.bisect_left(b,ab[i][0])
        if index == n:
            print('No')
            sys.exit()
        #tmp = ab[index][0]
        for j in range(index,n):
            tmp = ab[j][0]
            if tmp >= ab[i][1]:
                ab[j][0], ab[i][0] = ab[i][0], ab[j][0]
                break
            elif j == n-1:
                print('No')
                sys.exit()
            #ab[index][0] , ab[i][0] = ab[i][0] , ab[index][0]
        cnt += 1
        if cnt > 2n:
            print('No')
            sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
from heapq import heapify, heappop, heappush

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


a_s = sorted(a)
b_s = sorted(b)
ng = 0
for i in range(n):
    if a_s[i] > b_s[i]:
        ng = 1
if ng:
    print("No")
else:
    c = []
    for i in range(n):
        c.append([a[i],b_s[i]])

    #cは[a,b]の順番
    c = sorted(c, key=lambda x: x[1])

    joho = []
    for i in range(10**5):
        nop = []
        heapify(nop)
        joho.append(nop)

    for i in range(n):
        heappush(joho[c[i][0]], c[i][1])

    sosa = 0
    for i in range(n):
        if c[i][0] > c[i][1]:
            st = len(c)-1
            while (c[st][0] > c[i][1]):
                st = st - 1
            tmp = c[i][0]
            c[i][0] = c[st][0]
            c[st][0] = tmp
            sosa += 1

    if sosa > n-1:
        ng = 1
    if ng:
        print("No")
    else: 
        print("Yes")

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

pa=[0]*(max(A)+1)
pb=[0]*(max(B)+1)

cnta=0
for i in range(N):
    pa[A[i]]+=1
    cnta+=i-sum(pa[:A[i]])

cntb=0
for i in range(N):
    pb[B[i]]+=1
    cntb+=i-sum(pb[:B[i]])


if cnta>N-2 or cntb>N-2:
    print("No")
    exit()


A.sort()
B.sort()

for i in range(N):
    if not A[i]<=B[i]:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import bisect as bi
import numpy as np
import sys
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = np.array(a)
b = np.array(b)
b.sort()
ab = np.dstack([a,b])
ab = [flatten for inner in ab for flatten in inner]
ab.sort(key=itemgetter(1))

tmplist = []
#tmp = 0
cnt = 0

for i in range(n):
    if ab[i][0] > ab[i][1]:
        index = bi.bisect_left(b,ab[i][0])
        if index == n:
            print('No')
            sys.exit()
        #tmp = ab[index][0]
        for j in range(index,n):
            tmp = ab[j][0]
            if tmp >= ab[i][1]:
                ab[j][0], ab[i][0] = ab[i][0], ab[j][0]
                break
            elif j == n-1:
                print('No')
                sys.exit()
            #ab[index][0] , ab[i][0] = ab[i][0] , ab[index][0]
        cnt += 1
        if cnt > 2n:
            print('No')
            sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}
A=[compression_dict[a] for a in A]
B=[compression_dict[a] for a in B]


SA=sorted(A)
SB=sorted(B)

for i in range(N):
    if SA[i]>SB[i]:
        print("No")
        sys.exit()

# BIT(BIT-indexed tree)
LEN=N

BIT=[0]*(LEN+1)# 1-indexedなtree

def update(v,w):# index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for a in A:
    update(a,1)

BIT2=[0]*(LEN+1)# 1-indexedなtree

def update2(v,w):# index vにwを加える
    while v<=LEN:
        BIT2[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue2(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT2[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for a in B:
    update2(a,1)

for i in range(N):
    a=A[i]
    b=B[i]

    update(a,-1)
    update2(b,-1)

    #print(getvalue(a),getvalue2(a),getvalue(b),getvalue2(b))

    if getvalue(a)<=getvalue2(a) and getvalue(b)<=getvalue2(b):
        update(a,1)
        update2(b,1)
    else:
        print("Yes")
        sys.exit()

print("No")

Submission status: Runtime Error

Solution code:
import sys
import heapq
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sub=[]
a_min=[]
b_min=[]

def detection (a,b):
    for i in range(len(a)-1):
        if a[i]-b[i]>0:
            print("No")
            sys.exit()
    print("Yes")

if min(a)-min(b)>0:
    print("No")
    sys.exit()
else:
    a_min=heapq.nsmallest(2, a)
    b_min=heapq.nsmallest(2, b)
    if a.index(a_min[0])>a.index(a_min[1]):
        a_min[0],a_min[1]=a_min[1],a_min[0]
    if b.index(a_min[0])>b.index(a_min[1]):
        b_min[0],b_min[1]=b_min[1],b_min[0]

detection(a_min,b_min)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if all(list(map(lambda x == 2, B))):
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if all(map(lambda x == 2, B)):
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

si2i = sorted(range(len(A)), key=lambda x:A[i])

a = 0
count = 0
while True:
    a = si2i[a]
    if a == 0:
        break
    count += 1

if count <= N - 2:
    print(yes)
    assert False
else:
    print(no)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A_, B_=sorted(A), sorted(B)
flag=True
for i in range(N):
  if A_[i]>B_[i]:
    flag=False
    break
if not flag:
  print("No")
else:
  flag=False
  for i in range(1, N):
    if A_[i-1]==A[i]:
      flag=True
      break
  if flag:
    print("Yes")
  else:
    C=[(A[i], B[i]) for i in range(N)]
    C.sort(key=lambda x:(x[1], x[0]))
    A=[C[i][0] for i in range(N)]
    start=A[0]
    now=A[0]
    cnt=1
    while True:
      now=A[now-1]
      if now==start:
        break
      cnt+=1
    if cnt==N:
      print("No")
    else:
      print("Yes")
    '''
    flag=False
    print(A)
    print(A_)
    if A[0]==A_[-1]:
      for i in range(1, N):
        if A[i]!=A_[i-1]:
          flag=True
          break
    else:
      flag=True
    if flag:
      print("Yes")
    else:
      print("No")
    '''

Submission status: Runtime Error

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

assert False

si2i = sorted(range(len(A)), key=lambda x:A[i])

a = 0
count = 0
while True:
    a = si2i[a]
    if a == 0:
        break
    count += 1

if count <= N - 2:
    print(yes)
else:
    print(no)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

pa=[0]*(max(A)+1)
pb=[0]*(max(B)+1)

cnta=0
for i in range(N):
    pa[A[i]]+=1
    cnta+=sum(pa[A[i]+1:])
cntb=0
for i in range(N):
    pb[B[i]]+=1
    cntb+=sum(pb[B[i]+1:])


if cnta>N-2 or cntb>N-2:
    print("No")
    exit()


A.sort()
B.sort()

for i in range(N):
    if not A[i]<=B[i]:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for i, (Li, Ri, Ci) in enumerate(LRC):
    graph[Li - 1].append((Ri, Ci))

for i, (Li, Ri, Ci) in enumerate(LRC):
    for idx in range(Ri - Li):
        if len(graph[(Ri - idx - 1) - 1]) > 0:
            graph[Ri - 1].append(((Ri - idx - 1), 0))

# for i in range(N):
#     print("#", graph[i])
            
import heapq

inf = 10 ** 18
d = [inf] * N

q = [(0, 1)] # cost, pos
while len(q) > 0:
    cost, src = heapq.heappop(q)
    for dst, c_dst in graph[src - 1]:
        if cost + c_dst < d[dst - 1]:
            d[dst - 1] = cost + c_dst
            heapq.heappush(q, (cost + c_dst, dst))

if d[N - 1] == inf:
    print(-1)
else:
    print(d[N - 1])

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
BA = sorted([(b, a) for a, b in zip(A, B)])
A = [a for b, a in BA]
B = [b for b, a in BA]


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


def f(x, y):
    if x[1] <= y[1]:
        return x
    else:
        return y


cnt = 0
ST = SegmentTree(list(enumerate(A)), f=f, ti=(-1, 10**10))
for i in range(N):
    now = ST.query(i, i + 1)
    if now[1] > B[i]:
        cnt += 1
        cand = ST.query(i + 1, N)
        if cnt==N-2:
            0/0
        if cnt < N - 1 and cand[1] <= B[i]:
            ST.update(cand[0], (cand[0], now[1]))
            ST.update(now[0], (now[0], cand[1]))
        else:
            print('No')
            exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
dekiru=1

	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		print("No")
	else:
		print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))

Alist_sorted = Alist.sorted()
Blist.sort()

check = True
cnt = 0
for i in range(N):
    if Alist[i] == Alist_sorted[i]:
        cnt += 1
    if Alist[i] > Blist[i]:
        check = False
        break

if not check:
    print("No")
else:
    if cnt >= 1:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
A=a.copy()
b=list(map(int,input().split()))
B=b.copy()
a=sorted(a)
b=sorted(b)
C=[0 for i in range(n)]
for j in range(n):
    C[j]=(A[j],B[j])
C=sorted(C,key=lambda x:(x[1],x[0]))
D=[0 for i in range(n)]
for i in range(n):
    D[i]=C[i][0]
flag=True
flag2=False
for j in range(n):
    if a[j]>b[j]:
        flag=False
        break
listss=[[] for i in range(n+1)]
for i in range(n):
    listss[a[i]].append(D[i])
    listss[D[i]].append(a[i])
for j in range(n):
    listss[j]=list(set(listss[j]))
del listss[0]
for j in listss:
    if len(j)!=0 and len(j)!=2:
        flag2=True
if flag and flag2:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa = sorted(a)
sb = sorted(b)

def can(t):
    ngo = b[t]
    if b[t] == sb[t]:
        return True
    if b[t] > sb[t]:
        tt = bisect.bisect_left(b[t],sb)
        if sa[tt] <= sb[t]:
            return True
        else:
            return False
    else:
        tt = bisect.bisect_right(b[t],sb)
        if sa[tt] <= sb[t]:
            return True
        else:
            return False

for i in range(n):
    if sa[i] > sb[i]:
        print('No')
        exit(0)
for i in range(n):
    if can(i):
        print('Yes')
        exit(0)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
flag = False
mask = ~np.identity(n, dtype=np.bool)
for i in np.where(a <= b)[0]:
  if np.all(np.sort(a[mask[i]]) <= np.sort(b[mask[i]])):
    flag = True
    break
if flag:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import Levenshtein as Ln
n=int(input())
a=list(input())
b=list(input())
g=0
if a!=b:
    if Ln.distance(a,b)<=n-2:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
flag = False
mask = ~np.identity(n, dtype=np.bool)
for i in np.where(a <= b)[0]:
  if np.all(a[mask[i]].sort() <= b[mask[i]].sort()):
    flag = True
    break
if flag:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
A=a.copy()
b=list(map(int,input().split()))
B=b.copy()
a=sorted(a)
b=sorted(b)
C=[0 for i in range(n)]
for j in range(n):
    C[j]=(A[j],B[j])
C=sorted(C,key=lambda x:(x[1],x[0]))
D=[0 for i in range(n)]
for i in range(n):
    D[i]=C[i][0]

flag=True
flag2=False
for j in range(n):
    if a[j]>b[j]:
        flag=False
        break
listss=[[] for i in range(n+1)]
for i in range(n):
    listss[a[i]].append(D[i])
    listss[D[i]].append(a[i])
for j in range(n):
    listss[j]=list(set(listss[j]))
del listss[0]
for j in listss:
    if len(j)!=0 and len(j)!=2:
        flag2=True
if flag and flag2:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=a
bb=b
a.sort()
b.sort()
dekiru=1
onaji=0
issho=0
for i in range(n):
	if a[i]==aa[i]:
		onaji=1
if onaji==1:
	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		print("Yes")
	else:
		print("No")
		
else:
	for i in range(n):
		if aa[i]==bb[i]:
			issho=1
			memo=i
			break
	if issho==1:
		a.remove(aa[memo])
		b.remove(bb[memo])
			for i in range(n):
				if a[i]>b[i]:
				dekiru=0
				break
			if dekiru==1:
				print("Yes")
			else:
				print("No")
	else:
		print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
a_ = list(map(int, input().split()))
b_ = list(map(int, input().split()))

cmb = [(b_[i],a_[i]) for i in range(n)]
cmb.sort()
a_.sort()
b_.sort()
for i in range(n):
    if a_[i]>b_[i]:
        print("No")
        sys.exit()
a = [cmb[i][1] for i in range(n)]
b = [cmb[i][0] for i in range(n)]
cnt = 0
for i in range(n):
    if a[i]>b[i]:
        cnt += 1
if cnt>=n-1:
    print("No")
    sys.exit()
"""
i = n-1
j = n-1
while i>0:
    if a[i]<=b[i]:
        i-=1
    else:
        while b[j]<a[i]:
            j-=1
            if j<0:
                print("No")
                sys.exit()
            i-=1
"""            
print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

diff,zeros=[],[]
for i in range(N):
    dif = sorted(B)[i]-sorted(A)[i]
    zero = B[i]-A[i]
    if zero < 0:
        zeros.append(zer0)
    if dif >= 0:
        diff.append(dif)
if (len(diff) == N) and (len(zeros) <= N-2):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
Alist = np.array(list(map(int, input().split())))
Blist = np.array(list(map(int, input().split())))
hikaku = np.sort(Alist) <= np.sort(Blist)
if (False not in hikaku) and np.count_nonzero(hikaku) >= 2:
    print("Yes")

else:
    print("No")

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split())).sort()
B=list(map(int,input().split())).sort()

d=[]
for i in range(N):
    e=B[i]-A[i]
    if e<=0:
        d.append(-e)
        
if sum(d)>0:
    print('No')
else :
    print('Yes')