def check(l, n, m, k):
    for i in range(n):
        if str(k) in set(l[i]):
            return 'Yes'
    return 'No'

while True:
    try:
        n, m, k = map(int, input().split())
        l = []
        for _ in range(n):
            l.append(input().split())
        print(check(l, n, m, k))
    except EOFError:
        break
题目数据不严谨,如果使用一行字符串读入判断包含关系,出现数字包含的字符串输入也会输出Yes,这样代码耗时会大大减少。
def check(l, n, m, k):
    for i in range(n):
        if str(k) in l[i]:
            return 'Yes'
    return 'No'

while True:
    try:
        n, m, k = map(int, input().split())
        l = []
        for _ in range(n):
            l.append(input())
        print(check(l, n, m, k))
    except EOFError:
        break