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: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

(N, Q) = map(int, raw_input().split())
while N!=0 and Q!=0:
    H=[0]*101
    for i in range(N):
        q = map(int, raw_input().split())
        for j in range(len(q)):
            H[q[j]] += 1
    if Q <= max(H):
        print H.index(max(H))
    else:
        print 0

    (N, Q) = map(int, raw_input().split())

Submission status: Wrong Answer

Solution code:
while True:
    n, q = map(int, input().split())
    if n == 0: break
    ls = []
    for i in range(n):
        ls.append(list(map(int, input().split())))

    for i in range(1, 101):
        count = 0
        for j in range(len(ls)):
            if i in ls[j][1:]:
                count += 1
                if count == q:
                    break
        else: continue
        print(i)
        break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

while True:
    amount, require = map(int, input().split())
    if amount == require == 0: break

    dates = []

    for _ in range(amount):
        date = list(map(int, input().split()))
        if not date.pop(0) == 0:
            # print("Appending date ... {0}".format(date))
            dates.append(date)
        else:
            dates.append([0])

    # print("date list: {0}".format(dates))
    max_d = 0
    for date in dates:
        if max(date) >= max_d:
            max_d = max(date)

    meet_count = 0
    can_meet = False
    x_day = 0
    for day in range(1, max_d):
        meet_count = 0
        for date in dates:
            # print("Investing date: {0}".format(date))
            if day in date:
                # print("day {0} is in date {1}.".format(day, date))
                meet_count += 1

        if meet_count >= require:
            # print("{0} people can meet in the day {1}.".format(meet_count, day))
            if day > x_day:
                x_day = day
            can_meet = True

    if can_meet:
        print(x_day)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

while True:
    amount, require = map(int, input().split())
    if amount == require == 0: break

    dates = []

    for _ in range(amount):
        date = list(map(int, input().split()))
        if not date.pop(0) == 0:
            # print("Appending date ... {0}".format(date))
            dates.append(date)
        else:
            dates.append([0])

    # print("date list: {0}".format(dates))
    max_d = 0
    for date in dates:
        if max(date) >= max_d:
            max_d = max(date)

    meet_count = 0
    can_meet = False
    x_day = 0
    for day in range(1, max_d):
        temp = 0
        for date in dates:
            # print("Investing date: {0}".format(date))
            if day in date:
                # print("day {0} is in date {1}.".format(day, date))
                temp += 1

            # print("{0} people can meet in the day {1}.".format(temp, day))
        if temp >= require:
            # print("temp:{0}, meet_count:{1}, require:{2}".format(temp, meet_count, require))
            if temp >= meet_count:
                x_day = day
                meet_count = temp
        can_meet = True

    if can_meet:
        print(x_day)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

while True:
    amount, require = map(int, input().split())
    if amount == require == 0: break

    dates = []

    for _ in range(amount):
        date = list(map(int, input().split()))
        if not date.pop(0) == 0:
            # print("Appending date ... {0}".format(date))
            dates.append(date)
        else:
            dates.append([0])

    # print("date list: {0}".format(dates))
    max_d = 0
    for date in dates:
        if max(date) >= max_d:
            max_d = max(date)

    meet_count = 0
    can_meet = False
    x_day = 0
    for day in range(1, max_d):
        temp = 0
        for date in dates:
            # print("Investing date: {0}".format(date))
            if day in date:
                # print("day {0} is in date {1}.".format(day, date))
                temp += 1

            # print("{0} people can meet in the day {1}.".format(temp, day))
        if temp >= require:
            # print("temp:{0}, meet_count:{1}, require:{2}".format(temp, meet_count, require))
            if temp >= meet_count:
                x_day = day
                meet_count = temp
                can_meet = True

    if can_meet:
        print(x_day)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:

while True:
	n, q = map(int, input().split())
	if (n, q) == (0, 0):
		break
	r = None
	for i in range(n):
		d = list(map(int, input().split()))
		if len(d) > 1:
			if r is None:
				r = set(d[1:])
			else:
				r &= set(d[1:])
	if not r:
		print(0)
	else:
		print(min(r))

Submission status: Wrong Answer

Solution code:
from collections import Counter

while True:
	n, q = map(int, input().split())
	if (n, q) == (0, 0):
		break
	r = []
	for i in range(n):
		d = list(map(int, input().split()))
		if len(d) > 1:
			r += d[1:]
	r = Counter(r).most_common()
	if len(r) > 0:
		print(r[0][0])
	else:
		print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

while True:
	n, q = map(int, input().split())
	if (n, q) == (0, 0):
		break
	r = []
	for i in range(n):
		d = list(map(int, input().split()))
		if len(d) > 1:
			r += d[1:]
	r = Counter(r).most_common()
	if len(r) > 0 and r[0][0] >= q:
		print(r[0][0])
	else:
		print(0)

Submission status: Wrong Answer

Solution code:
cond = [int(n) for n in input().split(" ")]
while True:
    answer = [101,0]
    case = []
    sets = set()
    for c in range(cond[0]):
        case.append([int(n) for n in input().split(" ")[1:]])
        sets = sets | {n for n in case[-1]} 
        #print(sets,case)
    else:
        for num in sets:
            disp = [num,0]
            for c in case:
                if num in c:
                    disp[1] += 1
            else:
                #print(disp,answer,cond)
                if (disp[1] >= cond[1] and disp[1] > answer[1] ) or (disp[1] == answer[1] and disp[0] < answer[0]):
                    answer = disp
        else:
            print(answer[0])
            cond = [int(n) for n in input().split(" ")]
            if cond == [0,0]:
                break

Submission status: Wrong Answer

Solution code:
while 1:
    n, q = map(int, raw_input().split())
    if n==0:
        break
    d = [0]*101
    for i in xrange(n):
        D = map(int, raw_input().split())
        for j in xrange(D[0]):
            d[D[j+1]] += 1
    print d.index(max(d))

Submission status: Wrong Answer

Solution code:
import collections

while True:
    max_value = 0
    max_key = 0
    list2 = []
    di = collections.defaultdict(int)
    num_data,num_success = map(int,raw_input().split())
    if (num_data == 0 and num_success == 0):
        break
    for i in xrange(num_data):
        str = raw_input()
        word_list = str.split()
        if word_list[0] != "0":
            del(word_list[0])
            list2.append(word_list)
    for num in xrange(len(list2)):
        for num2 in range(num+1,len(list2)):
            new_list = list(set(list2[num2])&set(list2[num]))
            if new_list != []:
                for ch in new_list:
                    di[ch] += 1
    for key in di.keys():
        if (int(di[key]) > max_value) and (int(di[key]) >= num_success-1):
            max_value = int(di[key])
            max_key = key
        elif (int(di[key]) == max_value) and (int(di[key]) >= num_success-1):
            if key < max_key:
                max_key = key
        else:
            pass
    print max_key

Submission status: Wrong Answer

Solution code:
import collections
while True:
    max_value = 0
    max_key = 0
    list2 = []
    di = collections.defaultdict(int)
    num_data,num_success = map(int,raw_input().split())
    if (num_data == 0 and num_success == 0):
        break
    for i in xrange(num_data):
        str = raw_input()
        word_list = str.split()
        if word_list[0] != "0":
            del(word_list[0])
            list2.append(word_list)
    for num in xrange(len(list2)):
        for num2 in range(num+1,len(list2)):
            new_list = list(set(list2[num2])&set(list2[num]))
            if new_list != []:
                for ch in new_list:
                    di[ch] += 1
    if di != {}:
        for key in di.keys():
            if (int(di[key]) > max_value) and (int(di[key]) >= num_success-1):
                max_value = int(di[key])
                max_key = key
            elif (int(di[key]) == max_value) and (int(di[key]) >= num_success-1):
                if key <= max_key:
                    max_key = key
            else:
                pass
    else:
        if list2 != []:
            max_key = min(list2)[0]
    print max_key

Submission status: Wrong Answer

Solution code:
import collections

while True:
    max_value = 1
    num_people,num_border = map(int,raw_input().split())
    if (num_people == 0) and (num_border == 0):
        break
    list2 = []
    for i in range(num_people):
        line = raw_input()
        list1 = line.split()
        if list1[0] != "0":
            del list1[0]
            list2.extend(list1)
    counter = collections.Counter(list2)
    for key,value in sorted(zip(counter.keys(),counter.values()),key= lambda x:x[1],reverse= True):
        if value >= num_border:
            print key
            break
        else:
            print "0"
            break

Submission status: Wrong Answer

Solution code:
import collections
from operator import itemgetter

while True:
    max_value = 1
    num_people,num_border = map(int,raw_input().split())
    if (num_people == 0) and (num_border == 0):
        break
    list2 = []
    for i in range(num_people):
        line = raw_input()
        list1 = line.split()
        [int(s) for s in list1]
        if list1[0] != 0:
            del list1[0]
            list2.extend(list1)
    counter = collections.Counter(list2)
    print counter
    if counter == {}:
        print "0"
    s = sorted(counter.items(), key=itemgetter(0))
    for key,value in sorted(s,key= itemgetter(1),reverse = True):
        print key,value
        if value >= num_border:
            print key
            break
        else:
            print "0"
            break

Submission status: Wrong Answer

Solution code:
import collections
from operator import itemgetter

while True:
    max_value = 1
    num_people,num_border = map(int,raw_input().split())
    if (num_people == 0) and (num_border == 0):
        break
    list2 = []
    for i in range(num_people):
        line = raw_input()
        list1 = line.split()
        [int(s) for s in list1]
        if list1[0] != 0:
            del list1[0]
            list2.extend(list1)
    counter = collections.Counter(list2)
    if counter == {}:
        print "0"
    s = sorted(counter.items(), key=itemgetter(0))
    for key,value in sorted(s,key= itemgetter(1),reverse = True):
        if value >= num_border:
            print key
            break
        else:
            print "0"
            break

Submission status: Wrong Answer

Solution code:
#coding: utf-8
while True:
    pnum,least = map(int,raw_input().split())
    if(pnum == 0 and least == 0):
        break
    l = [0 for i in xrange(100)]
    for i in xrange(pnum):
        temp_li = []
        schedule = raw_input()
        schedule = schedule[2:]
        for j in schedule:
            if(j != " "):
                l[int(j)] += 1
    ma = 0
    count = 0
    li = []
    for i in l:
        if(i>ma):
            ma = i
    if (ma < least):
        print 0
    else:
        for i in l:
            if ma == i:
                print count
                break
            count +=1

Submission status: Wrong Answer

Solution code:
#coding: utf-8
while True:
    pnum,least = map(int,raw_input().split())
    if(pnum == 0 and least == 0):
        break
    l = [0 for i in xrange(100)]
    for i in xrange(pnum):
        temp_li = []
        schedule = raw_input()
        schedule = schedule[2:]
        for j in schedule:
            if(j != " "):
                l[int(j)] += 1
    ma = 0
    count = 0
    for i in l:
        if(i>ma):
            ma = i
    if (ma < least):
        print 0
    else:
        for i in l:
            if ma == i:
                print count
                break
            count +=1

Submission status: Wrong Answer

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

    data = [list(map(int, input().split())) for i in range(n)]
    for li in data:
        if li[0] > 0:
            del(li[0])

    q -= 1
    day = 0
    for d in range(100):
        cnt = 0
        for li in data:
            if d in li:
                cnt += 1
        if cnt > q:
            q = cnt
            day = d

    print(day)

Submission status: Wrong Answer

Solution code:

while 1:
  day = [0] * 100
  n, q = map(int, raw_input().split())
  if not n:
    break
  for i in range(n):
    data = map(int, raw_input().split())
    for j in range(1, len(data)):
      day[data[j] - 1] += 1
  b = False
  for v in range(101, q - 1, -1):
    for i in range(0, len(day)):
      if day[i] == v:
        print i + 1
        b = True
        break
      if b:
        break
  if not b:
    print 0

Submission status: Accepted

Solution code:
# AOJ 1124: When Can We Meet?
# Python3 2018.7.14 bal4u

while True:
	n, q = map(int, input().split())
	if n == 0: break
	f, ma = [0]*120, 0
	for i in range(n):
		ds = list(map(int, input().split()))
		for d in ds[1:]:
			f[d] += 1
			ma = max(ma, d)
	ans = 0
	for i in range(1, ma+1):
		if f[i] >= q and f[i] > f[ans]: ans = i
	print(ans)

Submission status: Accepted

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]
    if not len(D) == 0:
        c = collections.Counter(D)
        cc = c.most_common()
        # print(cc)
        if cc[0][1] >= Q:
            ans = 1000000
            tmp = cc[0][1]
            for i in range(len(cc)):
                if cc[i][1] == tmp:
                    ans = min(cc[i][0], ans)
            print(ans)
        else:
            print(0)
    else:
        print(0)

Submission status: Accepted

Solution code:
while True:
    (N, Q) = [int(x) for x in input().split()]
    if N==0 and Q==0:
        exit()
    Date = [0]*100
    meeting_day = 0
    member_num = 0
    for i in range(N):
        M = [int(x) for x in input().split()]
        for j in range(1, M[0]+1):
            Date[M[j]-1] += 1
    for i in range(100):
        if Date[i] >= Q and Date[i]>member_num:
            meeting_day = i+1
            member_num = Date[i]
    print(meeting_day)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n, q = map(int, raw_input().split())
            if n == 0 and q == 0:
                break
            c = Counter()
            for i in range(n):
                line = map(int, raw_input().split())
                m = line[0]
                for j in range(1, m+1):
                    c[line[j]] += 1
            # print c
            max_key = None
            max_value = -1
            for k, v in c.items():
                if v > max_value or (v == max_value and k < max_key):
                    max_key = k
                    max_value = v
            if max_value >= q:
                print max_key
            else:
                print 0
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,Q = map(int,input().split(" "))
    if N == 0 and Q == 0:
        break
    dateList = [0 for i in range(101)]
    for i in range(N):
        date = list(map(int,input().split()))
        for d in date[1:]:
            dateList[d] += 1
    max_participant = max(dateList)
    if max_participant < Q:
        print(0)
    else:
        for i in range(101):
            if max_participant == dateList[i]:
                print(i)
                break

Submission status: Accepted

Solution code:
while 1:
	n, q = map(int, raw_input().split(" "))
	if (n, q) == (0,0):
		break
	date_total = [0 for i in range(100)]
	for i in range(n):
		date = map(int, raw_input().split(" "))
		for j in range(1,date[0]+1):
			date_total[date[j]] += 1
	best = max(date_total)
	if best < q:
		print 0
	else :
		print date_total.index(best)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

(N, Q) = map(int, raw_input().split())
while N!=0 and Q!=0:
    H=[0]*101
    for i in range(N):
        q = map(int, raw_input().split())
        for j in range(1, len(q)):
            H[q[j]] += 1
    if Q <= max(H):
        print H.index(max(H))
    else:
        print 0

    (N, Q) = map(int, raw_input().split())

Submission status: Accepted

Solution code:
while True:
    n, q = map(int, input().split())
    if n == 0: break
    ls = []
    for i in range(n):
        ls.append(list(map(int, input().split())))

    max_q = 0
    date = 0
    for i in range(1, 101):
        count = 0
        for j in range(len(ls)):
            if i in ls[j][1:]:
                count += 1
                if count > max_q:
                    max_q = count
                    date = i
    if max_q < q:
        print(0)
    else:
        print(date)

Submission status: Accepted

Solution code:
while True:
    N, Q = map(int, raw_input().split())
    if (N, Q) == (0, 0):
        break
    count = [Q-1] + [0] * 100
    for _ in xrange(N):
        for d in map(int, raw_input().split())[1:]:
            count[d] += 1
    print count.index(max(count))

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

# f = open("1124_input.txt")

while True:
    amount, require = map(int, input().split())
    if amount == require == 0: break

    dates = []

    for _ in range(amount):
        date = list(map(int, input().split()))
        if not date.pop(0) == 0:
            # print("Appending date ... {0}".format(date))
            dates.append(date)
        else:
            dates.append([0])

    # print("date list: {0}".format(dates))
    max_d = 0
    for date in dates:
        if max(date) >= max_d:
            max_d = max(date)

    meet_count = 0
    can_meet = False
    x_day = 0
    for day in range(1, max_d+1):
        temp = 0
        for date in dates:
            # print("Investing date: {0}".format(date))
            if day in date:
                # print("day {0} is in date {1}.".format(day, date))
                temp += 1

            # print("{0} people can meet in the day {1}.".format(temp, day))
        if temp >= require:
            # print("temp:{0}, meet_count:{1}, require:{2}".format(temp, meet_count, require))
            if temp > meet_count:
                # print("temp {0} > meet_count {1}".format(temp, meet_count))
                x_day = day
                meet_count = temp
                can_meet = True

    if can_meet:
        print(x_day)
    else:
        print(0)

# f.close()

Submission status: Accepted

Solution code:
from collections import Counter

while True:
	n, q = map(int, input().split())
	if (n, q) == (0, 0):
		break
	r = []
	for i in range(n):
		d = list(map(int, input().split()))
		if len(d) > 1:
			r += d[1:]
	r = Counter(r).most_common()
	if len(r) > 0 and r[0][1] >= q:
		print(r[0][0])
	else:
		print(0)

Submission status: Accepted

Solution code:
while True:
    n, q = map(int, raw_input().split())

    if n == 0:
        break

    m = {}

    for _ in range(n):
        d = map(int, raw_input().split())
        for i in range(1, len(d)):
            if d[i] in m:
                m[d[i]] += 1
            else:
                m[d[i]] = 1

    maxk = 0
    maxv = 0
    for k, v in m.items():
        if v >= q and maxv < v:
            maxk = k
            maxv = v

    print maxk

Submission status: Accepted

Solution code:
cond = [int(n) for n in input().split(" ")]
while True:
    answer = [101,0]
    case = []
    sets = set()
    for c in range(cond[0]):
        case.append([int(n) for n in input().split(" ")[1:]])
        sets = sets | {n for n in case[-1]} 
        #print(sets,case)
    else:
        for num in sets:
            disp = [num,0]
            for c in case:
                if num in c:
                    disp[1] += 1
            else:
                #print(disp,answer,cond)
                if (disp[1] >= cond[1] and disp[1] > answer[1] ) or (disp[1] == answer[1] and disp[0] < answer[0]):
                    answer = disp
        else:
            if answer[0] == 101:
                print(0)
            else:
                print(answer[0])
            cond = [int(n) for n in input().split(" ")]
            if cond == [0,0]:
                break

Submission status: Accepted

Solution code:
while True:
  N,Q = map(int, raw_input().split())
  if N==Q==0: break
  schedule = [0] * 101
  for _ in xrange(N):
    ipt = map(int, raw_input().split())
    for i in xrange(1, ipt[0]+1):
      schedule[ipt[i]] += 1
  bestday = 0
  bestnum = 0
  for i in xrange(1, 101):
    if bestnum < schedule[i]:
      bestday = i
      bestnum = schedule[i]
  if bestnum < Q:
    bestday = 0
  print bestday

Submission status: Accepted

Solution code:
while 1:
    n, q = map(int, raw_input().split())
    if n==0:
        break
    d = [0]*101
    for i in xrange(n):
        D = map(int, raw_input().split())
        for j in xrange(D[0]):
            d[D[j+1]] += 1

    v = max(d)
    if v < q:
        print 0
    else:
        print d.index(v)

Submission status: Accepted

Solution code:
import collections
from operator import itemgetter

while True:
    max_value = 1
    num_people,num_border = map(int,raw_input().split())
    if (num_people == 0) and (num_border == 0):
        break
    list2 = []
    for i in range(num_people):
        line = raw_input()
        list1 = line.split()
        list1 = [int(s) for s in list1]
        if list1[0] != "0":
            del list1[0]
            list2.extend(list1)
    counter = collections.Counter(list2)
    if counter == {}:
        print "0"
    s = sorted(counter.items(), key=itemgetter(0))
    for key,value in sorted(s,key= itemgetter(1),reverse = True):
        if value >= num_border:
            print key
            break
        else:
            print "0"
            break

Submission status: Accepted

Solution code:

while True:
    tmp = input().split(' ')
    n = int(tmp[0])
    q = int(tmp[1])
    if n == 0 and q == 0:
        break
    a = []
    d = [0]*100
    for i in range(n):
        a = input().split(' ')
        for j in range(int(a[0])):
            qq = int(a[ j+1 ])
            d[qq] = d[qq] + 1
    mx = max(d)
    if mx < q:
        print(0)
    else:
        for i in range(len(d)):
            if mx == d[i]:
                print( i )
                break

Submission status: Accepted

Solution code:
from collections import Counter
while True:
    N,Q = map(int,input().split())
    if N == 0: break
    ctr = Counter()
    for i in range(N):
        src = list(map(int,input().split()))
        ctr.update(src[1:])
    ans_n = 0
    ans_d = -1
    for d,n in sorted(ctr.items()):
        if n > ans_n:
            ans_n = n
            ans_d = d
    if ans_n >= Q:
        print(ans_d)
    else:
        print(0)

Submission status: Accepted

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(101)]

    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: Accepted

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

    data = [list(map(int, input().split())) for i in range(n)]
    for li in data:
        if li[0] > 0:
            del(li[0])

    q -= 1
    day = 0
    for d in range(1,100):
        cnt = 0
        for li in data:
            if d in li:
                cnt += 1
        if cnt > q:
            q = cnt
            day = d

    print(day)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
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 pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,q = LI()
        if n == 0:
            break
        a = [LI() for _ in range(n)]
        d = collections.defaultdict(int)
        for c in a:
            for cc in c[1:]:
                d[cc] += 1
        t = sorted([[-v,k] for k,v in d.items() if v >= q])
        if len(t) == 0:
            rr.append(0)
        else:
            rr.append(t[0][1])

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
while 1:
    n,q = map(int, raw_input().split())
    if n == 0 and q == 0: break
    dates = [0 for i in xrange(100)]
    for i in xrange(n):
        cDate = map(int, raw_input().split())
        if cDate[0] != 0:
            for j in xrange(cDate[0]):
                dates[cDate[j+1]] += 1
    nom = max(dates)
    if nom >= q:
        for i in xrange(len(dates)):
            if dates[i] == nom:
                print i
                break
    else:
        print 0

Submission status: Accepted

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:])
    
    if len(counter) == 0:
        print 0
        continue
    
    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: Accepted

Solution code:
while True:
	n, q = map(int, raw_input().split())
	if n == q == 0: break
	counts = [0] * 101
	maxd = 0
	for i in xrange(n):
		data = map(int, raw_input().split()[1:])
		for d in data:
			counts[d] += 1
			maxd = max(maxd, counts[d])
	if q <= maxd:
		print counts.index(maxd)
	else:
		print 0

Submission status: Accepted

Solution code:
while True:
    N,Q=map(int,raw_input().split())
    if N==Q==0:break
    T=[0]*101
    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)

Submission status: Accepted

Solution code:

while 1:
  day = [0] * 100
  n, q = map(int, raw_input().split())
  if not n:
    break
  for i in range(n):
    data = map(int, raw_input().split())
    for j in range(1, len(data)):
      day[data[j] - 1] += 1
  m = max(day) 
  if m >= q:
    for i in range(0, len(day)):
      if day[i] == m:
        print i + 1
        break
  else:
    print 0

Submission status: Accepted

Solution code:
while 1:
	N,Q = map(int,raw_input().split())
	if N == 0: break
	C = [0]*100
	for _ in range(N):
		D = map(int,raw_input().split())
		for i in D[1:]:
			C[i] += 1
	print C.index(max(C)) if max(C) >= Q else 0

Submission status: Accepted

Solution code:
while True:
    N, Q = map(int, input().split())
    if N == 0 and Q == 0:
        break
    counts = [0 for i in range(100)]
    for i in range(N):
        tmp = list(map(int, input().split()))
        M = tmp[0]
        for i in range(M):
            counts[tmp[i + 1] - 1] += 1
            
    max_count = max(counts)
    if max_count < Q:
        print(0)
    else:
        for i in range(100):
            if counts[i] == max_count:
                print(i + 1)
                break