Problem:
 Score : 700 points    Problem Statement Takahashi is hosting an sports meet.
There are N people who will participate. These people are conveniently numbered 1 through N .
Also, there are M options of sports for this event. These sports are numbered 1 through M .
Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i 's j -th favorite sport is Sport A_{ij} .
Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people.
Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.
Find the minimum possible number of the participants in the sport with the largest number of participants.      Constraints  1 \leq N \leq 300  1 \leq M \leq 300  A_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M .         Input Input is given from Standard Input in the following format:  N  M  A_{11}  A_{12}  ...  A_{1M}  A_{21}  A_{22}  ...  A_{2M}  :  A_{N1}  A_{N2}  ...  A_{NM}       Output Print the minimum possible number of the participants in the sport with the largest number of participants.        Sample Input 1 4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1      Sample Output 1 2  Assume that Sports 1 , 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1 , Person 2 in Sport 3 , Person 3 in Sport 3 and Person 4 in Sport 4 .
Here, the sport with the largest number of participants is Sport 3 , with two participants.
There is no way to reduce the number of participants in the sport with the largest number of participants to 1 . Therefore, the answer is 2 .       Sample Input 2 3 3
2 1 3
2 1 3
2 1 3      Sample Output 2 3  Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.
Therefore, the answer is 3 .

Solution (Python):
n, m = map(int, raw_input().split())
a = [map(int, raw_input().split())[::-1] for _ in xrange(n)]
ans = n
d = [0] * (m + 1)
for i in xrange(m):
    s = [0] * (m + 1)
    for j in xrange(n):
        while d[a[j][-1]]:
            a[j].pop()
            continue
        s[a[j][-1]] += 1
    l = 1
    for i in xrange(m + 1):
        if s[l] < s[i]:
            l = i
    d[l] = 1
    ans = min(ans, s[l])
print ans

Solution (Python):
N, M = map(int, input().split())
A = [[0 for i in range(M)] for j in range(N)]

for i in range(N):
    A[i] = list(map(int, input().split()))

ans = float('inf')
for i in range(M):
    rank = [0] * M
    for j in range(N):
        rank[A[j][0] - 1] += 1
    ans = min(ans, max(rank))
    remove_idx = rank.index(max(rank)) + 1
    for j in range(N):
        A[j].remove(remove_idx)
print(ans)

Solution (Python):
def main():
    n, m = [int(x) for x in raw_input().split()]
    a = [[int(x) - 1 for x in raw_input().split()] for i in xrange(n)]
    ans = n
    for _ in xrange(m):
        cnt = [0] * m
        for ai in a:
            cnt[ai[0]] += 1
        c = max(xrange(m), key=lambda k: cnt[k])
        ans = min(ans, cnt[c])
        for ai in a:
            ai.remove(c)
    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
import numpy as np

N, M = list(map(int, input().split(" ")))

A = []
for i in range(N):
    A.append(list(map(int, input().split(" "))))
    

ans = 9999999999999999

A_np = np.asarray(A)
for i in range(M):
    tmp = np.bincount(A_np[:, 0]).max()
    a = np.bincount(A_np[:, 0]).argmax()
    if tmp < ans:
        ans = tmp
    
    A_flatten = A_np.flatten()
    A_flatten = np.delete(A_flatten, np.where(A_flatten == a)[0])
    A_np = A_flatten.reshape((N, M-1-i))
    
print (ans)

Solution (Python):

N, M = map(int, input().split())
arys = []
for i in range(N):
    tmp = input()
    ary = [int(a) - 1 for a in tmp.split()]
    arys.append(ary)


s = set([i for i in range(M)])
i_s = [0 for i in range(len(arys))]
min_num = None
while len(s) > 0:
    select_num = [0 for i in range(M)]
    max_v = None
    max_k = None
    for j, ary in enumerate(arys):
        while ary[i_s[j]] not in s:
            i_s[j] += 1
        select_num[ary[i_s[j]]] += 1
        tmp = select_num[ary[i_s[j]]]
        if max_v is None or max_v < tmp:
            max_v = tmp
            max_k = ary[i_s[j]]
    if min_num is None or min_num > max_v:
        min_num = max_v
    s.remove(max_k)
print(min_num)

Solution (Python):
N, M = map(int, input().split())
a = []

for i in range(N):
    a_i = list(map(int, input().split()))
    a.append(a_i)

max_min_num = N
for _ in range(M):
    selected = {}
    for i in range(N):
        if a[i][0] in selected:
            selected[a[i][0]] += 1
        else:
            selected[a[i][0]] = 1
    max_value = 0
    target_key = 0
    for key, value in selected.items():
        if value > max_value:
            max_value = value
            target_key = key
    if max_min_num > max_value:
        max_min_num = max_value

    for i in range(N):
        a[i].remove(target_key)

print(max_min_num)

Solution (Python):
n, m = map(int, input().split())
rank = []
ind = [0 for i in range(n)]
for i in range(n):
    rank.append(list(map(int, input().split())))
sports = set(range(1, m + 1))
best = n
while len(sports) > 0:
    kol = [0 for i in range(m + 1)]
    for i in range(n):
        while rank[i][ind[i]] not in sports:
            ind[i] += 1
        kol[rank[i][ind[i]]] += 1
    best = min(best, max(kol))
    new_sports = []
    for s in sports:
        if kol[s] < best:
            new_sports.append(s)
    sports = set(new_sports)
print(best)

Solution (Python):

import collections

N, M = map(int, input().split())

A = []
for _ in range(N):
    A.append(list(map(int, input().split())))

res = N
for _ in range(M-1):
    count_dict = collections.Counter([a[0] for a in A])
    sport, count = count_dict.most_common(1)[0]
    res = min(res, count)
    for a in A:
        a.remove(sport)

print(res)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def gcd(a,b):
    while b>0:
        a,b = b,a
        b %= a
    return a

def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    ai = [0] * n
    d = collections.defaultdict(int)
    for i in range(n):
        d[a[i][0]] += 1
    dr = r = max(d.values())
    s = set(list(range(1,m+1)))
    while s:
        for k,v in d.items():
            if v == dr:
                s.remove(k)
        if not s:
            break
        d = collections.defaultdict(int)
        for i in range(n):
            while a[i][ai[i]] not in s:
                ai[i] += 1
        for i in range(n):
            d[a[i][ai[i]]] += 1
        dr = max(d.values())
        if r > dr:
            r = dr
    return r


print(main())

Solution (Python):
N,M=map(int, input().split())
A=[]
for i in range(N):
  A.append(list(map(int,input().split())))

ans=N

for i in range(M-1):
  sanka=[0]*M
  for j in range(N):
    sanka[A[j][0]-1]+=1

  saidai=max(enumerate(sanka), key=lambda x: x[1])[0]+1

  ans=min(ans,max(sanka))
  for j in range(N):
    A[j].remove(saidai)

print(ans)

Solution (Python):

import sys

input=sys.stdin.readline

n,m=map(int,input().split())

g=[list(map(lambda x:int(x)-1,input().split())) for _ in range(n)]
picking=[0]*n


hist=[0]*m
sport=[1]*m
for i in range(n):
    hist[g[i][0]]+=1
ans=max(hist)


for _ in range(m-1):
    
    b=0
    while not sport[b]: b+=1
    for i in range(b+1,m):
        if hist[b]<hist[i]:
            b=i
    sport[b]=0
    
    for i in range(n):
        while not sport[g[i][picking[i]]]:
            hist[g[i][picking[i]]]-=1
            picking[i]+=1
            hist[g[i][picking[i]]]+=1
    
    ans=min(ans,max(hist))

print(ans)