def substrings(a, b, n):
    """Return substrings of length n in both a and b"""

    def substring(s, n):
        subs = set()

        for i in range(len(s) - 1):
            if n > len(s):
                break
            subs.add(s[i:n])
            n += 1

        return subs

    subs_a = substring(a, n)
    subs_b = substring(b, n)

    matches = subs_a.intersection(subs_b)

    return matches