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


from itertools import product

# 1
w1 = [''.join(p) for p in product('ДРСЩЭ', repeat=4)]
ans1 = w1.index('ЩДЩД') + 1

# 2
w2 = [''.join(p) for p in product('ГИНРЧ', repeat=5)]
ans2 = w2[414]

# 3
w3 = [''.join(p) for p in product('АБРТЫ', repeat=5)]
ans3 = next(i for i, w in enumerate(w3, 1) if 'Ы' not in w and 'АА' not in w)

# 4
w4 = [''.join(p) for p in product('ИНЬЮ', repeat=5)]
ans4 = max(i for i, w in enumerate(w4, 1) if sum(w.count(c) for c in 'ИЮ') == 2)

# 5
w5 = [''.join(p) for p in product('ЕКОФ', repeat=5)]
res5 = []
for i, w in enumerate(w5, 1):
    if w.count('О') == 1:
        j = w.index('О')
        if (j == 0 or w[j - 1] not in 'КФ') and (j == 4 or w[j + 1] not in 'КФ'):
            res5.append(i)
ans5 = res5[0] + res5[-1]

# 6
w6 = [''.join(p) for p in product('АКЛМНЯ', repeat=5)]
mn = [i for i, w in enumerate(w6, 1) if w.startswith('МН')]
ans6 = mn[-1] - mn[0] - 1

# Вывод ответов в столбик
for ans in [ans1, ans2, ans3, ans4, ans5, ans6]:
    print(ans)