Загрузка данных


from itertools import product

# Задача №29340
# Буквы в алфавитном порядке: А, Е, Л, П, Р, Ь
letters1 = ['А', 'Е', 'Л', 'П', 'Р', 'Ь']
words1 = [''.join(w) for w in product(letters1, repeat=6)]

for i, word in enumerate(words1, 1):
    if (i % 2 == 1
            and word[0] not in ('А', 'Л')
            and word.count('П') >= 2):
        print(f"Задача 29340 — первое слово: №{i}, слово: {word}")
        break


# Задача №28929
# Буквы в алфавитном порядке: В, И, Л, М, О, С
letters2 = ['В', 'И', 'Л', 'М', 'О', 'С']
words2 = [''.join(w) for w in product(letters2, repeat=5)]

result2 = None
for i, word in enumerate(words2, 1):
    if (i % 2 == 1
            and word[0] not in ('О', 'С')
            and word.count('В') == 1
            and word.count('С') <= 1):
        result2 = (i, word)

print(f"Задача 28929 — последнее слово: №{result2[0]}, слово: {result2[1]}")