human
Solve in Python:
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library.

Some long and uninteresting story was removed...

The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large version of a letter x is denoted by x'. BSCII encoding, which is used everywhere in Bookland, is made in that way so that large letters are presented in the order of the numbers they are denoted by, and small letters are presented in the order of the numbers they are denoted by, but all large letters are before all small letters. For example, the following conditions hold: 2 < 3, 2' < 3', 3' < 2.

A word x_1, x_2, ..., x_{a} is not lexicographically greater than y_1, y_2, ..., y_{b} if one of the two following conditions holds:   a ≤ b and x_1 = y_1, ..., x_{a} = y_{a}, i.e. the first word is the prefix of the second word.
 there is a position 1 ≤ j ≤ min(a, b), such that x_1 = y_1, ..., x_{j} - 1 = y_{j} - 1 and x_{j} < y_{j}, i.e. at the first position where the words differ the first word has a smaller letter than the second word has.  

For example, the word "3' 7 5" is before the word "2 4' 6" in lexicographical order. It is said that sequence of words is in lexicographical order if each word is not lexicographically greater than the next word in the sequence.

Denis has a sequence of words consisting of small letters only. He wants to change some letters to large (let's call this process a capitalization) in such a way that the sequence of words is in lexicographical order. However, he soon realized that for some reason he can't change a single letter in a single word. He only can choose a letter and change all of its occurrences in all words to large letters. He can perform this operation any number of times with arbitrary letters of Bookland's alphabet.

Help Denis to choose which letters he needs to capitalize (make large) in order to make the sequence of words lexicographically ordered,...
 ... What is a Python code to fix of the second word?
assistant
#Here is Python code to fix of the second word.

from collections import defaultdict, deque

def main():
    n,m = map(int, input().split())
    cap = [None]*(m+1)
    same_cap = defaultdict(list)
    q = deque()

    def apply_cap(a, c):
        if cap[a] is not None:
            return cap[a] == c
        q.append((a,c))
        while q:
            b = q.pop()
            if b[1] == c:
                if cap[b[0]] is None:
                    cap[b[0]] = c
                    q.extend(same_cap[b[0]])
                    same_cap[b[0]] = []
                elif cap[b[0]]!=c:
                    return False

        return True

    def same(a,b):
        same_cap[b].append((a,True))
        same_cap[a].append((b,False))

        if cap[a] == False:
            return apply_cap(b, False)

        if cap[b] == True:
            return apply_cap(a, True)

        return True

    def process(p,c):
        lp = p[0]
        lc = c[0]
        for i in range(1, min(lp,lc)+1):
            if p[i]>c[i]:
                return apply_cap(p[i], True) and apply_cap(c[i], False)
            if p[i]<c[i]:
                return same(p[i], c[i])
        return lp<=lc

    p = list(map(int, input().split()))
    for i in range(n-1):
        c = list(map(int, input().split()))
        if not process(p, c):
            print ('No')
            break
        p = c
    else:
        print ('Yes')
        res = []
        for i,b in enumerate(cap):
            if b:
                res.append(i)
        print(len(res))
        print(' '.join(map(str,res)))

main()