Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import factorial
from copy import copy

N, M = map(int, input().split())

all_patterns = 1
start, end = None, None
for m_i in range(M + 1):
    if m_i < M:
        a_i = int(input())
    if m_i == 0:
        start = 0
        end = a_i - 1
        next_start = a_i + 1
    elif m_i == M:
        start = copy(next_start)
        end = N
    else:
        start = copy(next_start)
        end = a_i - 1
        next_start = a_i + 1
    passdiff = end - start
    num_2 = passdiff // 2
    residue = passdiff % 2

    tmp_patterns_for_range = 0
    for num2to1 in range(num_2 + 1):
        add_n_1 = num2to1 * 2
        tmp_num2 = num_2 - num2to1
        tmp_n_pattern = \
            factorial(tmp_num2 + add_n_1 + residue) \
            // factorial(tmp_num2) \
            // factorial(add_n_1 + residue)
        tmp_patterns_for_range += tmp_n_pattern
    all_patterns *= tmp_patterns_for_range

print(all_patterns % 1000000007)


Fixed submission:
N, M = map(int, input().split())

if M == 0:
    alist = set()
else:
    alist = set(int(input()) for _ in range(M))

dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 1 if 1 not in alist else 0

MOD = 10**9 + 7
for i in range(2, N + 1):
    if i in alist:
        continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

N, M = map(int, input().split())
search_starts = [0]
search_ends = []
for _ in range(M):
    a_i = int(input())
    search_ends.append(a_i-1)
    search_starts.append(a_i+1)
search_ends.append(N)

all_patterns = 1
for start, end in zip(search_starts, search_ends):
    passdiff = end - start
    num_2 = passdiff // 2
    residue = passdiff % 2

    tmp_patterns_for_range = 0
    for num2to1 in range(num_2+1):
        add_n_1 = num2to1 * 2
        tmp_num2 = num_2 - num2to1
        tmp_n_pattern = \
            factorial(tmp_num2 + add_n_1 + residue) // factorial(tmp_num2) // factorial(add_n_1 + residue)
        tmp_patterns_for_range += tmp_n_pattern
    all_patterns *= tmp_patterns_for_range

print(all_patterns%1000000007)

Fixed submission:
N, M = map(int, input().split())

if M == 0:
    alist = set()
else:
    alist = set(int(input()) for _ in range(M))

dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 1 if 1 not in alist else 0

MOD = 10**9 + 7
for i in range(2, N + 1):
    if i in alist:
        continue
    dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
v_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

max_diff = -10000000
for selection in range(1 << N):
    v_tmp = 0
    c_tmp = 0
    for idx in range(N):
        if (selection >> idx) & 1:
            v_tmp += v_list[idx]
            c_tmp += c_list[idx]
    max_diff = max(max_diff, v_tmp - c_tmp)

print(max_diff)

Fixed submission:
from itertools import combinations

N = int(input())
v_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

max_diff = -10000000
for n_selection in range(0, N+1):
    v_selected = list(combinations(v_list, n_selection))
    c_selected = list(combinations(c_list, n_selection))
    if n_selection == 0:
        max_diff = max(max_diff, 0)
    for i in range(len(v_selected)):
        X = sum(v_selected[i])
        Y = sum(c_selected[i])
        max_diff = max(max_diff, X - Y)

print(max_diff)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from itertools import combinations
from functools import reduce
import random

N = int(input())
a_list = list(map(int, input().split()))

origina_gcd = reduce(gcd, a_list)

n_1_combis = combinations(a_list, N - 1)

max_gcd = 1
for combi in n_1_combis:
    tmp_gcd = reduce(gcd, combi)
    max_gcd = max(max_gcd, tmp_gcd)
print(max_gcd)

Fixed submission:
from fractions import gcd

N = int(input())
AAA = list(map(int, input().split()))

# +1 shifted
dp_l = [0] * (N + 1)
dp_r = [0] * (N + 1)

dp_l[0] = 0
dp_r[0] = 0

for i in range(1, N):
    dp_l[i] = gcd(dp_l[i - 1], AAA[i - 1])
    dp_r[i] = gcd(dp_r[i - 1], AAA[-i])

max_gcd = 0
for i in range(N + 1):
    gcd_cand = gcd(dp_l[i], dp_r[N - i - 1])
    max_gcd = max(gcd_cand, max_gcd)

print(max_gcd)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    part_len = r - l + 1
    removed_len = len(S[l - 1:r].replace('AC', ''))
    n_ac = (part_len - removed_len) // 2
    print(n_ac)


Fixed submission:
N, Q = map(int, input().split())
S = input()

t = [0] * (N+2)
t[0] = 1 if S[:2] == 'AC' else 0

for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i + 2] == 'AC' else 0)

for _ in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()

t = [0] * (N+2)
t[0] = 1 if S[:2] == 'AC' else 0

for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i + 2] == 'AC' else 0)

for _ in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()

t = [0] * (N+2)
t[0] = 1 if S[:2] == 'AC' else 0

for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i + 2] == 'AC' else 0)

for _ in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()

t = [0] * (N+2)
t[0] = 1 if S[:2] == 'AC' else 0

for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i + 2] == 'AC' else 0)

for _ in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
from fractions import gcd 

n = int(input())
a_set = set(map(int, input().split()))
max_a = max(a_set)
min_sub = max_a


if len(a_set) == 1:
    print(a_list[0])
    exit()
elif 1 in a_set:
    print(1)
    exit()
else:
    for val in a_set:
        min_sub = min(gcd(max_a, val), min_sub)
        if min_sub == 1:
            print(1)
            exit()
print(min_sub)

Fixed submission:
from fractions import gcd 

n = int(input())
a_set = set(map(int, input().split()))
max_a = max(a_set)
min_sub = max_a

for val in a_set:
    min_sub = min(gcd(max_a, val), min_sub)
    if min_sub == 1:
        print(1)
        exit()
print(min_sub)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i, h in enumerate(hhh):
    s = 0 if i < K else i-K
    if i == 0:
        continue
    dp[i] = \
        min([abs(hhh[i] - h_k) + dp_k for h_k, dp_k in zip(hhh[s:i], dp[s:i])])

print(dp[-1])


Fixed submission:
# WIP
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, i+1)])
    else:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, K+1)])

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# WIP
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, i+1)])
    else:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, K+1)])

print(dp[-1])


Fixed submission:
# WIP
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, i+1)])
    else:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, K+1)])

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split())
    for w_k in range(1, W+1):
        if w_k >= w:
            dp[i][w_k] = max(dp[i-1][w_k-w] + v, dp[i-1][w_k])
        else:
            dp[i][w_k] = dp[i-1][w_k]

print(max(dp[N]))


Fixed submission:
N, W = map(int, input().split())

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split())
    for w_k in range(1, W+1):
        if w_k >= w:
            dp[i][w_k] = max(dp[i-1][w_k-w] + v, dp[i-1][w_k])
        else:
            dp[i][w_k] = dp[i-1][w_k]

print(max(dp[N]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

is_all_swappd = False
n_swap = 0
n_white = s.count('W')
for i in range(n_white):
    w_idx = None
    if i == 0:
        w_idx = s.find('W')
    else:
        w_idx = s[last_w_idx + 1:].find('W') + last_w_idx + 1
    n_swap += s[:w_idx].count('B')
    last_w_idx = w_idx

print(n_swap)

Fixed submission:
s = input()

is_all_swappd = False
n_swap = 0
n_white = s.count('W')
for i in range(n_white):
    w_idx = None
    if i == 0:
        w_idx = s.find('W')
    else:
        w_idx = s[last_w_idx + 1:].find('W') + last_w_idx + 1
    n_swap += w_idx - i
    last_w_idx = w_idx

print(n_swap)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

is_all_swappd = False
n_swap = 0
while is_all_swappd is not True:
    start_idx = s.find('BW')
    if start_idx != -1:
        s_list = list(s)
        s_list[start_idx], s_list[start_idx+1] = \
            s_list[start_idx+1], s_list[start_idx]
        n_swap += 1
        s = "".join(s_list)
    else:
        is_all_swappd = True

print(n_swap)

Fixed submission:
s = input()

is_all_swappd = False
n_swap = 0
n_white = s.count('W')
for i in range(n_white):
    w_idx = None
    if i == 0:
        w_idx = s.find('W')
    else:
        w_idx = s[last_w_idx + 1:].find('W') + last_w_idx + 1
    n_swap += w_idx - i
    last_w_idx = w_idx

print(n_swap)
Buggy python submission (verdict: Runtime Error):
n = int(input())

spoken_words = []
for i in range(9):
    word = input()
    if i >= 1:
        if word in spoken_words or spoken_words[-1][-1] != word[0]:
            print("No")
            exit()
    spoken_words.append(word)
print("Yes")

Fixed submission:
n = int(input())

spoken_words = []
for i in range(n):
    word = input()
    if i >= 1:
        if word in spoken_words or spoken_words[-1][-1] != word[0]:
            print("No")
            exit()
    spoken_words.append(word)
print("Yes")
Buggy python submission (verdict: Runtime Error):
S = input()
S_list = list(map(int, S.split()))
K = int(input())

S_set_under_K = set(S[:K])

if len(S_set_under_K) == 1 and S_list[0] == 1:
    print(1)
else:
    print(S_list[1])


Fixed submission:
S = input()
S_list = list(map(int, list(S)))
K = int(input())

S_set_under_K = set(S[:K])

if len(S) == 1:
    print(S)
elif len(S_set_under_K) == 1 and S_list[0] == 1:
    print(1)
else:
    for c in S:
        if c != "1":
            print(c)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())

int_list = [i for i in range(a, b + 1)]
out_list = sorted(int_list[:k] + int_list[-k:])

last_val = 0
for out_val in out_list:
    if last_val != out_val:
        print(out_val)
    last_val = out_val

Fixed submission:
a, b, k = map(int, input().split())

lower_list = [i for i in range(a, a + k)]
upper_list = [i for i in range(b, b - k, -1)]
out_list = sorted(set(lower_list + upper_list))

for out_val in out_list:
    if a <= out_val <= b:
        print(out_val)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())

int_list = [i for i in range(a, b + 1)]
out_list = sorted(int_list[:k] + int_list[-k:])

last_val = 0
for out_val in out_list:
    # Neglect duplicated value
    if last_val != out_val:
        print(out_val)
    last_val = out_val

Fixed submission:
a, b, k = map(int, input().split())

lower_list = [i for i in range(a, a + k)]
upper_list = [i for i in range(b, b - k, -1)]
out_list = sorted(set(lower_list + upper_list))

for out_val in out_list:
    if a <= out_val <= b:
        print(out_val)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())

int_list = [i for i in range(a, b+1)]
out_list = sorted(set(int_list[:k] + int_list[-k:])) 

for out_val in out_list:
    print(out_val)

Fixed submission:
a, b, k = map(int, input().split())

lower_list = [i for i in range(a, a + k)]
upper_list = [i for i in range(b, b - k, -1)]
out_list = sorted(set(lower_list + upper_list))

for out_val in out_list:
    if a <= out_val <= b:
        print(out_val)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

combi = [A, B, C]
max_ABC = max([A, B, C])
other = [c for c in combi if c != max_ABC]
max_other = max(other)
min_other = min(other)

# Operation (1st method)
n_operation = max_ABC - max_other
max_other += n_operation
min_other += n_operation

if max_other == min_other:
    print(n_operation)
    exit()

# Operation (2nd method)
if (max_ABC - min_other) % 2:
    n_add = (max_ABC - min_other) // 2 + 1
else:
    n_add = (max_ABC - min_other) // 2
n_operation += n_add

print(n_operation)


Fixed submission:
# WIP
A, B, C = map(int, input().split())

combi = [A, B, C]
set_abc = set(combi)

len_set_abc = len(set_abc)
max_set = max(set_abc)
min_set = min(set_abc)
if len_set_abc == 1:
    print(0)
elif len_set_abc == 2:
    max_freq = combi.count(max_set)
    diff = max_set - min_set
    if max_freq == 2 and diff % 2:
        print((diff + 1) // 2 + 1)
    elif max_freq == 2:
        print(diff // 2)
    else:
        print(diff)
else:
    other = [c for c in combi if c != max_set]
    max_other = max(other)
    min_other = min(other)
    
    n_operation = max_set - max_other
    max_other += n_operation
    min_other += n_operation

    diff = max_set - min_other
    if diff % 2 and diff == 1:
        n_add = (max_set - min_other) // 2 + 2
    elif diff % 2:
        n_add = (max_set - min_other) // 2 + 2
    else:
        n_add = (max_set - min_other) // 2
    n_operation += n_add

    print(n_operation)

Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

combi = [A, B, C]
max_ABC = max([A, B, C])
other = [c for c in combi if c != max_ABC]
max_other = max(other)
min_other = min(other)

# Operation (1st method)
n_operation = max_ABC - max_other
max_other += n_operation
min_other += n_operation

# print(max_ABC, max_other, min_other, 'n_op:', n_operation)

# Operation (2nd method)
diff = max_ABC - min_other
if diff % 2 and diff == 1:
    n_add = (max_ABC - min_other) // 2 + 2
elif diff % 2:
    n_add = (max_ABC - min_other) // 2 + 1
else:
    n_add = (max_ABC - min_other) // 2
n_operation += n_add

print(n_operation)


Fixed submission:
# WIP
A, B, C = map(int, input().split())

combi = [A, B, C]
set_abc = set(combi)

len_set_abc = len(set_abc)
max_set = max(set_abc)
min_set = min(set_abc)
if len_set_abc == 1:
    print(0)
elif len_set_abc == 2:
    max_freq = combi.count(max_set)
    diff = max_set - min_set
    if max_freq == 2 and diff % 2:
        print((diff + 1) // 2 + 1)
    elif max_freq == 2:
        print(diff // 2)
    else:
        print(diff)
else:
    other = [c for c in combi if c != max_set]
    max_other = max(other)
    min_other = min(other)
    
    n_operation = max_set - max_other
    max_other += n_operation
    min_other += n_operation

    diff = max_set - min_other
    if diff % 2 and diff == 1:
        n_add = (max_set - min_other) // 2 + 2
    elif diff % 2:
        n_add = (max_set - min_other) // 2 + 2
    else:
        n_add = (max_set - min_other) // 2
    n_operation += n_add

    print(n_operation)
Buggy python submission (verdict: Runtime Error):
# WIP
N, M = map(int, input().split())

if N == 1:
    print(max(M - 2, 0)))
elif M == 1:
    print(max(M - 2, 0)))
elif N == 1 and M == 1:
    print(1)
else:
    # Number of cards appearing "back"
    # = (N-2)*(M-2)
    print(max((N - 2) * (M - 2), 0))

"""
# An experiment
n_count_map = [[0 for _ in range(M)] for _ in range(N)]


def update(x, y):
    # Count
    n_count_map[y][x] += 1
    if y + 1 < N:
        n_count_map[y + 1][x] += 1
    if y - 1 >= 0:
        n_count_map[y - 1][x] += 1
    if x + 1 < M:
        n_count_map[y][x + 1] += 1
    if x - 1 >= 0:
        n_count_map[y][x - 1] += 1
    if y + 1 < N and x + 1 < M:
        n_count_map[y + 1][x + 1] += 1
    if y - 1 >= 0 and x - 1 >= 0:
        n_count_map[y - 1][x - 1] += 1
    if y + 1 < N and x - 1 >= 0:
        n_count_map[y + 1][x - 1] += 1
    if y - 1 >= 0 and x + 1 < M:
        n_count_map[y - 1][x + 1] += 1


for n in range(N):
    for m in range(M):
        update(m, n)

print(n_count_map)
"""


Fixed submission:
# WIP
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M - 2 if M > 2 else 0)
elif M == 1:
    print(N - 2 if N > 2 else 0)
elif N > 2 and M > 2:
    print((N - 2) * (M - 2))
else:
    print(0)

"""
# An experiment
n_count_map = [[0 for _ in range(M)] for _ in range(N)]


def update(x, y):
    # Count
    n_count_map[y][x] += 1
    if y + 1 < N:
        n_count_map[y + 1][x] += 1
    if y - 1 >= 0:
        n_count_map[y - 1][x] += 1
    if x + 1 < M:
        n_count_map[y][x + 1] += 1
    if x - 1 >= 0:
        n_count_map[y][x - 1] += 1
    if y + 1 < N and x + 1 < M:
        n_count_map[y + 1][x + 1] += 1
    if y - 1 >= 0 and x - 1 >= 0:
        n_count_map[y - 1][x - 1] += 1
    if y + 1 < N and x - 1 >= 0:
        n_count_map[y + 1][x - 1] += 1
    if y - 1 >= 0 and x + 1 < M:
        n_count_map[y - 1][x + 1] += 1


for n in range(N):
    for m in range(M):
        update(m, n)

print(n_count_map)
"""
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())
SSS = [input() for _ in range(N)]

# Filter1
filter_1 = {'M', 'A', 'R', 'C', 'H'}
canditates = [S for S in SSS if S[0] in filter_1]

n_satisfied = 0
for cand in combinations(canditates, 3):
    cond1 = cand[0][0] != cand[1][0]
    cond2 = cand[1][0] != cand[2][0]
    cond3 = cand[2][0] != cand[0][0]
    if cond1 and cond2 and cond3:
        n_satisfied += 1

print(n_satisfied)


Fixed submission:
# WIP
from itertools import combinations

N = int(input())
SSS = [input() for _ in range(N)]

# Filter1
filter_1 = {'M', 'A', 'R', 'C', 'H'}
canditates = [S for S in SSS if S[0] in filter_1]
cand_inits = [c[0] for c in canditates]
cand_inits_set = set(cand_inits)
init_counts = {init_c: cand_inits.count(init_c) for init_c in filter_1}

n_combi = 0
for init_combi in combinations(cand_inits_set, 3):
    tmp_combi = 1
    for init_c in init_combi:
        tmp_combi *= init_counts[init_c]

    n_combi += tmp_combi

print(n_combi)
Buggy python submission (verdict: Runtime Error):
# 初見分からず
# 考え方：個数の組み合わせを総当たりで全パターン試せばよい！
a, b, c, x = map(int, [val for val in input()])

n_pattern = 0
for i in range(a+1):#0~a+1
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == 1:
                n_pattern += 1

print(n_pattern)

Fixed submission:
# 初見分からず
# 考え方：個数の組み合わせを総当たりで全パターン試せばよい！
a, b, c, x = map(int, [input() for val in range(4)])

n_pattern = 0
for i in range(a+1):#0~a+1
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                n_pattern += 1

print(n_pattern)
Buggy python submission (verdict: Runtime Error):
n , y= map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1 - i):
            if  10000 * i + 5000 * j + 1000 * k == y:
                print(i, j, n - i - j)
                exit()
                    
print(-1, -1, -1)        

Fixed submission:
n , y= map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1 - i):
            if  10000 * i + 5000 * j + 1000 * (n - i - j) == y:
                print(i, j, n - i - j)
                exit()
                    
print(-1, -1, -1)

Buggy python submission (verdict: Time Limit Exceeded):
n , y= map(int, input().split())

for i in range(n+1):
    for j in range(n+1):
        for k in range(n+1):
            if i + j + k == n:
                if  10000 * i + 5000 * j + 1000 * k == y:
                    print(i, j, k)
                    exit()
                    
print(-1, -1, -1)  

Fixed submission:
n , y= map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1 - i):
            if  10000 * i + 5000 * j + 1000 * (n - i - j) == y:
                print(i, j, n - i - j)
                exit()
                    
print(-1, -1, -1)
Buggy python submission (verdict: Runtime Error):
s = sorted(input())
t = sorted(input(), reverse=True)
len_s = len(s)
len_t = len(t)
n_passed = 0

for i in range(len_s):
    if s[i] < t[i]:
        print("Yes")
        exit()

t = sorted(t)
if len_s < len_t:
    for i in range(len_s):
        if s[i] == t[i]:
            n_passed += 1
    if n_passed == len_s:
        print("Yes")
        exit()
print("No")

Fixed submission:
s = sorted(input())
t = sorted(input(), reverse=True)
len_s = len(s)
len_t = len(t)
n_passed = 0

min_len = min(len_s, len_t)
for i in range(min_len):
    if s[i] < t[i]:
        print("Yes")
        exit()

if len_s < len_t:
    t = sorted(t)
    for i in range(len_s):
        if s[i] == t[i]:
            n_passed += 1
    if n_passed == len_s:
        print("Yes")
        exit()
        
print("No")