def de_bruijn(k, n):
    
    try:
        
        
        _ = int(k)
        alphabet = list(map(str, range(k)))

    except (ValueError, TypeError):
        alphabet = k
        k = len(k)

    a = [0] * k * n
    sequence = []

    def db(t, p):
        if t > n:
            if n% p == 0:
                sequence.extend(a[1:p + 1])
        else:
            a[t] = a[t - p]
            db(t + 1, p)
            for j in range(a[t - p] + 1, k):
                a[t] = j
                db(t + 1, t)
    db(1, 1)
    return .join(alphabet[i] for i in sequence)

def validate(db):
    

    dbwithwrap = db+db[0:3]

    digits = '0123456789'

    errorstrings = []

    for d1 in digits:
        for d2 in digits:
            for d3 in digits:
                for d4 in digits:
                    teststring = d1+d2+d3+d4
                    if teststring not in dbwithwrap:
                        errorstrings.append(teststring)

    if len(errorstrings) > 0:
        print(+str(len(errorstrings))+)
        for e in errorstrings:
            print(+e+)
    else:
        print()

db = de_bruijn(10, 4)

print()
print(, str(len(db)))
print()
print(+db[0:130])
print()
print(+db[-130:])
print()
print()
validate(db)
dbreversed = db[::-1]
print()
print()
validate(dbreversed)
dboverlaid = db[0:4443]+'.'+db[4444:]
print()
print()
validate(dboverlaid)