There are a number of people who will be attending ACM-ICPC World Finals. Each of them may be well versed in a number of topics. Given a list of topics known by each attendee, presented as binary strings, determine the maximum number of topics a 2-person team can know. Each subject has a column in the binary string, and a '1' means the subject is known while '0' means it is not.  Also determine the number of teams that know the maximum number of topics.  Return an integer array with two elements.  The first is the maximum number of topics known, and the second is the number of teams that know that number of topics.  

Example  

$n=3$ 

$to pics=[\text{'}10101\text{'},\text{'}11110\text{'},\text{'}00010\text{'}]$  

The attendee data is aligned for clarity below:

10101
11110
00010

These are all possible teams that can be formed:

Members Subjects
(1,2)   [1,2,3,4,5]
(1,3)   [1,3,4,5]
(2,3)   [1,2,3,4]

In this case, the first team will know all 5 subjects.  They are the only team that can be created that knows that many subjects, so $[5,1]$ is returned.

Function Description  

Complete the acmTeam function in the editor below. 

acmTeam has the following parameter(s):  

string topic: a string of binary digits  

Returns  

int[2]:  the maximum topics and the number of teams that know that many topics   

Input Format

The first line contains two space-separated integers $n$ and $m$, where $n$ is the number of attendees and $m$ is the number of topics.  

Each of the next $n$ lines contains a binary string of length $m$.  

Constraints

$2\leq n\leq500$ 

$1\leq m\leq500$ 

Sample Input
4 5
10101
11100
11010
00101

Sample Output
5
2

Explanation

Calculating topics known for all permutations of 2 attendees we get:  

$(1,2)\rightarrow4$ 

$(1,3)\rightarrow5$ 

$(1,4)\rightarrow3$ 

$(2,3)\rightarrow4$ 

$(2,4)\rightarrow4$ 

$(3,4)\rightarrow5$  

The 2 teams (1, 3) and (3, 4) know all 5 topics which is maximal.

Difficulty: EASY

Solutions:
def gp():
	d = [int(v) for v in input()]
	c = len([v for v in d if v == 1])
	return (c, d)

def merge(p1, p2):
	count = 0
	for i in range(len(p1)):
		if p1[i] == 1 or p2[i] == 1:
			count += 1
	return count
(N, M) = [int(v) for v in input().split()]
p = [gp() for Ni in range(N)]
p.sort(reverse=True)
mxcount = 0
mxteams = 0
for pi in range(len(p)):
	p1 = p[pi]
	for pj in range(pi + 1, len(p)):
		p2 = p[pj]
		if p1[0] + p2[0] < mxcount:
			continue
		count = merge(p1[1], p2[1])
		if count > mxcount:
			mxcount = count
			mxteams = 1
		elif count == mxcount:
			mxteams += 1
print(mxcount)
print(mxteams)


def add(p1, p2):
	return sum((i or j for (i, j) in zip(p1, p2)))
(N, M) = (int(i) for i in input().split())
persons = []
for i in range(N):
	persons.append([int(i) for i in list(input())])
totals = []
for i in range(N - 1):
	for j in range(i + 1, N):
		totals.append(add(persons[i], persons[j]))
highest = max(totals)
print(highest)
print(totals.count(highest))


from itertools import combinations

def find_best_topic_duo(people):
	results = {'max': 0, 'num': 0}
	for duo in combinations(people, 2):
		topics_known = bin(int(duo[0], 2) | int(duo[1], 2)).count('1')
		if topics_known > results['max']:
			results['num'] = 1
			results['max'] = topics_known
		elif topics_known == results['max']:
			results['num'] += 1
	return [results['max'], results['num']]
not_needed = int(input().split(' ')[0])
peoples = []
for _ in range(not_needed):
	peoples.append(input())
for answer in find_best_topic_duo(peoples):
	print(answer)


cases = []
for _ in range([int(x) for x in input().split(' ')][0]):
	cases += [int(input(), 2)]
max_result = 0
max_result_count = 0
for i in range(1, len(cases)):
	for k in range(i):
		s = bin(cases[i] | cases[k]).count('1')
		if s > max_result:
			max_result = s
			max_result_count = 1
		elif s == max_result:
			max_result_count += 1
print(max_result)
print(max_result_count)


constraints = list(map(int, input().split()))
skillset = []
for i in range(0, constraints[0]):
	skillset.append(input())
highestval = 0
teams = 0
for i in range(0, constraints[0] - 1):
	for j in range(i + 1, constraints[0]):
		val1 = int(skillset[i], 2)
		val2 = int(skillset[j], 2)
		testval = val1 | val2
		if bin(testval).count('1') > highestval:
			highestval = bin(testval).count('1')
			teams = 1
		elif bin(testval).count('1') == highestval:
			teams += 1
		else:
			pass
print(highestval)
print(teams)


(n, m) = map(int, input().split())
lt = [0 for i in range(n)]
for i in range(n):
	a = input()
	lt[i] = int(a, base=2)
c = 0
max = bin(lt[0] | lt[1]).count('1')
for i in range(n - 1):
	j = i + 1
	while j < n:
		k = bin(lt[i] | lt[j]).count('1')
		if k > max:
			max = k
			c = 1
		elif k == max:
			c = c + 1
		j = j + 1
print(max)
print(c)


import sys

def getCombinedKnowledge(binary1, binary2):
	nbr1 = int(binary1)
	nbr2 = int(binary2)
	combined = nbr1 + nbr2
	re_string = str(combined)
	known_subjects = 0
	for c in re_string:
		if c != '0':
			known_subjects += 1
	return known_subjects
(N, M) = [int(nbr) for nbr in sys.stdin.readline().split()]
lines = sys.stdin.read().split()
best_knowledge = 0
number_best_knowledge = 0
for outer_pos in range(len(lines)):
	binary1 = lines[outer_pos]
	for inner_pos in range(outer_pos + 1, len(lines)):
		binary2 = lines[inner_pos]
		comb_knowledge = getCombinedKnowledge(binary1, binary2)
		if comb_knowledge > best_knowledge:
			best_knowledge = comb_knowledge
			number_best_knowledge = 1
		elif comb_knowledge == best_knowledge:
			number_best_knowledge += 1
print(best_knowledge)
print(number_best_knowledge)


memo = [0] * 2 ** 16
for i in range(len(memo)):
	memo[i] = (i & 1) + memo[i >> 1]

def popcount(x):
	return memo[x & 65535] + memo[x >> 16 & 65535]

def string_to_bitset(s):
	return [int(s[i:i + 31], 2) for i in range(0, len(s), 31)]
(n, m) = map(int, input().split())
a = [string_to_bitset(input()) for _ in range(n)]
(ans, cnt) = (-1, 0)
for i in range(n):
	for j in range(i + 1, n):
		cur = 0
		for (c1, c2) in zip(a[i], a[j]):
			cur += popcount(c1 | c2)
		if cur > ans:
			(ans, cnt) = (cur, 1)
		elif cur == ans:
			cnt += 1
print(ans)
print(cnt)


def calc(k1, k2):
	c = 0
	for (i, j) in zip(k1, k2):
		if i == '1' or j == '1':
			c += 1
	return c

def main():
	(N, M) = [int(x) for x in input().split()]
	know = []
	for _ in range(N):
		know.append(input())
	teams = {}
	for (i, k1) in enumerate(know):
		for (j, k2) in enumerate(know):
			if (j, i) not in teams:
				teams[i, j] = calc(k1, k2)
	m = max(teams.values())
	print(m)
	count = 0
	for (k, v) in teams.items():
		if v == m:
			count += 1
	print(count)
main()


def count(n):
	res = 0
	while n:
		n = n & n - 1
		res = res + 1
	return res
(n, m) = input().split()
k = []
max = 0
for i in range(int(n)):
	o = int(input(), 2)
	k.append(o)
	for j in range(i):
		c = count(k[j] | o)
		if c > max:
			maxcount = 1
			max = c
		elif c == max:
			maxcount += 1
print(max)
print(maxcount)


import sys
(N, M) = list(map(int, sys.stdin.readline().split()))
T = [int(sys.stdin.readline(), 2) for _ in range(N)]
(max_topics, num_teams) = (0, 0)
for i in range(len(T) - 1):
	for j in range(i + 1, len(T)):
		topics = bin(T[i] | T[j]).count('1')
		if topics == max_topics:
			num_teams += 1
		if topics > max_topics:
			max_topics = topics
			num_teams = 1
print(max_topics)
print(num_teams)


(N, M) = (int(i) for i in input().split())
TEAM = []

def solve(T):
	if len(T) == 2:
		return (len(T[0].union(T[1])), 1)
	(best, count) = solve(T[1:])
	mA = T[0]
	for mB in T[1:]:
		t = len(mA.union(mB))
		if t == best:
			count += 1
		elif t > best:
			best = t
			count = 1
	return (best, count)
for _ in range(N):
	known = set()
	for (i, b) in enumerate(input().strip()):
		if int(b):
			known.add(i)
	TEAM.append(known)
print(*solve(TEAM), sep='\n')


(P, T) = [int(x) for x in input().split()]
team = []
topics = [0] * (T + 1)
for i in range(P):
	team.append(int(input(), 2))
for i in range(P - 1):
	for j in range(i + 1, P):
		topics[format(team[i] | team[j], 'b').count('1')] += 1
for i in range(T, -1, -1):
	if topics[i]:
		print(i)
		print(topics[i])
		break


import sys
info = sys.stdin.readline().split()
people = int(info[0])
skills = int(info[1])
plist = []
for i in range(people):
	plist.append(int(sys.stdin.readline(), 2))
maxm = 0
tot = 0
for i in range(people - 1):
	for j in range(i + 1, people):
		ones = bin(plist[i] | plist[j])[2:]
		count = ones.count('1')
		if count > maxm:
			maxm = count
			tot = 1
		elif count == maxm:
			tot += 1
print(maxm)
print(tot)


__author__ = 'jeffmcgraw'

def read_line():
	line_list = []
	line_string = input()
	for a in line_string.split(' '):
		b = int(a)
		line_list.append(b)
	return line_list

def get_table(n):
	raw_table = []
	for a in range(n):
		b = input()
		raw_table.append(int(b, 2))
	return raw_table

def main():
	data_run = read_line()
	n = data_run[0]
	m = data_run[1]
	high = 0
	count = 0
	data_table = get_table(n)
	for x in range(0, n):
		for y in range(0, x + 1):
			check = 0
			compare_parts = bin(data_table[x] | data_table[y])
			test_list = compare_parts[2:]
			num_topics = test_list.count('1')
			if num_topics > high and num_topics > 0:
				high = num_topics
				count = 1
			elif num_topics == high and num_topics > 0:
				count += 1
	print(high)
	print(int(count))
main()


from collections import Counter
from itertools import combinations
(N, M) = map(int, input().split())
Max = 0
Count = 0
for (i, j) in combinations([int(input(), 2) for i in range(N)], 2):
	C = Counter(bin(i | j))['1']
	if C == Max:
		Count += 1
	elif C > Max:
		Count = 1
		Max = C
print(Max)
print(Count)


(n, m) = map(int, input().split())
l = [int(input(), 2) for _ in range(n)]
(mv, mc) = (0, 0)
for (i, e) in enumerate(l):
	for j in range(i + 1, len(l)):
		nv = bin(e | l[j]).count('1')
		if nv > mv:
			(mv, mc) = (nv, 1)
		elif nv == mv:
			mc += 1
print(mv, mc, sep='\n')


def get_input():
	attendee_array = []
	(num_attendees, num_topics) = [int(i) for i in input().split()]
	for attendee in range(num_attendees):
		attendee_array.append(int(input(), 2))
	return (num_attendees, num_topics, attendee_array)

def find_two_person_teams(num_attendees, num_topics, attendee_array):
	cur_max = 0
	num_teams = 0
	for i in range(num_attendees):
		for j in range(i + 1, num_attendees):
			num_subjects = bin(attendee_array[i] | attendee_array[j]).count('1')
			if num_subjects > cur_max:
				cur_max = num_subjects
				num_teams = 1
			elif num_subjects == cur_max:
				num_teams += 1
	print(cur_max)
	print(num_teams)

def run_tests():
	(num_attendees, num_topics, attendee_array) = get_input()
	find_two_person_teams(num_attendees, num_topics, attendee_array)
run_tests()


test = str(input())
test = test.split()
test = list(map(int, test))
lst = []
for j in range(test[0]):
	topic = int(input(), 2)
	lst.append(topic)
	lst.sort()
	maxx = 0
	count = 0
	memo = {}
for i in range(len(lst)):
	for k in range(i, len(lst)):
		a = lst[i] | lst[k]
		if a in memo:
			temp = memo[a]
		else:
			newlst = list(str(bin(a)))
			temp = newlst.count('1')
			memo[a] = temp
		if temp == maxx:
			count += 1
		elif maxx < temp:
			maxx = temp
			count = 1
print(maxx)
print(count)


line = input()
line = line.split()
n = int(line[0])
m = int(line[1])
people = [input() for i in range(n)]
skills = []
max_skills = 0
for i in range(len(people)):
	j = i
	while j < n:
		first_person = people[i]
		second_person = people[j]
		skill = bin(int(first_person, 2) | int(second_person, 2))[2:].count('1')
		if skill > max_skills:
			max_skills = skill
		skills.append(str(skill))
		j += 1
print(max_skills)
print(skills.count(str(max_skills)))


(N, M) = list(map(int, input().split()))
indexes = []
for n in range(N):
	person = input()
	indexes.append(set([i for i in range(M) if person[i] == '1']))
max_inters = 0
counts = 0
for i in range(N):
	for j in range(i + 1, N):
		intersection = len(indexes[i].union(indexes[j]))
		if intersection > max_inters:
			max_inters = intersection
			counts = 1
		elif intersection == max_inters:
			counts += 1
print(max_inters)
print(counts)


POP_M1 = 4469269309980865699858008332735282042493121940197464459241187147907254676691182325600624766055634475896677286062162016951251294270648856648811216335361365
POP_M2 = 2681561585988519419914804999641169225495873164118478675544712288744352806014709395360374859633380685538006371637297210170750776562389313989286729801216819
POP_M4 = 788694584114270417622001470482696831028197989446611375160209496689515531180796880988345546950994319275884226952146238285514934283055680585084332294475535
POP_M8 = 52170458871371973150093482483291230068013096578180518979469110675960171323243373450590950576524916061050707619402669458574917831953099493954994743214335
POP_M16 = 204583791292591926691396081575382549208529011407180575518006033900266475884974090617542369930984076593222635430161375266700549045759594884514604711935
POP_M512 = (1 << 512) - 1
POP_MUL = 3121748551042830955846434448392195761173861469553377210925551749450926617608515916953419850934372115559970022585814835838873106672153732883415041

def popcount(n):
	n -= n >> 1 & POP_M1
	n = (n & POP_M2) + (n >> 2 & POP_M2)
	n = (n & POP_M4) + (n >> 4 & POP_M4)
	n = (n & POP_M8) + (n >> 8 & POP_M8)
	n = (n & POP_M16) + (n >> 16 & POP_M16)
	return (n * POP_MUL & POP_M512) >> 480
(N, M) = [int(_) for _ in input().split()]
T = [int(input(), 2) for _ in range(N)]
(Tmax, count) = (0, 0)
for a in range(N):
	for b in range(a):
		c = popcount(T[a] | T[b])
		if c > Tmax:
			Tmax = c
			count = 1
		elif c == Tmax:
			count += 1
print(Tmax)
print(count)


from itertools import combinations
[N, M] = map(int, input().split(' '))
skills = []
for i in range(N):
	skills.append(int(input(), 2))
combos = combinations(range(M - 1), 2)
teams = []
for i in combos:
	A = i[0]
	B = i[1]
	skill = skills[A] | skills[B]
	teams.append(bin(skill).count('1'))
maxskills = max(teams)
print(maxskills)
print(teams.count(maxskills))


import sys
(N, M) = list(map(int, sys.stdin.readline().split()))
T = [int(sys.stdin.readline(), 2) for _ in range(N)]
(max_topics, num_teams) = (0, 0)
for i in range(len(T) - 1):
	for j in range(i + 1, len(T)):
		topics = bin(T[i] | T[j]).count('1')
		if topics == max_topics:
			num_teams += 1
		if topics > max_topics:
			max_topics = topics
			num_teams = 1
print(max_topics)
print(num_teams)


def popcount(x):
	x -= x >> 1 & 6148914691236517205
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	return (x * 72340172838076673 & 18446744073709551615) >> 56
in_a = input().split()
n = int(in_a[0])
m = int(in_a[1])
people = []
skills = []
temp = n
while n > 0:
	people.append(int(input(), 2))
	n -= 1
n = temp
i = 0
j = 0
k = 0
max_topics = 0
teams = 0
temp = 0
while i < n - 1:
	a = people[i]
	j = i + 1
	while j < n:
		b = people[j]
		k = 0
		temp = bin(a | b).count('1')
		if temp >= max_topics:
			max_topics = temp
			skills.append(temp)
		j += 1
	i += 1
print(max_topics)
print(skills.count(max_topics))


(numParti, numTopic) = [int(i) for i in input().strip().split()]
outer = []
resultMap = {}
for i in range(0, numParti):
	outer.append([int(j) for (j, i) in list(enumerate(input().strip())) if i == '1'])
for i in range(0, numParti - 1):
	for k in range(i + 1, numParti):
		count = len(set(outer[i] + outer[k]))
		resultMap[count] = resultMap.get(count, 0) + 1
mKey = max(resultMap.keys())
print(mKey)
print(resultMap[mKey])


(N, M) = input().split()
N = int(N)
M = int(M)
people = []
for person in range(N):
	people.append(int(input(), 2))
max_knowledge = -1
learned_teams = 0
for i in range(N):
	for j in range(i + 1, N):
		knowledge = bin(people[i] | people[j]).count('1')
		if knowledge > max_knowledge:
			max_knowledge = knowledge
			learned_teams = 1
		elif knowledge == max_knowledge:
			learned_teams += 1
print(max_knowledge)
print(learned_teams)


from sys import stdin
(N, M) = tuple(map(int, stdin.readline().split()))
configs = []
for person in range(N):
	configs.append(int(stdin.readline(), 2))

def count_bits(config):
	bit_count = 0
	while 0 < config:
		bit_count += 1 & config
		config >>= 1
	return bit_count
bits_hash = {}
for i in range(2 ** 16):
	bits_hash[i] = count_bits(i)

def count_bits_by_hash(config):
	bit_count = 0
	while 0 < config:
		bit_count += bits_hash[65535 & config]
		config >>= 16
	return bit_count
bit_count_best = 0
team_count_best = 0
for person_1 in range(N):
	for person_2 in range(person_1 + 1, N):
		config = configs[person_1] | configs[person_2]
		bit_count = count_bits_by_hash(config)
		if bit_count_best == bit_count:
			team_count_best += 1
		elif bit_count_best < bit_count:
			bit_count_best = bit_count
			team_count_best = 1
print(bit_count_best)
print(team_count_best)


(n, m) = [int(x) for x in input().split(' ')]
data = []
for i in range(n):
	data.append([int(x) for x in input()])

def union_size(a, b):
	u = 0
	for i in range(len(a)):
		if a[i] or b[i]:
			u += 1
	return u
Max = 0
Count = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		n = union_size(data[i], data[j])
		if n > Max:
			Max = n
			Count = 1
		elif n == Max:
			Count += 1
print(Max)
print(Count)


(N, M) = input().split()
N = int(N)
M = int(M)
l = []
nt = 0
t = 0
for i in range(N):
	l.append(int(input(), 2))
for i in range(N - 1):
	for j in range(i, N):
		z = len(str(bin(l[i] | l[j])).replace('0', '')) - 1
		if z > nt:
			nt = z
			t = 1
		elif z == nt:
			t += 1
print(nt)
print(t)


def countOnes(num):
	return bin(num).count('1')

def solve(l):
	m = 0
	c = 0
	for i in range(len(l)):
		for j in range(i + 1, len(l)):
			n = countOnes(l[i] | l[j])
			if n > m:
				m = n
				c = 1
			elif n == m:
				c += 1
	print(m)
	print(c)
num = int(input().split(' ')[0])
l = []
for n in range(num):
	l.append(int(input().strip(), 2))
solve(l)


(n, m) = (int(x) for x in input().split())
l = []
for i in range(n):
	l.append(input())
val = c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		cur = sum((1 for (x, y) in zip(l[i], l[j]) if x == '1' or y == '1'))
		if cur > val:
			val = cur
			c = 1
		elif cur == val:
			c += 1
print(val, c, sep='\n')


def read_bools(s):
	return [l == '1' for l in s]

def team_power(d1, d2):
	result = 0
	for i in range(len(d1)):
		if d1[i] or d2[i]:
			result += 1
	return result
nums = input().split()
n = int(nums[0])
m = int(nums[1])
dudes = []
for i in range(n):
	dudes.append(read_bools(input()))
(r, c) = (0, 0)
i = 0
while i < n - 1:
	j = i + 1
	while j < n:
		p = team_power(dudes[i], dudes[j])
		if p > r:
			(r, c) = (p, 1)
		elif p == r:
			c += 1
		j += 1
	i += 1
print(r)
print(c)


i = input().split()
l = []
o = []
ans = []
for x in range(int(i[0])):
	inp = input()
	l.append(int(inp, 2))
for m in range(int(i[0])):
	for j in range(m + 1, int(i[0])):
		a = l[m] | l[j]
		o.append(str(bin(a))[2:])
for t in o:
	ans.append(t.count('1'))
print(max(ans))
print(ans.count(max(ans)))


import itertools

def acm(N, M, O):
	newO = [len([c for c in str(bin(i[0] | i[1])) if c == '1']) for i in list(itertools.combinations(O, 2))]
	maxVal = max(newO)
	print(maxVal)
	print(len([i for i in newO if i == maxVal]))
(N, M) = [int(i) for i in input().split()]
O = []
for i in range(N):
	O.append(int(input().strip(), base=2))
acm(N, M, O)


inp = input().split()
n_p = int(inp[0])
n_t = int(inp[1])
cases = [int(input(), 2) for i in range(n_p)]
max_topics = 0
num_topics = 0
team_cnt = 1
for pi in range(n_p):
	for pj in range(pi + 1, n_p):
		num_topics = bin(cases[pi] | cases[pj]).count('1')
		if num_topics > max_topics and num_topics > 0:
			max_topics = num_topics
			team_cnt = 1
		elif num_topics == max_topics:
			team_cnt += 1
		num_topics = 0
print(max_topics)
print(team_cnt)


(n, m) = map(int, input().split())
teams = list()
for _ in range(n):
	teams.append(input())

def count_topics(team):
	count = 0
	for topic in str(bin(team)):
		if topic == '1':
			count += 1
	return count
maximum_combs = dict()
maximum = 0
for index in range(len(teams)):
	for index2 in range(index + 1, len(teams)):
		topics = count_topics(int(teams[index], 2) | int(teams[index2], 2))
		maximum_combs[frozenset([teams[index], teams[index2]])] = topics
		if topics > maximum:
			maximum = topics
maximum_teams = 0
for comb in maximum_combs.keys():
	if maximum_combs[comb] == maximum:
		maximum_teams += 1
print(maximum)
print(maximum_teams)


def count_ones(e):
	return bin(e).replace('0b', '').count('1')

def team_knows(player1, player2):
	return (player1[i] | player2[i] for i in range(len(player1)))
(N, M) = map(int, input().split())
who_knows_what = []
resto = 32 - M % 32
for i in range(N):
	knowledge = str(input())
	who_knows_what.append([knowledge[i:i + 32] for i in range(0, len(knowledge), 32)])
	who_knows_what[-1][-1] = who_knows_what[-1][-1] + ''.join(('0' for i in range(resto)))
	who_knows_what[-1] = list(map(lambda e: int(e, 2), who_knows_what[-1]))
how_much_teams_know = ((i, j, t, sum([count_ones(e) for e in t])) for i in range(N) for j in range(i + 1, N) for t in [team_knows(who_knows_what[i], who_knows_what[j])])
max_knowledge = 0
amount_with_knowledge = 0
for (i, j, k, howmuch) in how_much_teams_know:
	if howmuch > max_knowledge:
		max_knowledge = howmuch
		amount_with_knowledge = 1
	elif howmuch == max_knowledge:
		amount_with_knowledge = amount_with_knowledge + 1
print(max_knowledge)
print(amount_with_knowledge)


(n, m) = [int(x) for x in input().split(' ')]
people = [int('0b' + input(), 2) for _ in range(n)]
maximum = 0
count = 0
for (i, p1) in enumerate(people):
	for p2 in people[i:]:
		x = bin(p1 | p2).count('1')
		if x == maximum:
			count += 1
		elif x > maximum:
			maximum = x
			count = 1
print(maximum)
print(count)


(n, m) = list(map(int, input().split()))
ts = []
for i in range(n):
	t = set([i for (i, d) in enumerate(input()) if d == '1'])
	ts.append(t)
(max_topic, max_team) = (0, 0)
for i in range(len(ts) - 1):
	for j in range(i + 1, len(ts)):
		n_topic = len(ts[i].union(ts[j]))
		if n_topic > max_topic:
			(max_topic, max_team) = (n_topic, 1)
		elif n_topic == max_topic:
			max_team += 1
print(max_topic)
print(max_team)


def num_bits(p1, p2):
	return sum([1 for (b1, b2) in zip(p1, p2) if b1 == '1' or b2 == '1'])
(N, M) = [int(x) for x in input().split()]
people = []
for i in range(N):
	people.append(input())
max_b = 0
num_teams = 0
for (i, p1) in enumerate(people):
	for p2 in people[i + 1:]:
		num_b = num_bits(p1, p2)
		if num_b > max_b:
			max_b = num_b
			num_teams = 1
		elif num_b == max_b:
			num_teams += 1
print(max_b)
print(num_teams)


import collections
(P, T) = [int(e) for e in input().strip().split()]
people = []
for _ in range(P):
	people.append(int(input(), 2))
people.sort()
countDict = collections.defaultdict(int)
for (i, p1) in enumerate(people):
	for p2 in people[i + 1:]:
		countDict[bin(p1 | p2).count('1')] += 1
maxCount = max(countDict.keys())
print(maxCount)
print(countDict[maxCount])


def calcSum(str1, str2, l):
	a = 0
	for i in range(l):
		if str1[i] == 1 or str2[i] == 1:
			a += 1
	return a
(n, m) = list(map(int, input().split(' ')))
nums = list()
for i in range(n):
	nums.append(list(map(int, list(input()))))
counter = 0
maxSum = 0
for i in range(n):
	for j in range(i, n):
		tmpSum = calcSum(nums[i], nums[j], m)
		if tmpSum > maxSum:
			maxSum = tmpSum
			counter = 0
		if tmpSum == maxSum:
			counter += 1
print(maxSum)
print(counter)


(people, topics) = list(map(int, input().split()))
person = []
max = 0
count = 0
for _ in range(people):
	new_person = int(input(), 2)
	for p in person:
		team = bin(new_person | p).count('1')
		if team > max:
			max = team
			count = 1
		elif team == max:
			count += 1
	person.append(new_person)
print(max)
print(count)


ip = [int(a) for a in input().split()]
s = []
for i in range(0, ip[0]):
	s.append(input().replace('\n', ''))
kn_count = 0
max_c = 0
for i in range(0, ip[0]):
	for j in range(i + 1, ip[0]):
		l = [1 for (s1, s2) in zip(s[i], s[j]) if s1 == '1' or s2 == '1']
		len_l = len(l)
		if len_l > max_c:
			max_c = len_l
			kn_count = 0
		if len_l == max_c:
			kn_count += 1
print(max_c)
print(kn_count)


def solve(people, topics):
	know = list()
	num = list()
	max = 0
	count = 1
	for i in range(people):
		know.append(input())
	for x in range(len(know)):
		for y in range(x + 1, len(know)):
			first = int(know[x], 2)
			second = int(know[y], 2)
			third = first | second
			temp = bin(third).count('1')
			if temp > max:
				max = temp
				count = 1
			elif temp == max:
				count += 1
	print(max)
	print(count)
initial = list(map(int, input().split()))
solve(initial[0], initial[1])


(N, M) = map(int, input().split(' '))
people = []
for _ in range(N):
	binary_string = '0b' + input()
	binary_int = int(binary_string, 2)
	people.append(binary_int)
max_topics = -1
teams = {}
for p1 in range(len(people) - 1):
	for p2 in range(p1 + 1, len(people)):
		num_topics = bin(people[p1] | people[p2]).count('1')
		if num_topics < max_topics:
			continue
		elif num_topics > max_topics:
			max_topics = num_topics
			teams[max_topics] = 1
		else:
			teams[max_topics] += 1
print(max_topics)
print(teams[max_topics])


import sys
import math
(N, M) = list(map(int, str(input()).split()))
array = []
for x in range(N):
	array.append(int(sys.stdin.readline(), 2))
max = 0
count = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		cur = bin(array[i] | array[j]).count('1')
		if cur > max:
			max = cur
			count = 1
		elif cur == max:
			count += 1
print(max)
print(count)


def topics(a, b):
	result = a | b
	return '{0:b}'.format(result).count('1')
(N, M) = tuple(map(int, input().split()))
p = []
for case_id in range(N):
	p.append(int(input(), base=2))
max = -1
for i in range(N):
	for j in range(i, N):
		t = topics(p[i], p[j])
		if t > max:
			max = t
			maxn = 1
		elif t == max:
			maxn += 1
print(max)
print(maxn)


def howMushKnows(list1, list2):
	howMush = 0
	for i in range(len(list1)):
		if list1[i] > 0 or list2[i] > 0:
			howMush += 1
	return howMush
entree = input()
entree = entree.split(' ')
n = int(entree[0])
m = int(entree[1])
l = n
matiersKnowns = []
while l:
	ligneLocale = input()
	listeLocale = [int(c) for c in ligneLocale]
	matiersKnowns.append(listeLocale)
	l -= 1
Max = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		howMush = howMushKnows(matiersKnowns[i], matiersKnowns[j])
		if Max < howMush:
			Max = howMush
			combientConnaissentLeMax = 1
		elif Max == howMush:
			combientConnaissentLeMax += 1
print(Max)
print(combientConnaissentLeMax)


[n, m] = list(map(int, input().split()))
lst = []
for i in range(n):
	lst.append(int(input(), 2))
maxThemes = 0
teamCount = 0
for i in range(len(lst)):
	for j in range(i, len(lst)):
		p1 = lst[i]
		p2 = lst[j]
		if bin(p1 | p2).count('1') > maxThemes:
			maxThemes = bin(p1 | p2).count('1')
			teamCount = 1
		elif bin(p1 | p2).count('1') == maxThemes:
			teamCount += 1
print(maxThemes)
print(teamCount)


tmp = input().split()
numberofpeople = int(tmp[0])
numberoftopics = int(tmp[1])
(knowledge, result) = ([], [])
for i in range(0, numberofpeople):
	knowledge.append(str(input()))
	knowledge[i] = '0b' + knowledge[i]
for k in range(0, numberofpeople - 1):
	for j in range(k + 1, numberofpeople):
		result.append(bin(int(knowledge[k], 2) | int(knowledge[j], 2)))
result.sort()
answer = []
for l in range(0, len(result)):
	answer.append(result[l].count('1'))
answer.sort()
answer1 = answer[len(answer) - 1]
answer2 = answer.count(answer1)
print(answer1)
print(answer2)


def get_matches(arr1, idx_used, found, length, largest, largest_arr):
	matches = 0
	row_id = []
	unfound = True
	for i in range(len(arr1)):
		counter = 0
		for z in found:
			if arr1[i][z] == '1':
				counter += 1
		if counter + (length - len(found)) > largest:
			largest = counter + (length - len(found))
			largest_arr = []
			largest_arr.append([i, idx_used])
		elif counter + (length - len(found)) == largest:
			if len(largest_arr) == 0:
				largest_arr.append([i, idx_used])
			else:
				for x in range(len(largest_arr)):
					if i in largest_arr[x] and idx_used in largest_arr[x]:
						unfound = False
				if unfound:
					largest_arr.append([i, idx_used])
	return [largest_arr, largest]
line = input().split()
n = int(line[0])
m = int(line[1])
peops = []
largest_arr = []
matches = []
biggest = 0
found = 0
new_high = 0
amt = 0
max1 = []
for i in range(n):
	peops.append(input())
for i in range(n):
	zeros = []
	for z in range(m):
		if peops[i][z] is '0':
			zeros.append(z)
	max1.append(get_matches(peops, i, zeros, m, new_high, largest_arr))
	new_high = max1[i][1]
	largest_arr = max1[i][0]
print(new_high)
print(len(largest_arr))


(N, M) = (int(i) for i in input().split())
people = tuple((set((i for (i, m) in enumerate(input()) if m == '1')) for n in range(N)))
max_topics = 0
count = 0
for i in range(N):
	for j in range(i):
		topics = len(people[i] | people[j])
		if max_topics < topics:
			max_topics = topics
			count = 1
		elif max_topics == topics:
			count += 1
print(max_topics)
print(count)


[N, M] = [int(inp) for inp in str(input()).split(' ') if inp != '']
part = [int(input(), base=2) for k in range(N)]
teams = ['{0:0b}'.format(part[i] | part[j]).count('1') for i in range(len(part)) for j in range(i + 1, len(part))]
m = max(teams)
print(m)
print(len([t for t in teams if t == m]))


__author__ = 'danielbaeck'
import itertools
cache = {}

def intOr(k, l):
	sums = 0
	for x in range(len(k)):
		sums += binsum(k[x] | l[x])
	return sums

def intsum(k, l):
	sums = 0
	for x in range(len(k)):
		if k[x] == '1' or l[x] == '1':
			sums += 1
	return sums

def binsum(x):
	if x in cache:
		return cache[x]
	s = sum([int(i) for i in bin(x)[2:]])
	cache[x] = s
	return s
(n, m) = [int(i) for i in input().split()]
t = []
to = []
for i in range(n):
	t.append([])
	r = input()
	to.append(r)
	for j in range(0, m, 8):
		t[i].append(int(r[j:min(j + 8, len(r))], 2))
maxt = 0
maxn = 0
maxr = None
for i in itertools.combinations(range(n), 2):
	r = intOr(t[i[0]], t[i[1]])
	if r > maxt:
		maxt = r
		maxn = 1
		maxr = i
	elif r == maxt:
		maxn += 1
print(intsum(to[maxr[0]], to[maxr[1]]))
print(maxn)


def prog():
	(numberOfPeople, topics) = [int(x) for x in str(input()).split()]
	people = [[int(y) for y in list(str(input()))] for x in range(numberOfPeople)]
	max_M = 0
	max_teams = 0
	for n in range(numberOfPeople):
		for m in range(numberOfPeople)[n + 1:]:
			t = totalTopics(topics, people[n], people[m])
			if t > max_M:
				max_M = t
				max_teams = 1
			elif t == max_M:
				max_teams += 1
	print('%d\n%d' % (max_M, max_teams))

def totalTopics(M, a, b):
	count = 0
	for i in range(M):
		if a[i] or b[i]:
			count += 1
	return count
prog()


import itertools
(people, topics) = [int(i) for i in input().split(' ')]
knowledge = []
for i in range(people):
	knowledge.append(input())
knowledge = ['{0:b}'.format(int(i, 2) | int(j, 2)).count('1') for (i, j) in itertools.combinations(knowledge, 2)]
maximum = max(knowledge)
print(maximum)
print(knowledge.count(maximum))


import itertools
(N, M) = map(int, input().split())
persons = [input() for i in range(N)]
teamdata = itertools.combinations(persons, 2)
teams = []
for tuples in teamdata:
	teams.append(tuples)
topics_per_team = [bin(int(x[0], 2) | int(x[1], 2)) for x in teams]
max_topic_team = [topic.count('1') for topic in topics_per_team]
max_no_of_topics = max(max_topic_team)
no_of_teams_with_most_topics = max_topic_team.count(max_no_of_topics)
print(max_no_of_topics)
print(no_of_teams_with_most_topics)


(people, topics) = [int(x) for x in input().split()]
arr = []
for _ in range(people):
	arr.append(int(input(), 2))
(max_topics, teams) = (0, 0)
for i in range(people - 1):
	for j in range(i + 1, people):
		s = bin(arr[i] | arr[j])
		d = dict(((char_, s.count(char_)) for char_ in set(s)))
		tk = d['1'] if '1' in d else 0
		if tk > max_topics:
			max_topics = tk
			teams = 1
		elif tk == max_topics:
			teams += 1
print(max_topics)
print(teams)


(n, m) = (int(s) for s in input().split())
topics = [input() for _ in range(n)]
known = lambda t1, t2: sum((1 for tup in zip(t1, t2) if '1' in tup))
(max_topic, max_cnt) = (-1, 0)
for (i, ti) in enumerate(topics):
	for tj in topics[i + 1:]:
		tmp_topic = known(ti, tj)
		if tmp_topic > max_topic:
			max_topic = tmp_topic
			max_cnt = 1
		elif tmp_topic == max_topic:
			max_cnt += 1
print(max_topic)
print(max_cnt)


(N, M) = map(int, input().strip().split(' '))
inputs = []
for i in range(N):
	inputs.append(int(input(), 2))
topic_counts = {}
max_topics = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		topic_count = bin(inputs[i] | inputs[j]).count('1')
		if topic_count > max_topics:
			max_topics = topic_count
		if topic_count in topic_counts:
			topic_counts[topic_count] += 1
		else:
			topic_counts[topic_count] = 1
print(max_topics)
print(topic_counts[max_topics])


def to_idxs(x):
	return {i for (i, c) in enumerate(x) if c == '1'}
(N, M) = input().split()
l = [to_idxs(input()) for _ in range(int(N))]
mval = sorted((len(a.union(b)) for (i, a) in enumerate(l[:-1]) for b in l[i + 1:]), reverse=True)
print(mval[0])
print(mval.count(mval[0]))


num_test_cases = input().split(' ')
N = int(num_test_cases[0])
M = int(num_test_cases[1])
testcases = []
max_teams = 0
max_topics_per_team = 0
for i in range(N):
	testcases.append(int(input(), 2))
for j in range(N):
	master = testcases[j]
	for k in range(j + 1, N):
		tmp_team_topic = master | testcases[k]
		if bin(max_topics_per_team).count('1') < bin(tmp_team_topic).count('1'):
			max_teams = 1
			max_topics_per_team = tmp_team_topic
		elif bin(max_topics_per_team).count('1') == bin(tmp_team_topic).count('1'):
			max_teams += 1
print(bin(max_topics_per_team).count('1'))
print(max_teams)


(pep, top) = list(map(int, input().split()))
u = [''] * pep
for i in range(0, pep):
	u[i] = str(input())
su = []
for h in range(0, pep):
	for g in range(h + 1, pep):
		su.append(bin(int(u[h], 2) | int(u[g], 2)))
fo = []
for ty in range(0, len(su)):
	su[ty] = su[ty][-top:]
	fo.append(su[ty].count('1'))
fo.sort()
print(fo[len(fo) - 1])
print(fo.count(fo[len(fo) - 1]))


n = int(input().split()[0])
bits = [int(input(), 2) for _ in range(n)]
from collections import defaultdict
unions = []
for b1 in range(len(bits)):
	for b2 in range(b1, len(bits)):
		unions.append(bits[b1] | bits[b2])
most = bin(max(unions, key=lambda el: bin(el).count('1'))).count('1')
count = 0
for union in unions:
	if bin(union).count('1') == most:
		count += 1
print(most)
print(count)


def toInt(s):
	n = 0
	for i in range(len(s)):
		if s[-i - 1] == '1':
			n += pow(2, i)
	return n
(N, M) = map(int, input().split())
persons = []
for i in range(N):
	persons.append(toInt(input()))
max_value = 0
max_teams = 0
for i in range(N):
	for j in range(i + 1, N):
		candidate = bin(persons[i] | persons[j]).count('1')
		if candidate > max_value:
			max_value = candidate
			max_teams = 1
		elif candidate == max_value:
			max_teams += 1
print(max_value, max_teams, sep='\n')


from sys import stdin
lines = stdin.read().split('\n')
(N, M) = lines.pop(0).split(' ')
(N, M) = (int(N), int(M))
delete = []
for i in range(len(lines)):
	if lines[i] == '':
		delete.append(lines[i])
	else:
		lines[i] = int(lines[i], 2)
for dele in delete:
	lines.remove(dele)
(maxx, count) = (0, 0)
for x in range(N):
	for y in range(x + 1, N):
		nmaxx = str(bin(lines[x] | lines[y])).count('1')
		if maxx < nmaxx:
			(maxx, count) = (nmaxx, 1)
		elif maxx == nmaxx:
			count += 1
print(maxx)
print(count)


(n, m) = [int(x) for x in str(input()).split(' ')]
stu = []
perms = []
for x in range(n):
	stu.append(int(input(), 2))
for x in range(len(stu)):
	for y in range(x + 1, len(stu)):
		perms.append(stu[x] | stu[y])
count = str(bin(perms[0])).count('1')
teams = 1
for x in range(len(perms)):
	if str(bin(perms[x])).count('1') == count:
		teams += 1
	elif str(bin(perms[x])).count('1') > count:
		count = str(bin(perms[x])).count('1')
		teams = 1
print(count)
print(teams)


def TT(persons, topic_teams, possible_topics, people):
	for p1 in range(people):
		for p2 in range(p1, people):
			topic_knowhow = bin(int(persons[p1], 2) | int(persons[p2], 2))
			if topic_knowhow.count('1') > possible_topics:
				possible_topics = topic_knowhow.count('1')
				topic_teams = 1
			elif topic_knowhow.count('1') == possible_topics:
				topic_teams += 1
	return (possible_topics, topic_teams)
(people, topics) = input().split()
(people, topics) = (int(people), int(topics))
persons = []
for i in range(people):
	persons.append(input())
topic_knowhow = ''
for i in range(topics):
	topic_knowhow + '0'
	possible_topics = 0
	topic_teams = 0
(possible_topics, topic_teams) = TT(persons, topic_teams, possible_topics, people)
print(possible_topics)
print(topic_teams)


import itertools
from collections import defaultdict

def max_topics_in_team(member_one, member_two):
	return [x or y for (x, y) in zip(member_one, member_two)].count(True)
(num_people, num_topics) = (int(x) for x in input().split())
topic_stats = []
for _ in itertools.repeat(None, num_people):
	topic_stats.append([x == '1' for x in input()])
count = defaultdict(int)
for (player_one, player_two) in itertools.combinations(range(num_people), 2):
	count[max_topics_in_team(topic_stats[player_one], topic_stats[player_two])] += 1
max_topics = max(count.keys())
print(max_topics)
print(count[max_topics])


from itertools import combinations
from collections import Counter

def known_subjects(num_subjs):
	return bin(num_subjs).count('1')
(n, m) = [int(i) for i in input().split()]
subjects_known = [int(input(), 2) for i in range(n)]
topics_to_teams = Counter((known_subjects(p1 | p2) for (p1, p2) in combinations(subjects_known, 2)))
most_topics = max(topics_to_teams.keys())
print(most_topics)
print(topics_to_teams[most_topics])


def add(p1, p2):
	return sum((i or j for (i, j) in zip(p1, p2)))
(N, M) = (int(i) for i in input().split())
persons = []
for i in range(N):
	persons.append([int(i) for i in list(input())])
topics = []
for i in range(N - 1):
	for j in range(i + 1, N):
		topics.append(add(persons[i], persons[j]))
answer = max(topics)
print(answer)
print(topics.count(answer))


(N, M) = [int(x) for x in input().split()]
population = [str(input())]
max_known = max_count = 0
for i in range(N - 1):
	new = str(input())
	for p in population:
		pair = [1 if '1' in x else 0 for x in zip(new, p)]
		current_known = pair.count(1)
		if current_known > max_known:
			max_count = 1
			max_known = current_known
		elif current_known == max_known:
			max_count += 1
	population.append(new)
print(max_known)
print(max_count)


[N, M] = [int(num) for num in input().split(' ')]
tot = int(N * (N + 1) / 2)
knowledge = [0 for i in range(tot)]
starts = [int(tot - (N - i) * (N - i + 1) / 2) for i in range(N)]
individualKnowledge = [0 for i in range(N)]

def getKnowledgePos(a, b, starts):
	i = min(a, b)
	j = max(a, b)
	pos = starts[i] + j - i
	return pos
for person in range(N):
	individualKnowledge[person] = int(input(), 2)
for person in range(N):
	for otherperson in range(person, N):
		pos = getKnowledgePos(person, otherperson, starts)
		knowledge[pos] = bin(individualKnowledge[person] | individualKnowledge[otherperson])[2:].count('1')
maxKnowledge = max(knowledge)
print(maxKnowledge)
print(knowledge.count(maxKnowledge))


def knowledge_base(blist, max_tpx):
	pair_count = 0
	for i in range(1, len(blist)):
		for j in range(0, i):
			tmp = blist[i] | blist[j]
			weight = bin(tmp).count('1')
			if weight == max_tpx:
				pair_count += 1
	print(pair_count)

def max_topics(blist):
	max_tpx = 0
	for i in range(1, len(blist)):
		for j in range(0, i):
			temp = blist[i] | blist[j]
			temp = bin(temp).count('1')
			if temp > max_tpx:
				max_tpx = temp
	print(max_tpx)
	knowledge_base(blist, max_tpx)
(ppl, tpx) = input().split()
blist = []
for _ in range(int(ppl)):
	bnum = input()
	blist.append(bnum)
blist = [int(x, 2) for x in blist]
max_topics(blist)


def solve():
	(N, M) = map(int, input().split(' '))
	P = [int(input(), base=2) for _ in range(N)]
	best = 0
	teams = 0
	for i in range(N):
		for j in range(i + 1, N):
			t = bin(P[i] | P[j]).count('1')
			if t > best:
				best = t
				teams = 0
			if t == best:
				teams += 1
	print(best)
	print(teams)
solve()


listNums = []
numPeople = int(input().split(' ')[0])
for i in range(0, numPeople):
	listNums.append(int(input(), 2))
best = 0
numTeams = 0
for i in range(0, len(listNums)):
	for j in range(i + 1, len(listNums)):
		teamKnowledge = bin(listNums[i] | listNums[j]).count('1')
		if teamKnowledge > best:
			best = teamKnowledge
			numTeams = 1
		elif teamKnowledge == best:
			numTeams += 1
print(best)
print(numTeams)


__author__ = 'Hrishikesh'
(n, m) = map(int, input().split())
x = m
count = 0
flag = 0
matrix = []
for i in range(0, n):
	matrix.append(int(input()))
for i in range(0, n - 1):
	for j in range(i + 1, n):
		z = str(matrix[i] + matrix[j]).count('0')
		if z:
			if x > z:
				x = z
				count = 1
				if len(str(matrix[i])) == len(str(matrix[j])):
					if len(str(matrix[i])) < m:
						x += 1
			elif x == z:
				count += 1
		elif flag == 1:
			count += 1
		else:
			count = 1
			flag = 1
			x = 0
print(m - x)
print(count)


(n, m) = [int(i) for i in input().split()]
p = []
for i in range(n):
	p.append([int(j) == 1 for j in input()])
teams = {}
for i in range(n - 1):
	for j in range(i + 1, n):
		team = [a or b for (a, b) in zip(p[i], p[j])]
		sumT = sum(team)
		if sumT in teams.keys():
			teams[sumT] += 1
		else:
			teams[sumT] = 1
maxT = max(teams.keys())
print(maxT)
print(teams[maxT])


import itertools
people = []
max_topics = 0
num_teams = 0
for _ in range(int(input().split()[0])):
	people.append(set((i for (i, c) in enumerate(input()) if c == '1')))
for (a, b) in itertools.combinations(people, 2):
	topics = len(a | b)
	if topics > max_topics:
		max_topics = topics
		num_teams = 1
	elif topics == max_topics:
		num_teams += 1
print(max_topics)
print(num_teams)


def max_topics(s1, s2, M):
	count = 0
	for i in range(M):
		if s1[i] is '1' or s2[i] is '1':
			count += 1
	return count

def main():
	d = input().split()
	(N, M) = (int(d[0]), int(d[1]))
	people = []
	for i in range(N):
		people.append(input())
	max_teams = []
	for i in range(N - 1):
		for j in range(i, N):
			max_teams.append(max_topics(people[i], people[j], M))
	m = max(max_teams)
	print(m)
	print(max_teams.count(m))
main()


from itertools import combinations

def numTopics(a, b):
	return sum((1 for (aa, bb) in zip(a, b) if aa == '1' or bb == '1'))
ar = [input() for i in range(int(input().split()[0]))]
mx = 0
cx = 0
for (a, b) in combinations(ar, 2):
	curr = numTopics(a, b)
	if curr > mx:
		mx = curr
		cx = 1
	elif curr == mx:
		cx += 1
print(mx)
print(cx)


def known_topics(p1, p2):
	return bin(p1 | p2)[2:].count('1')
stdIn = input().split()
N = int(stdIn[0])
M = int(stdIn[1])
person = []
for i in range(0, N):
	person.append(int(input(), 2))
max_topics = 0
for i in range(0, N):
	for j in range(i + 1, N):
		max_topics = max(max_topics, known_topics(person[i], person[j]))
win_teams = 0
for i in range(0, N):
	for j in range(i + 1, N):
		if known_topics(person[i], person[j]) == max_topics:
			win_teams = win_teams + 1
print(max_topics)
print(win_teams)


get_topics_sum = lambda first, second: bin(first | second).count('1')

def main():
	(n, m) = map(int, input().split())
	participants = [int(input(), 2) for _ in range(n)]
	results = []
	for i in range(n):
		for j in range(i + 1, n):
			results.append(get_topics_sum(participants[i], participants[j]))
	answer0 = max(results)
	answer1 = sum((1 for result in results if result == answer0))
	print(answer0)
	print(answer1)
main()


test_cases = int(input().split(' ')[0])
teams = []
max_topics = 0
max_count = 0
for _ in range(test_cases):
	team = int(input(), 2)
	for team2 in teams:
		topics = bin(team | team2).count('1')
		if topics > max_topics:
			max_topics = topics
			max_count = 1
		elif topics == max_topics:
			max_count += 1
	teams.append(team)
print(max_topics)
print(max_count)


def sumTopics(personA, personB):
	unknownTopicsPositionPersonA = personA[2]
	unknownTopicsPositionPersonB = personB[2]
	topics = personA[1]
	for pos in unknownTopicsPositionPersonA:
		if pos not in unknownTopicsPositionPersonB:
			topics += 1
	return topics

def solve():
	(n, m) = map(int, input().split())
	people = []
	for i in range(n):
		person = input()
		totalKnownTopics = sum((1 for t in person if t == '1'))
		unknownTopicsPosition = set((i for (i, t) in enumerate(person) if t == '0'))
		people.append((person, totalKnownTopics, unknownTopicsPosition))
	maxTopics = 0
	totalTeams = 0
	for i in range(len(people)):
		for j in range(i, len(people)):
			totalKnownTopicsPersonA = people[i][1]
			totalKnownTopicsPersonB = people[j][1]
			if totalKnownTopicsPersonA + totalKnownTopicsPersonB >= maxTopics:
				topics = sumTopics(people[i], people[j])
				if topics > maxTopics:
					maxTopics = topics
					totalTeams = 1
				elif topics == maxTopics:
					totalTeams += 1
	print(maxTopics)
	print(totalTeams)
solve()


s = input()
s = s.split(' ')
N = int(s[0])
M = int(s[1])

def onesInBinary(n):
	l = [x for x in bin(n)[2:]]
	count = l.count('1')
	return count
pass
n = []
for x in range(N):
	n.append(int(input(), 2))
pass
m = 0
t = 0
for x in range(N - 1):
	for y in range(x + 1, N):
		tmp = onesInBinary(n[x] | n[y])
		if tmp == m:
			t = t + 1
		elif tmp > m:
			m = tmp
			t = 1
		pass
print(m)
print(t)


(N, M) = list(map(int, input().split(' ')))
people = [0] * N
maxPair = 0
pairs = 0
for n in range(N):
	people[n] = int(input(), 2)
for a in range(N):
	for b in range(a + 1, N):
		pair = bin(people[a] | people[b]).count('1')
		if pair > maxPair:
			maxPair = pair
			pairs = 1
		elif pair == maxPair:
			pairs = pairs + 1
print('{0}'.format(maxPair))
print('{0}'.format(pairs))


from collections import Counter
(str1, str2) = str(input()).split(' ')
people = int(str1)
topics = int(str2)
p = []
n = people
while n > 0:
	p.append(int(input(), 2))
	n -= 1
c2p = []
for (e, p1) in enumerate(p):
	for p2 in p[:e + 1]:
		c2p.append(bin(p1 | p2).strip('0b').count('1'))
c = Counter(c2p)
print(max(c2p))
print(c[max(c2p)])


def add(p1, p2):
	return sum((i or j for (i, j) in zip(p1, p2)))
(N, M) = (int(i) for i in input().split())
persons = []
for i in range(N):
	persons.append([int(i) for i in list(input())])
totals = []
for i in range(N - 1):
	for j in range(i + 1, N):
		totals.append(add(persons[i], persons[j]))
highest = max(totals)
print(highest)
print(totals.count(highest))


(N, M) = tuple((int(item) for item in input().split()))
(max_topics, max_pairs) = (0, 0)
topics_array = []
for _ in range(N):
	topics_array.append(int(input(), base=2))
for i in range(N):
	for j in range(i + 1, N):
		curr_topics_num = topics_array[i] | topics_array[j]
		curr_topics = bin(curr_topics_num).count('1')
		if curr_topics > max_topics:
			max_topics = curr_topics
			max_pairs = 1
		elif curr_topics == max_topics:
			max_pairs += 1
print(max_topics)
print(max_pairs)


(num_people, num_topics) = map(int, input().split())
people = []
for _ in range(num_people):
	people.append(int(input(), 2))
max_topics = 0
num_groups = 0
for i in range(num_people - 1):
	for j in range(i + 1, num_people):
		combined = bin(people[i] | people[j])
		topics = combined.count('1')
		if topics > max_topics:
			max_topics = topics
			num_groups = 1
		elif topics == max_topics:
			num_groups += 1
print(max_topics)
print(num_groups)


(N, M) = map(int, input().split())
p = [int(input(), 2) for i in range(N)]
tm = 0
pn = 0
for i in range(N):
	for j in range(i + 1, N):
		t = bin(p[i] | p[j]).count('1')
		if t > tm:
			tm = t
			pn = 1
		elif t == tm:
			pn += 1
print('%i\n%i' % (tm, pn))


def max_topic_knowledge(p, t, sl):
	max_skill = 0
	max_teams = 0
	for i in range(len(sl) - 1):
		for j in range(i + 1, len(sl)):
			x = bin(sl[i] | sl[j]).count('1')
			if x == max_skill:
				max_teams += 1
			if x > max_skill:
				max_skill = x
				max_teams = 1
	return [max_skill, max_teams]
(persons, topics) = (int(i) for i in input().split())
skills_list = [int(input(), 2) for _ in range(persons)]
print('{0}\n{1}'.format(*max_topic_knowledge(persons, topics, skills_list)))


def topics_known(person):
	return person.count('1')

def merge(a, b):
	result = list(a)
	for i in range(len(result)):
		if b[i] == '1':
			result[i] = '1'
	return ''.join(result)

def solve(people):
	most = 0
	teams = 0
	for i in range(len(people)):
		a = people[i]
		for j in range(i + 1, len(people)):
			b = people[j]
			known = topics_known(merge(a, b))
			if known > most:
				teams = 1
				most = known
			elif known == most:
				teams += 1
	return (most, teams)
(num_people, num_topics) = map(int, input().split())
people = [input() for i in range(num_people)]
(most, teams) = solve(people)
print(most)
print(teams)


(N, M) = [int(num) for num in input().split(' ')]
people = []
for i in range(N):
	people.append(set())
	str = input()
	for (index, c) in enumerate(str):
		if c == '1':
			people[i].add(index)
dict = {}
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		sz = len(people[i] | people[j])
		if sz in dict:
			dict[sz] += 1
		else:
			dict[sz] = 1
		ans = sz if sz > ans else ans
print(ans)
print(dict[ans])


def solve(persons):
	max_teams = 0
	max_len = 0
	for p1 in range(len(persons) - 1):
		for p2 in range(p1 + 1, len(persons)):
			current_len = len(persons[p1].union(persons[p2]))
			if current_len > max_len:
				max_teams = 1
				max_len = current_len
			elif current_len == max_len:
				max_teams += 1
	return (max_len, max_teams)
(N, M) = list(map(int, input().split()))
persons = []
for person in range(N):
	persons.append({i for (i, ch) in enumerate(input()) if ch == '1'})
result = solve(persons)
print(result[0])
print(result[1])


def bit_or_count_ones(array1, array2):
	count = 0
	for i in range(len(array1)):
		if array1[i] or array2[i]:
			count += 1
	return count
(n, m) = input().strip().split()
(n, m) = (int(n), int(m))
people_hab = []
for i in range(n):
	person = input().strip()
	person_list = []
	for know_topic in person:
		if know_topic == '1':
			person_list.append(True)
		else:
			person_list.append(False)
	people_hab.append(person_list)
maximum_topics = 0
number_groups = 0
for i in range(n):
	for j in range(i + 1, n):
		number_ones = bit_or_count_ones(people_hab[i], people_hab[j])
		if number_ones > maximum_topics:
			maximum_topics = number_ones
			number_groups = 1
		elif number_ones == maximum_topics:
			number_groups += 1
print(maximum_topics)
print(number_groups)


def numbestteams(n, m, c):
	bestscore = 0
	numteams = 0
	for i1 in range(n - 1):
		if c[i1] < 2 ** (bestscore - 1):
			return (bestscore, numteams)
		for i2 in range(i1 + 1, n):
			score = 0
			for l in bin(c[i1] | c[i2])[2:]:
				score += ord(l) - 48
			if score > bestscore:
				bestscore = score
				numteams = 1
			elif score == bestscore:
				numteams += 1
	return (bestscore, numteams)

def run():
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	c = [0] * n
	for i in range(n):
		c[i] = int(input(), 2)
	c.sort(reverse=True)
	(score, teams) = numbestteams(n, m, c)
	print(score)
	print(teams)
run()