def sumsequences(N,K):
    """ 
    All sequences of length N with numbers adding up to K;
    The number of such is sequences is given by the multiset number:
    N+K-1 over K.
    """
    seqs = [ [] ]
    for i in range(N-1):
        new_seqs = []
        for s in seqs:
            for j in range(K - sum(s) + 1):
                new_seqs += [ [j] + s ]
        seqs = new_seqs
    return [ [ K - sum(s) ] + s for s in seqs ]