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:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
n = int(input())
a_arr = list(map(int,input().split()))
s_a = sorted(a_arr)
b_arr = sorted(list(map(int,input().split())))
swap = False
pb = 0
for a,b in zip(s_a,b_arr):
    if a > b:
        print('No')
        exit()
    if pb >= a:
        swap =  True
    pb = b
if swap:
    print('Yes')
    exit()
uf = UnionFind(n)
print(Yes)

Submission status: Runtime Error

Solution code:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
n = int(input())
a_arr = list(map(int,input().split()))
s_a = sorted(a_arr)
b_arr = sorted(list(map(int,input().split())))
swap = False
pb = 0
for a,b in zip(s_a,b_arr):
    if a > b:
        print('No')
        exit()
    if pb >= a:
        swap =  True
    pb = b
if swap:
    print('Yes')
    exit()
uf = UnionFind(n)
for a,sa in zip(a_arr,s_a):
    if not uf.isSameGroup(a,sa):
        uf.Unite(a,sa)
print('Yes')

Submission status: Runtime Error

Solution code:
#!/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

Submission status: Runtime Error

Solution code:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
from collections import Counter
n = int(input())
a_arr = list(map(int,input().split()))
s_a = sorted(a_arr)
b_arr = sorted(list(map(int,input().split())))
swap = False
pb = 0
for a,b in zip(s_a,b_arr):
    if a > b:
        print('No')
        exit()
    if pb >= a:
        swap =  True
    pb = b
if swap:
    print('Yes')
    exit()
uf = UnionFind(n)
for a,sa in zip(a_arr,s_a):
    if not uf.isSameGroup(a,sa):
        uf.Unite(a,sa)
if uf.Count(a_arr[0]) < n:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
As = list(map(int, input().strip().split()))
Bs = list(map(int, input().strip().split()))


def swap(i, j, lis):
    temp = lis[i]
    lis[i] = lis[j]
    lis[j] = temp


def search(lis, i, most):
    ret = -1
    for j in range(i + 1, len(lis)):
        if most >= lis[j] > ret:
            ret = j
    return ret


for i in range(N):
    for j in range(i + 1, N):
        if Bs[i] > Bs[j]:
            swap(i, j, Bs)
            swap(i, j, As)

# print(As)
# print(Bs)
cnt = 0
exissw = 1
for i in range(N):
    if As[i] > Bs[i]:
        lessMostIdx = search(As, i, Bs[i])
        if lessMostIdx != -1:
            swap(i, lessMostIdx, As)
            cnt += 1
        else:
            exissw = 0
            break
        if cnt > N - 2:
            exissw = 0
        	break

if exissw == 0:
    print("No")
else:
    print("Yes")
    # print(As)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sa = sorted(a)
sb = sorted(b)
c = [list(i) for i in zip(b,sa)]
cnt = 0
if any(sb[i] < sa[i] for i in range(n)):
    print('No')
    exit(0)
if any(sa[i] <= sb[i-1] for i in range(1,n)):
    print('Yes')
    exit(0)
for i in range(n):
    while c[i][1] != c[i][0]:
        c[i][1],c[c[i][1]-1][1] = c[c[i][1]-1][1],c[i][1]
        cnt += 1
if cnt <= n-2:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sa = sorted(a)
sb = sorted(b)
c = [list(i) for i in zip(b,sa)]
cnt = 0
if any(sb[i] < sa[i] for i in range(n)):
    print('No')
    exit(0)
if any(sa[i] <= sb[i-1] for i in range(1,n)):
    print('Yes')
    exit(0)
for i in range(n):
    while c[i][1] != c[i][0]:
        c[i][1],c[c[i][1]-1][1] = c[c[i][1]][1],c[i][1]
        cnt += 1
if cnt <= n-2:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
AB=np.array([(a,b) for a,b in zip(A,B)])
AB=AB[np.argsort(AB[:,1])]
AI=np.array([[i,AB[i,0]] for i in range(N)])
AI=AI[np.argsort(AI[:,1])]
sigma=AI[:,0]
ASort=AI[:,1]
BSort=AB[:,1]
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
counter=0
if g==0:
    used=np.array([])
    start=0
    now=sigma[start]
    np.append(used,now)
    while start!=now:
        now=sigma[now]
        np.append(used,now)
    
if N==len(used) or g==1:
    print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
import sys
from operator import itemgetter
sys.setrecursionlimit(10**9)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [[a[i], b[i]] for i in range(n)]
a.sort(key=itemgetter(1))
a = [[a[i][0], a[i][1], i] for i in range(n)]
b.sort()
a.sort(key=itemgetter(0))

for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()
c = 0
num = a[0][2]
while c < n-1 and num != 0:
    num = a[num][2]
    c += 1
if num == 0 and c < n-1:
    print('Yes')
    sys.exit()

for i in range(1, n):
    if a[i] <= b[i-1]:
        print('Yes')
        sys.exit()
print('No')

Submission status: Runtime Error

Solution code:
import sys
from operator import itemgetter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [[a[i], b[i]] for i in range(n)]
a.sort(key=itemgetter(1))
a = [[a[i][0], a[i][1], i] for i in range(n)]
b.sort()
a.sort(key=itemgetter(0))

for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()
c = 0
num = a[0][2]
while c < n-1 and num != 0:
    num = a[num][2]
    c += 1
if num == 0 and c < n-1:
    print('Yes')
    sys.exit()

for i in range(1, n):
    if a[i] <= b[i-1]:
        print('Yes')
        sys.exit()
print('No')

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sa = sorted(a)
sb = sorted(b)
c = [list(i) for i in zip(b,sa)]
cnt = 0
if any(sb[i] < sa[i] for i in range(n)):
    print('No')
    exit(0)
if any(sa[i] <= sb[i-1] for i in range(1,n)):
    print('Yes')
    exit(0)
for i in range(n):
    while c[i][1] != c[i][0]:
        c[i][1],c[c[i][1]][1] = c[c[i][1]][1],c[i][1]
        cnt += 1
if cnt <= n-2:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
A = np.asarray(list(map(int, input().split())))
B = np.asarray(list(map(int, input().split())))
AB = np.stack((A, B), axis=1)
AB = AB[np.argsort(AB[:, 1])]

flag = False
k = 0
while(not flag and k<n):
    if AB[k,0] <= AB[k,1]:
        ABd = np.delete(AB, k, 0)

        As = ABd[:, 0]

        As.sort()

        for i in range(n-1):
            if As[i] > ABd[i, 1]:
                break
        else:
            flag = True

    k += 1

if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

#na = [a[i] for bi,i in pb]
na = []
from itertools import groupby
for k,g in groupby(pb,key=lambda x: x[0]):
    g = list(g)
    res = [a[i] for bi,i in g]
    res.sort()
    #print(g,res)
    na += res

ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    if na == sa[1:] + sa[:1]:
        ok = 0
    else: a(1)
    
#print(a,b,sa,sb,na)

if ok: print("Yes")    
else: print("No")

Submission status: Runtime Error

Solution code:
def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  tmp={}
  for i in range(N):
    if not B[i] in tmp.keys():
      tmp[B[i]]=[]
    tmp[B[i]].append(A[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 0
  for i in range(N):
    if A[i] in tmp[B[i]]:
      print("Yes")
      return 0
   	if i!=N-1:
      if B[i] >= A[i+1]:
        print("Yes")
        return 0
  print("No")
      
main()

Submission status: Runtime Error

Solution code:
def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  tmp={}
  for i in range(N):
    if not B[i] in tmp.keys():
      tmp[B[i]]=[]
    tmp[B[i]].append(A[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 0
  for i in range(N):
    if A[i] in tmp[B[i]]:
      print("Yes")
      return 0
    if B[i] >= A[i+1]:
      print("Yes")
      return 0
  print("No")
      
main()

Submission status: Runtime Error

Solution code:
import Levenshtein as Ln
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=a
d=b
f=0
c.sort()
d.sort()
lndis=Ln.distance(str(a),str(c))
if lndis<=n-2:
    if a!=b:
         for k in range(len(a)):
             if c[k]<=d[k]:
                 f+=1
                 if f==len(a):
                     print("Yes")
                     break
             else:
                 print("No")
                 break
    else:
        print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import bisect

#mod = 1000000007
mod = 998244353

def main():
    n = int(input())
    a = [x for x in map(int,input().split())]
    b = [x for x in map(int,input().split())]
    cnt = 0
    for i in range(n):
        if a[i]>b[i]:
            cnt += 1
    if cnt>n-2:
        print("No")
        return
    a.sort()
    b.sort()
    for i in range(n):
        if a[i]>b[i]:
            print("No")
            return
    for i in range(1,n):
        if a[i]<b[i-1]:
            print("Yes"):
            return
    print("Yes")
    return


if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split()])
B = np.array([int(x) for x in input().split()])
I = B.argsort()
A = A[I]
B = B[I]
calc = max(A) <= max(B)
if not calc:
    print("No")
    exit(0)
if any(A.sort()[1:] <= B[:-1]):
    print('Yes')
    exit()
p = A.argsort().tolist()
x = 0
c = 0
while True:
    c += 1
    x = p[x]
    if x == 0:
        break
print("Yes" if p != N else "No")

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()


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

A_c = copy.deepcopy(A)

A.sort()
B.sort()

for i in range(N):
    if A[i] > B[i]:
        print("No")
        sys.exit(0)

for i in range(1,N):
    if A[i] < B[i-1]:
        print("Yes")
        sys.exit(0)

# ans = "Yes"
# for i in range(N):
#     if A[i] <= B[i]:
#         pass
#     else:
#         ans = "No"
#         break

si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
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:
# -*- coding: utf-8 -*-
import sys
N = int(input())

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

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
        
s = 0
count = 0

if a[0] > b[1]:
    while A[0] < a[0]:
        s = A[0]
        A[0] = A[s]
        count +=1
    if count > N - 2:
        print("No")
    else:
        print("Yes")

else:
    print("Yes")

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()

A_c = copy.deepcopy(A)

A.sort()
B.sort()

for i in range(N):
    if A[i] > B[i]:
        print("No")
        sys.exit(0)

for i in range(1,N):
    if A[i] < B[i-1]:
        print("Yes"):
        sys.exit(0)


# ans = "Yes"
# for i in range(N):
#     if A[i] <= B[i]:
#         pass
#     else:
#         ans = "No"
#         break

if True:
    si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
    a = 0
    count = 0
    while True:
        a = si2i[a]
        if a == 0:
            break
        count += 1

    if count <= N - 2:
        pass
    else:
        ans = "No"

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
N = int(input())

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

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
        
s = 0
count = 0

if a[0] > b[1]:
    while A[0] < a[0]:
        s = A[0]
        A[0] = A[s]
        count +=1
    if count > N - 2:
        print("No")

else:
    print("Yes")

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()

A_c = copy.deepcopy(A)

A.sort()
B.sort()

ans = "Yes"
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        ans = "No"
        break

if ans == "Yes"
    si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
    a = 0
    count = 0
    while True:
        a = si2i[a]
        if a == 0:
            break
        count += 1

    if count <= N - 2:
        print("Yes")
    else:
        print("No")
else:
    print(ans)

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()

A_c = copy.deepcopy(A)

A.sort()
B.sort()

ans = "Yes"
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        ans = "No"
        break

if ans == "Yes"
    si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
    a = 0
    count = 0
    while True:
        a = si2i[a]
        if a == 0:
            break
        count += 1

    if count <= N - 2:
        print("Yes")
    else:
        print("No")
else:
    print(ans)









print(ans)

Submission status: Runtime Error

Solution code:
class UnionFind:
    def __init__(self, n):
        self.rank = [0]*n
        self.parent = [i for i in range(n)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            self.rank[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)





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()

ufa = UnionFind(n)
ufb = UnionFind(n)

for i in range(n-1):
    if a_[i][0] == a_[i+1][0]:
        ufa.merge(a_[i][1], a_[i+1][1])
    if b_[i][0] == b_[i+1][0]:
        ufb.merge(b_[i][1], b_[i+1][1])


for i in range(n):
    if ufa.same(a_[i][0], b_[i][0]) or ufb.same(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=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=a
d=b
f=0
c.sort()
d.sort()
if Ln.distance(str(a),str(c))<=n-2:
    if a!=b:
         for k in range(len(a)):
             if c[k]<=d[k]:
                 f+=1
                 if f==len(a):
                     print("Yes")
                     break
             else:
                 print("No")
                 break
    else:
        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()))
ans = 'Yes'

asort=sorted(a)
bsort=sorted(b)
i=0
cnt = 0
con = 1
f = 1
while (i<N):
    if asort[i]>bsort[i]:
        ans = 'No'
        break
    else:
        if asort[i]!=bsort[i]:
            cont=0
            break
    i+=1
if con==1:
    i=0
    while (i<N):
        if (a[b[i]-1]==b[a[i]-1])&(a[i]==b[a[b[i]-1]-1]):
            f=0
            break
        i+=1
    if f==1:
        ans='No'

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
a = [int(s) for s in input().split()]
b = [int(t) for t in input().split()]
cir = False
ans = 'Yes'

sorta = np.sort(a)
sortb = np.sort(b)
indexa = np.argsort(a)
indexb = np.argsort(b)
index2b = np.concatenate([indexb,indexb])

#循環してるか
for i in range(n):
    if np.all(indexa == index2b[i:i+n]):
        cir = True
        break

if not cir:
    for i in range(n):
        if sorta[i] > sortb[i]:
            ans = 'No'
        break

if cir:
    ans = 'No'
    for i in range(1,n-1):
        temp = np.array(sorta.copy())
        temp[i], temp[i+1] = temp[i+1], temp[i]
        if np.all(temp <= sortb):
            ans = 'Yes'
            break
print(ans)

Submission status: Runtime Error

Solution code:
def check(listA, listB):
    for i in range(len(listA)):
       if listA[i] > listB[i]:
           return False
    return True
    
def solution3(N, listA, listB):
    cnt = 0
    max_A = max(listA)
    max_B = max(listB)
    if max_A > max_B:
        return False
    if check(listA, listB):
    	return True   
    skip_index = []
    loopIndex = [int(i) for i in range(len(listA))]
    for i in range(len(listA)-2):
        max_A = 0
        max_B = 0
        for j in loopIndex:
            if max_A < listA[j]:
                max_index_A = j
                max_A = listA[j]
            if max_B < listB[j]:
                max_index_B = j
                max_B = listB[j]

        # swap
        temp = listA[max_index_B]
        listA[max_index_B] = max_A
        listA[max_index_A] = temp
        skip_index.append(max_index_B)
        loopIndex.pop(max_index_B)

        if check(listA, listB):
            return True
    
    return False
  
N = int(input())
listA = input()
listA = [int(n) for n in listA.split(" ")]
listB = input()
listB = [int(n) for n in listB.split(" ")]

if solution3(N, listA, listB):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
a_list = sorted([int(i) for i in input().split()])
b_list = sorted([int(i) for i in input().split()])

for a, b in zip(a_list, b_list):
  if a > b:
    print("No")
    exit()

for i in range(n):
  if a_list[i] <= b_list[i+1] and a_list[i+1] <= b_list[i]:
    print("Yes")

print("No")

Submission status: Runtime Error

Solution code:
def check(listA, listB):
    for i in range(len(listA)):
       if listA[i] > listB[i]:
           return False
    return True
    
def solution3(N, listA, listB):
    cnt = 0
    max_A = max(listA)
    max_B = max(listB)
    if max_A > max_B:
        return False
    if check(listA, listB):
    	return True   
    skip_index = []
    loopIndex = [int(i) for i in range(len(listA))]
    for i in range(len(listA)-2):
        max_A = 0
        max_B = 0
        for j in loopIndex:
            if max_A < listA[j]:
                max_index_A = j
                max_A = listA[j]
            if max_B < listB[j]:
                max_index_B = j
                max_B = listB[j]

        # swap
        temp = listA[max_index_B]
        listA[max_index_B] = max_A
        listA[max_index_A] = temp
        skip_index.append(max_index_B)
        loopIndex.pop(max_index_B)

    if check(listA, listB):
        return True
    
    return False
N = int(input())
listA = input()
listA = [int(n) for n in listA.split(" ")]
listB = input()
listB = [int(n) for n in listB.split(" ")]

if solution3(N, listA, listB):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Nov  9 17:43:40 2019
nikkei2019
@author: maezawa
"""

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ab = [(a[i], b[i]) for i in range(n)]
a.sort()
b.sort()
ab.sort(lambda x: x[1])
ans = 'Yes'
for i in range(n):
    if a[i]>b[i]:
        ans = 'No'
        break
    
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
bit = Bit(n)
ans1 = 0
 
for i, p in enumerate(ab):
    bit.add(p, 1)
    ans1 += i + 1 - sum(p)

if ans1>n-2:
    ans = 'No'
    
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))

def maxminsumNum(list):
    max = 0
    min = 1000000000
    sum = 0
    for n in list:
        sum += n
        if (max < n):
            max = n
        if (n < min):
            min = n
    return max, min, sum


def checkCirculation(list1, list2):
    nList2 = list2.sorted()
    sortedIndex = []
    for e in nList2:
        sortedIndex.append(list2.index(e))

    nList1 = []
    minindex = 0
    kensa = 1000000000
    for i in sortedIndex:
        nList1.append(list1[i])
        if (list2[i] < kensa):
            minindex = i

    kensa2 = 0
    for n in range(minindex, N):
        if (kensa2 <= nList1[n]):
            kensa2 = nList1[n]
        else:
            return False
        
    kensa2 = 0
    for n in range(1, minindex - 1):
        if (kensa2 <= nList1[n]):
            kensa2 = nList1[n]
        else:
            return False

    return True


maxA, minA, sumA = maxminsumNum(listA)
maxB, minB, sumB = maxminsumNum(listB)

if (maxA > maxB or minA > minB or sumA > sumB or checkCirculation(listA, listB)):
    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()))

A.sort()
B.sort()

check = False
for x, y in zip(A, B):
    if x <= y:
        check = True
    
    else:
        check = False
        print("No")
        sys.exit()

if check:
    print("Yes")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
N = int(input())

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

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
s = 0
count = 0
if a[1] > b[0]:
    while A[0] = a[0]:
        s = A[0]
        A[0] = A[s]
        count +=1
    if count > N - 2:
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

L = []
for i in range(N):
    L.append((A[i], B[i]))
    
L.sort(key=itemgetter(1))
for i in range(N):
    A[i] = L[i][0]
    B[i] = L[i][1]

def f(n, l, u, B):
    if u-l < 1:
        return l
    else:
        m = (u+l)//2
        if B[m] > n:
            return f(n, l, m, B)
        else:
            return f(n, m, u, B)

i = 0
cnt = 0
while cnt < N-2 and i < len(A):
    if A[i] > B[i]:
        t = f(A[i], i+1, len(A)-1, B)
        temp = A[i]
        A[i] = A[t]
        A[t] = temp
        if A[t] == B[t]:
            A.pop(t)
            B.pop(t)
        cnt += 1
    else:
        i += 1
        
ans = "Yes"
for i in range(len(A)):
    if A[i] > B[i]:
        ans = "No"
        break
        
print(ans)

Submission status: Runtime Error

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

# N = 4
# A = [1,3,2,1]
# B = [1,2,3,2]
count = 0
y = 0

A_B = []

for n in range(N):
    A_B.append([A[n],B[n]])

A_B = sorted(A_B, key = lambda x: (x[1], x[0]))

for n in range(N-1):
    if A_B[n][0] > A_B[n][1]:
        for m in range(n+1, N):
            if A_B[n][1] < A_B[m][0]:
                pass
            else:
                A_B[m][0] <= A_B[n][1] and A_B[n][0] <= A_B[m][1]:
                temp = A_B[m][0]
                A_B[m][0] = A_B[n][0]
                A_B[n][0] = temp
                count += 1
                break

for n in range(N):
    if A_B[n][0] > A_B[n][1]:
        y += 1


if y >= 1:
    print('No')
elif count > N-2:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())

for _ in range(N):
    A = list(map(int, input().split()))

for _ in range(N):
    B = list(map(int, input().split()))

A.sort()
B.sort()

check = False
for x, y in zip(A, B):
    if x <= y:
        check = True
    
    else:
        check = False

if check:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Nov  9 17:43:40 2019
nikkei2019
@author: maezawa
"""

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ab = [(a[i], b[i]) for i in range(n)]
a.sort(lambda x: x[0])
b.sort(lambda x: x[0])
ab.sort(lambda x: x[1])
ans = 'Yes'
for i in range(n):
    if a[i]>b[i]:
        ans = 'No'
        break
    
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
bit = Bit(n)
ans1 = 0
 
for i, p in enumerate(ab):
    bit.add(p, 1)
    ans1 += i + 1 - sum(p)

if ans1>n-2:
    ans = 'No'
    
    
print(ans)