Buggy python submission (verdict: Runtime Error):
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    rem_key = {}
    for key, val in C.most_common():
        if val >= tmp:
            tmp = val
            ans = min(ans, val)
            rem_key.add(key)
        else:
            break
    if len(sports_cand) > 2:
        Q.append(sports_cand-rem_key)
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val >= tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val >= tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    sports_cand = Q.pop(0)
    n_sports = [0]*M
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                n_sports[mat[n][m]] += 1
                break
    max_val = max(n_sports)
    for i, v in enumerate(n_sports):
        if v == max_val:
            ans = min(ans, v)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{i})
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
checked = {"".join([str(v) for v in range(M)])}
while Q:
    sports_cand = Q.pop(0)
    n_sports = [0]*M
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                n_sports[mat[n][m]] += 1
                break
    max_val = max(n_sports)
    for i, v in enumerate(n_sports):
        if v == max_val:
            ans = min(ans, v)
            next_state = "".join(map(str, list(sorted(list(sports_cand-{i})))))
            if len(sports_cand) > 2 and not next_state in checked:
                Q.append(sports_cand-{i})
                checked.add(next_state)
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
checked = {"".join([str(v) for v in range(M)])}
while Q:
    sports_cand = Q.pop(0)
    n_sports = [0]*M
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                n_sports[mat[n][m]] += 1
                break
    max_val = max(n_sports)
    for i, v in enumerate(n_sports):
        if v == max_val:
            ans = min(ans, v)
            next_state = "".join(map(str, sports_cand-{i}))
            if len(sports_cand) > 2 and not next_state in checked:
                Q.append(sports_cand-{i})
                checked.add(next_state)
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    sports_cand = Q.pop(0)
    n_sports = [0]*M
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                n_sports[mat[n][m]] += 1
                break
    max_val = max(n_sports)
    for i, v in enumerate(n_sports):
        if v == max_val:
            ans = min(ans, v)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{i})
print(ans)


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(N)]

ans = float('inf')
sports_cand = set([v for v in range(M)])


def rec(sports_cand, ans):
    if not sports_cand:
        return ans
    else:
        attend_i = [0]*N  # iの参加したいポイント
        attend_sports = [-1]*N  # iの参加するスポーツ
        for s in sports_cand:
            for p in range(N):
                if attend_i[p] < mat[p][s]:  # 今までに見たスポーツよりも参加したい
                    attend_i[p] = mat[p][s]
                    attend_sports[p] = s
        C = Counter(attend_sports)
        num = 0
        for id, tmp_val in C.most_common():
            if tmp_val >= num and id == -1:
                num = tmp_val
            elif tmp_val >= num:
                num = tmp_val
                ans = min(ans, tmp_val)
                ans = min(ans, rec(sports_cand, ans))
                sports_cand.remove(sports_cand - {id})
            else:
                break
    return ans


print(rec(sports_cand, ans))


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(N)]

ans = float('inf')
sports_cand = set([v for v in range(M)])


def rec(sports_cand, ans):
    if not sports_cand:
        return ans
    else:
        attend_i = [0]*N  # iの参加したいポイント
        attend_sports = [-1]*N  # iの参加するスポーツ
        for s in sports_cand:
            for p in range(N):
                if attend_i[p] < mat[p][s]:  # 今までに見たスポーツよりも参加したい
                    attend_i[p] = mat[p][s]
                    attend_sports[p] = s
        C = Counter(attend_sports)
        num = 0
        for id, tmp_val in C.most_common():
            if id == -1:
                continue
            if tmp_val >= num:
                num = tmp_val
                ans = min(ans, tmp_val)
                ans = min(ans, rec(sports_cand, ans))
                sports_cand.remove(sports_cand - {id})
            else:
                break
    return ans


print(rec(sports_cand, ans))


Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)