Problem:


When Can We Meet?

The ICPC committee would like to have its meeting as soon as
possible to address every little issue of the next contest.  
However, members of the committee are so busy maniacally developing
(possibly useless) programs that it is very difficult to arrange
their schedules for the meeting.
So, in order to settle the meeting date, the chairperson requested every
member to send back a list of convenient dates by E-mail.
Your mission is to help the chairperson, who is now dedicated to other
issues of the contest, by writing a program that 
chooses the best date from the submitted lists.
Your program should find the date convenient for the most members.
If there is more than one such day, the earliest is the best.

Input

The input has multiple data sets, each starting with a line
containing the number of committee members and the quorum of the meeting.
N Q

Here, N, meaning the size of the committee, and Q
meaning the quorum, are positive integers.  N is less than 50,
and, of course, Q is less than or equal to N.

N lines follow, each describing convenient dates for a
committee
member in the following format.

M Date1 
Date2 ... DateM

Here, M means the number of convenient dates for
the member, which is an integer greater than or equal to zero.
The remaining items in the line are his/her dates of convenience,
which are positive integers less than 100, that is, 1 means tomorrow, 
2 means the day after tomorrow, and so on.
They are in ascending order without any repetition 
and separated by a space character.
Lines have neither leading nor trailing spaces.

A line containing two zeros indicates the end of the input.

Output

For each data set, print a single line containing the date number
convenient for the largest number of committee members.
  If there is more than one
such date, print the earliest.  However, if no dates are convenient
for more than or equal to the quorum number of members, print 0 instead.

Sample Input

3 2
2 1 4
0
3 3 4 8
3 2
4 1 5 8 9
3 2 5 9
5 2 4 5 7 9
3 3
2 1 4
3 2 5 9
2 2 4
3 3
2 1 2
3 1 2 9
2 2 4
0 0

Output for the Sample Input

4
5
0
2



Sample input:
3 2
2 1 4
0
3 3 4 8
3 2
4 1 5 8 9
3 2 5 9
5 2 4 5 7 9
3 3
2 1 4
3 2 5 9
2 2 4
3 3
2 1 2
3 1 2 9
2 2 4
0 0


Sample output:
4
5
0
2

Submission status: Accepted

Solution code:
def get_input():
    data_list = input().split()
    for i in range(len(data_list)):
        data_list[i] = int(data_list[i])
    return data_list

def make_dict(day_dict, data_list):
    candidate_num =data_list[0] + 1
    for i in range(1, candidate_num):
        data = data_list[i]
        if data in day_dict:
            day_dict[data] += 1
        else:
            day_dict[data] = 1
    return day_dict

def decide_open_day(day_dict, quorum):
    max_num = max(day_dict.values())
    if max_num < quorum:
        return 0
    max_k_list = [kv[0] for kv in day_dict.items() if kv[1] == max_num]
    open_day = min(max_k_list)
    return open_day


if __name__ == "__main__":
    while True:
        member_num, quorum = get_input()
        if member_num == 0:
            break
        day_dict = dict()
        for i in range(member_num):
            data_list = get_input()
            day_dict = make_dict(day_dict, data_list)
        if day_dict == {}: # remove candidate_day is None
            print(0)
        else:
            open_day = decide_open_day(day_dict, quorum)
            print(open_day)

Submission status: Accepted

Solution code:
while 1:
    n, q = map(int, input().split())
    if n==0: break
    a = []
    for _ in range(n):
        a = a + list(map(int, input().split()))[1:]
    max = 0
    d = 0
    for i in range(1, 101):
        if a.count(i) >= q and max < a.count(i):
            max = a.count(i)
            d = i
    print(d)

Submission status: Accepted

Solution code:
while(True):
	N, Q = map(int, input().split())
	if (N+Q) == 0:break
	D = list(list(int(i) for i in input().split()) for i in range(N))
	D_i  = [1]*N
	answer = 0
	now_max = Q -1
	for i in range(1,100):
		member = 0
		for j in range(N):
			if D[j][0] < D_i[j]:
				continue
			if D[j][D_i[j]] == i:
				member += 1
				D_i[j] += 1
		if member > now_max :
			answer = i
			now_max = member
		if member == N:
			answer = i
			break
	print(answer)

Submission status: Accepted

Solution code:

while(1):
    N,Q=tuple(map(int,input().split()))
    if not(N or Q):
        break
    data=[]
    temp=[]
    for i in range(N):
        temp=list(map(int,input().split()))
        temp.pop(0)
        data.append(temp) 

    sum=0
    max=0
    index=0
    for i in range(100):
        sum=0
        for j in range(N):
            sum=sum+int((i in data[j]))
            if sum >= Q and sum > max:
                max = sum
                index=i

    print(index)

Submission status: Accepted

Solution code:
from collections import defaultdict
while True:
  n, q = list(map(int, input().split()))
  if n==0:
    break

  t = defaultdict(int)
  for i in range(n):
    d = list(map(int, input().split()))
    for j in range(1, len(d)):
      t[d[j]]+=1
  tt = sorted(t.items())
  tt.sort(key=lambda x: -x[1])
  if len(tt)==0 or tt[0][1]<q:
    print(0)
  else:
    print(tt[0][0])

Submission status: Accepted

Solution code:
from collections import defaultdict
def main(n, m):
    d = defaultdict(int)
    for _ in range(n):
        M = list(map(int, input().split()))
        for num, i in enumerate(M):
            if num == 0: continue
            d[i] += 1
    ans = 10**20
    for key, value in d.items():
        if value > m:
            ans = key
            m = value
        elif value == m:
            ans = min(ans,key)
    if ans == 10 ** 20:
        ans = 0
    print(ans)

while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    main(n,m)

Submission status: Accepted

Solution code:
while True:
    n, q = map(int, input().split())
    if n == 0:
        break
    count = [0] * 101
    for i in range(n):
        dates = list(map(int, input().split()))
        for d in range(1, len(dates)):
            count[dates[d]] += 1
    ind = 0
    max_ = 0
    for i in range(101):
        if max_ < count[i]:
            ind = i
            max_ = count[i]
    if max_ < q:
        print(0)
    else:
        print(ind)

Submission status: Accepted

Solution code:
while True:
  N,Q = map(int,input().split())
  if N+Q==0:
    break
  date = [0 for i in range(1000)]
  for i in range(N):
    M = list(map(int,input().split()))
    for i in M[1:]:
      date[i]+=1
  a = max(date)
  if a>=N:
    for i in range(1000):
      if N==date[i]:
        print(i)
        break
  elif N>a>=Q:
    for i in range(1000):
      if a==date[i]:
        print(i)
        break
  else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    while True:
        n,q = map(int,input().split())
        if not n and not q:
            return
        res = [0 for _ in range(1000)]
        for _ in range(n):
            for m in list(map(int,input().split()))[1::]:
                res[m] += 1
        ans = max(res)
        if ans < q:
            print(0)
        else:
            print(res.index(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while True:
    n, q = map(int, input().split())
    if n == 0: break

    c_dates = []

    for i in range(n):
        data = input().split()
        del data[0]
        for j in range(len(data)):
            data[j] = int(data[j])
        c_dates = c_dates + data
        
    c_dates.sort()
    #print(c_dates)
    #print("データの個数" + str(len(c_dates)))

    c_day = 0
    c_num = 1
    max_num = 0
    #print(str(q) + "人以上")

    if len(c_dates) == 1 and q == 1:
        print(c_dates[0])
        continue
    
    for i in range(len(c_dates) - 1):
        if c_dates[i] == c_dates[i + 1] and i != len(c_dates) - 1:
            c_num += 1
            if i != len(c_dates) - 2: continue
        if c_num >= q and c_num > max_num:
            c_day = c_dates[i]
            #print("c_day " + str(c_day))
            #print("c_num " + str(c_num))
            max_num = c_num
            c_num = 1
        else:
            c_num = 1

    print(c_day)
    #print("")

Submission status: Accepted

Solution code:
# coding: utf-8
while 1:
    date=[[0,i] for i in range(101)]
    n,q=map(int,input().split())
    if n==0:
        break
    for i in range(n):
        t = list(map(int,input().split()))
        for num in t[1:]:
            date[num][0]+=1
    ans = sorted(date,key=lambda x:(-x[0],x[1]))[0]
    print(ans[1] if ans[0]>=q else 0)

Submission status: Runtime Error

Solution code:
import collections

while True:
    N, Q = map(int, input().split())
    if N == 0 and Q == 0:
        break
    D = []
    for _ in range(N):
        i = list(map(int, input().split()))
        del i[0]
        [D.append(ii) for ii in i]
    c = collections.Counter(D)
    cc = c.most_common()
    if cc[0][1] >= Q:
        print(cc[0][0])
    else:
        print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
while 1:
    N,Q=map(int,input().split())
    if N==0: break
    M,l=[list(map(int,input().split())) for _ in range(N)],[]
    for mm in M:
        if len(mm)!=1:
            for i in range(1,len(mm)):
                l.append(mm[i])
    c=Counter(l)
    _,mv=c.most_common(1)[0]
    print(min([k for k,v in c.most_common() if mv==v]) if mv>=Q else 0)

Submission status: Runtime Error

Solution code:
from collections import Counter
while 1:
    N,Q=map(int,input().split())
    if (N,Q)==(0,0): break
    M,l=[list(map(int,input().split())) for _ in range(N)],[]
    for mm in M:
        if len(mm)!=1:
            for i in range(1,len(mm)):
                l.append(mm[i])
    c=Counter(l)
    _,mv=c.most_common(1)[0]
    print(min([k for k,v in c.most_common() if mv==v]) if mv>=Q else 0)

Submission status: Runtime Error

Solution code:
from collections import Counter
while 1:
    N,Q=map(int,input().split())
    if (N,Q)==(0,0): break
    M,l=[list(map(int,input().split())) for _ in range(N)],[]
    for mm in M:
        if len(mm)!=1:
            for i in range(1,len(mm)):
                l.append(mm[i])
    c=Counter(l)
    _,mv=c.most_common(1)[0]
    print(str(min([k for k,v in c.most_common() if mv==v])) if mv>=Q else '0')

Submission status: Runtime Error

Solution code:
while True:
    N, Q = map(int, raw_input().split())

    if N == 0 and Q == 0:
        break

    t = [map(int, raw_input().split())[1:] for _ in range(N)]
    table = [[i, 0] for i in range(10)]

    for i in t:
        for j in i:
            table[j][1] += 1

    table.sort(reverse=True, key=lambda x: x[1])

    print table[0][0] if table[0][1] >= Q else 0

Submission status: Runtime Error

Solution code:
import sys
import collections

while True:
    N, Q = map(int, sys.stdin.readline().split())
    if N == 0:
        break
    counter = collections.Counter()
    for i in xrange(N):
        date = map(int, sys.stdin.readline().split())
        if date[0] != 0:
            counter.update(date[1:])
    
    result = counter.most_common()
    largest = result[0][1]
    
    ret = -1
    if largest < Q:
        print 0
    else:
        smallest = 100
        for n, c in result:
            if c < largest:
                break
            if n < smallest:
                smallest = n
        print smallest

Submission status: Runtime Error

Solution code:
while True:
    N,Q=map(int,raw_input().split())
    if N==Q==0:break
    T=[0]*51
    for i in range(N):
        L=map(int,raw_input().split())
        for j in L[1:]:
            T[j]+=1
    m=max(T)
    print 0 if m<Q else T.index(m)