from itertools import groupby, accumulate
from collections import defaultdict

def sub_seq(li, n):
    d = defaultdict(list)
rle = [(k, len(list(g))) for k, g in groupby(li)]
endpoints = accumulate(size for k, size in rle)
for end_index, (value, count) in zip(endpoints, rle):
    for index in range(end_index - count, end_index - n + 1):
        d[value].append(index)
return dict(d)
Последовательность элементов в списке, удовлетворяющая условию