AtCoder Beginner Contest 082 - Two Anagrams

You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to satisfy s' < t' for the lexicographic order.

-----Notes-----
For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:
 - N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.
 - There exists i (1 \leq i \leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.
For example, xy < xya and atcoder < atlas.

-----Constraints-----
 - The lengths of s and t are between 1 and 100 (inclusive).
 - s and t consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
s
t

-----Output-----
If it is possible to satisfy s' < t', print Yes; if it is not, print No.

-----Sample Input-----
yx
axy

-----Sample Output-----
Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.

Difficulty: EASY

Starter code:

Solutions:
print('Yes' if sorted([c for c in input()]) < sorted([c for c in input()], reverse=1) else 'No')


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
if s < t:
	print('Yes')
else:
	print('No')


s = list(input())
t = list(input())
s = sorted(s)
t = sorted(t, reverse=True)
print('No' if s >= t else 'Yes')


s = list(map(str, input().rstrip()))
t = list(map(str, input().rstrip()))
s.sort()
t.sort(reverse=True)
s = ''.join(s)
t = ''.join(t)
print('Yes' if s < t else 'No')


S = sorted(input())
T = sorted(input(), reverse=True)
print('Yes' if S < T else 'No')


s = input()
t = input()
print('Yes' if ''.join(sorted(s)) < ''.join(reversed(sorted(t))) else 'No')


s = input()
t = input()
sorted_s = sorted(s)
sorted_t = sorted(t, reverse=True)
if sorted_s < sorted_t:
	print('Yes')
else:
	print('No')


A = input()
B = input()
if sorted(A) < sorted(B, reverse=True):
	print('Yes')
else:
	print('No')


print('Yes' if ''.join(sorted(input())) < ''.join(sorted(input()))[::-1] else 'No')


s = input()
t = input()
s1 = sorted(s)
t1 = sorted(t)[::-1]
print('Yes' if s1 < t1 else 'No')


a = sorted(input())
b = sorted(input())[::-1]
print('Yes' if a < b else 'No')


s = sorted(input())
t = sorted(input())[::-1]
print('Yes' if s < t else 'No')


print('Yes') if sorted(list(input())) < sorted(list(input()), reverse=True) else print('No')


print('Yes' if ''.join(sorted(input())) < ''.join(reversed(sorted(input()))) else 'No')


print('NYoe s'[sorted(input()) < sorted(input())[::-1]::2])


print('YNeos'[''.join(sorted(input())) >= ''.join(sorted(input())[::-1])::2])


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=1)
print('Yes') if s < t else print('No')


def main():
	import sys
	pin = sys.stdin.readline
	pout = sys.stdout.write
	perr = sys.stderr.write
	S = input()
	T = input()
	if S == T:
		print('No')
		return
	if S in T:
		print('Yes')
		return
	s = list(S)
	t = list(T)
	s.sort()
	t.sort(reverse=True)
	if s == t:
		print('No')
		return
	for i in range(min(len(s), len(t))):
		if ord(s[i]) > ord(t[i]):
			print('No')
			return
		elif ord(s[i]) < ord(t[i]):
			print('Yes')
			return
	print('No')
	return
main()


def main():
	s = input()
	t = input()
	s_list = []
	t_list = []
	for i in range(len(s)):
		s_list.append(s[i])
	for i in range(len(t)):
		t_list.append(t[i])
	s_list.sort()
	t_list.sort(reverse=True)
	s_l = len(s_list)
	t_l = len(t_list)
	if s_l >= t_l:
		ans = 'No'
	else:
		ans = 'Yes'
	for i in range(min(s_l, t_l)):
		if s_list[i] == t_list[i]:
			continue
		elif s_list[i] > t_list[i]:
			return 'No'
		else:
			return 'Yes'
	return ans
print(main())


s = input()
t = input()
S = sorted(s)
T = sorted(t, reverse=True)
ans = 'W'
for i in range(min(len(s), len(t))):
	if S[i] > T[i]:
		ans = 'No'
		break
	elif ans == 'W' and S[i] == T[i]:
		ans = 'W'
	elif ans == 'W' and S[i] < T[i]:
		ans = 'Yes'
		break
if ans == 'W':
	if len(s) < len(t):
		ans = 'Yes'
	else:
		ans = 'No'
print(ans)


S = sorted(input())
T = sorted(input())[::-1]
print('Yes' if S < T else 'No')


S = list(sorted(input()))
T = list(reversed(sorted(input())))
print('Yes' if S < T else 'No')


s = str(input())
t = str(input())
a = ''.join(sorted(s))
b = ''.join(sorted(t, reverse=True))
if a < b:
	print('Yes')
else:
	print('No')


s = sorted
print(['No', 'Yes'][s(input()) < s(input(), reverse=1)])


x = list(input())
x.sort()
y = list(input())
y.sort(reverse=True)
print(['No', 'Yes'][x < y])


print('Yes' * (sorted(input()) < sorted(input())[::-1]) or 'No')


s = ''.join(sorted(input()))
t = ''.join(sorted(input()))[::-1]
print(['No', 'Yes'][s < t])


S = input()
T = input()
S_len = len(S)
T_len = len(T)
S_sorted = sorted(S)
T_sorted = sorted(T, reverse=True)
ans = True
for i in range(min(S_len, T_len)):
	s = ord(S_sorted[i])
	t = ord(T_sorted[i])
	if s < t:
		print('Yes')
		return
	if s == t:
		continue
	else:
		print('No')
		return
if S_len >= T_len:
	print('No')
else:
	print('Yes')


(i, s) = (input, sorted)
print(['No', 'Yes'][''.join(s(i())) < ''.join(s(i()))[::-1]])


A = sorted(input())
B = sorted(input())[::-1]
if A < B:
	print('Yes')
else:
	print('No')


s = list(str(input()))
t = list(str(input()))
s.sort()
t.sort(reverse=True)
print('YNeos'[s >= t::2])


s = input()
a = sorted(s)
t = input()
b = sorted(t)
b.reverse()
if a < b:
	print('Yes')
else:
	print('No')


print('Yes') if ''.join(sorted(input())) < ''.join(sorted(input(), reverse=True)) else print('No')


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
l = [''.join(s), ''.join(t)]
if l == sorted(l) and l[0] != l[1]:
	print('Yes')
else:
	print('No')


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=1)
print('YNeos'[s >= t::2])


s = input()
t = input()
s = sorted(s)
t = sorted(t, reverse=True)
s_t = [s, t]
s_t.sort()
if s_t[0] == s and s_t[1] != s:
	print('Yes')
else:
	print('No')


a = sorted(input())
b = sorted(input(), reverse=True)
if b > a:
	print('Yes')
else:
	print('No')


def answer(s: str, t: str) -> str:
	return 'Yes' if sorted(s) < sorted(t, reverse=True) else 'No'

def main():
	s = input()
	t = input()
	print(answer(s, t))

def __starting_point():
	main()
__starting_point()


s = sorted
print(s(input()) < s(input(), reverse=1) and 'Yes' or 'No')


import sys
s = sorted(input())
t = sorted(input())[::-1]
print('Yes' if s < t else 'No')


(a, b) = [sorted(input()) for i in range(2)]
print('Yes' if a < b[::-1] else 'No')


print('Yes' if sorted(input()) < sorted(input(), reverse=1) else 'No')


def main():
	s = sorted(input())
	t = sorted(input(), reverse=True)
	if s < t:
		print('Yes')
	else:
		print('No')
main()


s = list(input())
t = list(input())
N = len(s)
M = len(t)
s_d = sorted(s)
t_d = sorted(t, reverse=True)
ans = 'No'
if N < M:
	new_t = ''.join(t_d[:N])
	new_s = ''.join(s_d)
	if new_t == new_s:
		ans = 'Yes'
if ans == 'No':
	pos = 0
	for i in range(min(N, M)):
		if s_d[i] != t_d[i]:
			pos = i
			break
	if s_d[pos] < t_d[pos]:
		ans = 'Yes'
print(ans)


print('Yes' if sorted(list(input())) < sorted(list(input()))[::-1] else 'No')


s = sorted(input())
t = sorted(input(), reverse=True)
print('Yes' if ''.join(s) < ''.join(t) else 'No')


(s, t) = (''.join(sorted(input())), ''.join(sorted(input(), reverse=True)))
print('YNeos'[s >= t::2])


s = sorted(input())
t = sorted(input(), reverse=True)
ans = 'No'
if s < t:
	ans = 'Yes'
print(ans)


s = input()
t = input()
ss = sorted(s)
tt = sorted(t, reverse=True)
print('Yes' if ss < tt else 'No')


s = list(input())
t = list(input())
s = sorted(s)
t = sorted(t, reverse=True)
flag = [0, 0]
if len(s) < len(t):
	for i in range(len(s)):
		if s[i] < t[i]:
			print('Yes')
			break
		elif s[i] > t[i]:
			print('No')
			break
		elif i == len(s) - 1:
			print('Yes')
elif len(s) > len(t):
	for i in range(len(t)):
		if s[i] < t[i]:
			print('Yes')
			break
		elif s[i] > t[i]:
			print('No')
			break
		elif i == len(t) - 1:
			print('No')
elif len(s) == len(t):
	for i in range(len(s)):
		if s[i] < t[i]:
			print('Yes')
			break
		elif s[i] > t[i]:
			print('No')
			break
		elif i == len(s) - 1:
			print('No')


(s, t) = (sorted(input()), sorted(input())[::-1])
print('YNeos'[sorted([s, t])[0] == t::2])


s = sorted(input())
r = sorted(input(), reverse=True)
if s < r:
	print('Yes')
else:
	print('No')


s = sorted(input())
t = sorted(input())
t.reverse()
if s < t:
	print('Yes')
else:
	print('No')


val = sorted(input())
val2 = sorted(input(), reverse=True)
print('Yes' if val2 > val else 'No')


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
for i in range(min(len(s), len(t))):
	if s[i] < t[i]:
		print('Yes')
		return
	if s[i] > t[i]:
		print('No')
		return
if len(s) < len(t):
	print('Yes')
else:
	print('No')


s = input()
t = input()
S = sorted(s)
T = sorted(t)[::-1]
if S < T:
	print('Yes')
else:
	print('No')


s = input()
t = input()
print(['No', 'Yes'][''.join(sorted(s)) < ''.join(sorted(t, reverse=True))])


print('YNeos'[''.join(sorted(list(input()))) >= ''.join(sorted(list(input()), reverse=True))::2])


(s, t) = open(0)
print('YNeos'[''.join(sorted(s[:-1])) >= ''.join(sorted(t.strip(), reverse=True))::2])


s = list(str(input()))
t = list(str(input()))
asc_s = sorted(s)
desc_t = sorted(t, reverse=True)
print('Yes' if ''.join(asc_s) < ''.join(desc_t) else 'No')


s = sorted((x for x in input()))
t = sorted([x for x in input()], reverse=True)
print('Yes' if s < t else 'No')


print(['No', 'Yes'][''.join(map(str, sorted(input()))) < ''.join(map(str, sorted(input(), reverse=True)))])


import sys
sys.setrecursionlimit(10 ** 6)
s = list(str(input()))
t = list(str(input()))
s.sort()
t.sort(reverse=True)
s = ''.join(s)
t = ''.join(t)
ans = sorted([s, t])
if ans[0] == t:
	print('No')
else:
	print('Yes')


s = input()
t = input()
sp = sorted(s)
tp = sorted(t, reverse=True)
print('Yes' if sp < tp else 'No')


S = input()
T = input()
s = sorted(S)
t = sorted(T)[::-1]
print(['Yes', 'No'][not s < t])


s = input()
t = input()
if s < t:
	print('Yes')
	return
s = list(s)
t = list(t)
s = sorted(s)
t = sorted(t)
t = t[::-1]
s = ''.join(s)
t = ''.join(t)
if s < t:
	print('Yes')
else:
	print('No')


S = list(input())
T = list(input())
S.sort()
T.sort(reverse=True)
alpha = list('abcdefghijklmnopqrstuvwxyz')
check = False
cnt = 0
for (s, t) in zip(S, T):
	res = alpha.index(s) - alpha.index(t)
	if res < 0:
		check = True
		break
	elif res == 0:
		cnt += 1
if cnt == len(S):
	if len(S) < len(T):
		check = True
print('Yes' if check else 'No')


s = input()
t = input()
ss = sorted(s)
tt = sorted(t, reverse=True)

def checker(s, t):
	for sz in ss:
		for tz in tt:
			if sz > tz:
				return 'No'
			elif sz == tz:
				continue
			else:
				return 'Yes'
	if len(ss) < len(tt):
		return 'Yes'
	return 'No'
print(checker(ss, tt))


s = list(input())
t = list(input())
s = sorted(s, reverse=False)
t = sorted(t, reverse=True)
result = 'No'
rang = min(len(s), len(t))
for i in range(rang):
	if ord(s[i]) < ord(t[i]):
		result = 'Yes'
		break
else:
	if s[:rang] == t[:rang] and len(s) < len(t):
		result = 'Yes'
print(result)


I = lambda : ''.join(sorted(list(input())))
print('YNeos'[I() >= I()[::-1]::2])


s = input()
t = input()
S = sorted(s)
T = sorted(t, reverse=True)
print('Yes' if S < T else 'No')


S = sorted(input())
N = sorted(input())
N.reverse()
print('Yes' if S < N else 'No')


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	s = ins()
	t = ins()
	s = sorted(s)
	t = sorted(t, reverse=True)
	return s < t
print('Yes' if solve() else 'No')


(s, t) = [input() for i in range(2)]
print('Yes' if sorted(s) < sorted(t, reverse=True) else 'No')


(s, t) = [sorted(list(input())) for _ in range(2)]
t.reverse()
print('Yes' if s < t else 'No')


print(['No', 'Yes'][''.join(sorted(input())) < ''.join(reversed(sorted(input())))])


a = ''.join(sorted(input()))
b = ''.join(sorted(input())[::-1])
print(['No', 'Yes'][a < b])


s = list(input())
t = list(input())
ss = sorted(s)
tt = sorted(t, reverse=True)
sa = ''.join(ss)
ta = ''.join(tt)
if sa < ta:
	print('Yes')
else:
	print('No')


(s, t) = list((input() for i in range(2)))
print('Yes' if sorted(s) < sorted(t)[::-1] else 'No')


s = sorted(str(input()))
t = sorted(str(input()), reverse=True)
print('Yes' if s < t else 'No')


s = str(input())
t = str(input())
num2alpha = lambda c: chr(c + 96)
alpha2num = lambda c: ord(c) - ord('a') + 1
S = [0] * 26
T = [0] * 26
for i in range(len(s)):
	S[alpha2num(s[i]) - 1] += 1
for i in range(len(t)):
	T[alpha2num(t[i]) - 1] += 1
ss = 0
while S[ss] == 0:
	ss += 1
tt = 25
while T[tt] == 0:
	tt -= 1
if tt < ss:
	print('No')
elif tt > ss:
	print('Yes')
elif T[tt] == sum(T) and S[ss] == sum(S):
	if sum(T) > sum(S):
		print('Yes')
	else:
		print('No')
else:
	print('No')


import io
print('Yes' if sorted(input()) < sorted(input(), reverse=True) else 'No')


s = str(input())
t = str(input())
sort_s_list = sorted(s)
sort_s = ''.join(sort_s_list)
t_list = list(t)
t_list.sort(reverse=True)
reverse_sort_t = ''.join(t_list)
if sort_s < reverse_sort_t:
	print('Yes')
else:
	print('No')


s = input().rstrip()
t = input().rstrip()
s = tuple(sorted(s))
t = tuple(sorted(t, reverse=True))
if s < t:
	print('Yes')
else:
	print('No')


s = sorted(list(input()))
t = sorted(list(input()), reverse=True)
for i in range(min(len(s), len(t))):
	if ord(s[i]) < ord(t[i]):
		print('Yes')
		return
	elif ord(s[i]) > ord(t[i]):
		print('No')
		return
if len(s) >= len(t):
	print('No')
else:
	print('Yes')


s = sorted(input())
t = sorted(input(), reverse=True)
flag1 = True
flag2 = False
if len(s) < len(t):
	for i in range(len(s)):
		if s[i] != t[i]:
			flag1 = False
			break
else:
	flag1 = False
for i in range(min(len(s), len(t))):
	if s[i] < t[i]:
		flag2 = True
		break
	elif s[i] > t[i]:
		break
if flag1 or flag2:
	print('Yes')
else:
	print('No')


s = sorted
print('YNeos'[s(input()) >= s(input())[::-1]::2])


s = sorted(input())
t = sorted(input())
u = list(reversed(t))
print('Yes' if s < u else 'No')


(ss, ts) = (sorted(list(input())), list(reversed(sorted(list(input())))))
result = False
min_size = min(len(ss), len(ts))
if ss[:min_size] == ts[:min_size] and len(ss) < len(ts):
	result = True
else:
	for index in range(min(len(ss), len(ts))):
		if ss[index] < ts[index]:
			result = True
			break
if result:
	print('Yes')
else:
	print('No')


i = input
print(['No', 'Yes'][sorted(i()) < sorted(i())[::-1]])


print('YNeos'[sorted(input()) >= sorted(input(), reverse=True)::2])


s = sorted(input())
t = sorted(input())
t.sort(reverse=True)
print('Yes' if s < t else 'No')


s = sorted(input())
t = sorted(input(), reverse=True)
print('Yes' if s < t and s != t else 'No')


s_min = sorted(input())
t_max = sorted(input())[::-1]
print('Yes' if s_min < t_max else 'No')


S = input()
T = input()
S = sorted(S)
T = sorted(T)[::-1]
print(['No', 'Yes'][S < T])


s = input()
t = input()
ret = sorted(s) < sorted(t, reverse=True)
print('Yes' if ret else 'No')


n = sorted(input())
m = sorted(input(), reverse=True)
if n < m:
	print('Yes')
else:
	print('No')


(s, t) = [sorted(input()) for _ in range(2)]
print('NYoe s'[s < t[::-1]::2])


s = input()
t = input()
import sys
if s == t:
	print('No')
	return
ss = sorted(list(s))
tt = sorted(list(t))[::-1]
if sorted([ss, tt])[0] == ss:
	print('Yes')
else:
	print('No')


from collections import defaultdict
s = input()
t = input()
AL = 'abcdefghijklmnopqrstuvwxyz'
S = defaultdict(int)
T = defaultdict(int)
for al in s:
	S[al] += 1
for al in t:
	T[al] += 1
ans_s = ''
for al in AL:
	ans_s += al * S[al]
ans_t = ''
for al in reversed(list(AL)):
	ans_t += al * T[al]
if ans_s < ans_t:
	print('Yes')
else:
	print('No')


s = input()
t = input()
s_list = list(s)
t_list = list(t)
s_sorted = sorted(s_list)
t_sorted = sorted(t_list, reverse=True)
s_joined = ''.join(s_sorted)
t_joined = ''.join(t_sorted)
if s_joined < t_joined:
	print('Yes')
else:
	print('No')


list_s = sorted(list(input()))
list_t = sorted(list(input()), reverse=True)
if ''.join(list_s) < ''.join(list_t):
	print('Yes')
else:
	print('No')


ss = input()
ts = input()
print('Yes' if sorted(ss) < sorted(ts, reverse=True) else 'No')


s = input()
t = input()
ss = sorted(s)
tt = sorted(t)
print('Yes' if ss < tt[::-1] else 'No')


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
for i in range(min(len(s), len(t))):
	if s[i] < t[i]:
		print('Yes')
		break
	elif s[i] > t[i]:
		print('No')
		break
	else:
		continue
else:
	if len(t) > len(s):
		print('Yes')
	else:
		print('No')


s = sorted
i = input
print(['No', 'Yes'][s(i()) < s(i(), reverse=True)])


s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
s1 = ''.join(s)
t1 = ''.join(t)
if s < t:
	print('Yes')
else:
	print('No')


s = input()
t = input()
s_d = ''.join(sorted(s))
t_d = ''.join(sorted(t, reverse=True))
arr = [t_d, s_d]
arr = sorted(arr)
if s == t:
	print('No')
	return
if arr[0] == s_d:
	print('Yes')
else:
	print('No')


S = sorted(list(str(input())))
T = sorted(list(str(input())), reverse=True)
print('YNeos'[S >= T::2])


s = ''.join(sorted(input()))
t = ''.join(sorted(input())[::-1])
print('YNeos'[s >= t::2])


import sys
input = sys.stdin.readline
s = list(input().strip())
t = list(input().strip())
if sorted(s) < sorted(t, reverse=True):
	print('Yes')
else:
	print('No')


(s, t) = [input() for _ in range(2)]
print('Yes' if sorted(s) < sorted(t)[::-1] else 'No')


s = input()
t = input()
s = sorted(s)
t = sorted(t)[::-1]
answer = 'Yes'
for i in range(len(s)):
	if i == len(t):
		answer = 'No'
		break
	s_c = s[i]
	t_c = t[i]
	if s_c < t_c:
		break
	elif s_c == t_c:
		continue
	else:
		answer = 'No'
		break
if s == t:
	answer = 'No'
print(answer)


print(['No', 'Yes'][''.join(sorted(input())) < ''.join(sorted(input()))[::-1]])


(n, m) = [sorted(list(input())) for i in range(2)]
print('Yes' if n < m[::-1] else 'No')


(s, t) = [input() for i in range(2)]
ns = ''.join(sorted(s))
nt = ''.join(sorted(t, reverse=True))
print('Yes') if ns < nt else print('No')


S = list(input())
T = list(input())
S.sort()
T.sort(reverse=True)
print('Yes' if S < T else 'No')


(s, t) = [sorted(input()) for i in (0, 0)]
print('YNeos'[s >= t[::-1]::2])


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	s = input()
	t = input()
	listS = []
	for i in range(len(s)):
		listS.append(s[i])
	listT = []
	for i in range(len(t)):
		listT.append(t[i])
	listS = sorted(listS)
	listT = sorted(listT, reverse=True)
	sortedS = ''
	for i in range(len(listS)):
		sortedS += listS[i]
	sortedT = ''
	for i in range(len(listT)):
		sortedT += listT[i]
	if sortedS < sortedT:
		print('Yes')
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


s = input()
t = input()
ord_s = []
ord_t = []
for i in range(len(s)):
	ord_s.append(ord(s[i]))
else:
	ord_s.sort()
for i in range(len(t)):
	ord_t.append(ord(t[i]))
else:
	ord_t.sort(reverse=True)
for i in range(min(len(s), len(t))):
	if ord_s[i] < ord_t[i]:
		print('Yes')
		break
	elif ord_s[i] == ord_t[i]:
		pass
	else:
		print('No')
		break
else:
	if len(s) < len(t):
		print('Yes')
	else:
		print('No')


a = list(input())
b = list(input())
a.sort()
b.sort()
b.reverse()
a = ''.join(a)
b = ''.join(b)
if a < b:
	print('Yes')
else:
	print('No')


s = input()
t = input()
data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
S = [0] * len(s)
T = [0] * len(t)
for i in range(len(s)):
	S[i] = data.index(s[i])
for i in range(len(t)):
	T[i] = data.index(t[i])
S.sort()
T.sort(reverse=True)
if S < T:
	print('Yes')
else:
	print('No')


x = sorted(input())
y = sorted(input(), reverse=True)
print('Yes' if x < y else 'No')