A class of students wrote a multiple-choice test.

There are $n$ students in the class. The test had $m$ questions, each of them had $5$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $i$ worth $a_i$ points. Incorrect answers are graded with zero points.

The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. 


-----Input-----

The first line contains integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of students in the class and the number of questions in the test.

Each of the next $n$ lines contains string $s_i$ ($|s_i| = m$), describing an answer of the $i$-th student. The $j$-th character represents the student answer (A, B, C, D or E) on the $j$-th question.

The last line contains $m$ integers $a_1, a_2, \ldots, a_m$ ($1 \le a_i \le 1000$) — the number of points for the correct answer for every question.


-----Output-----

Print a single integer — the maximum possible total score of the class.


-----Examples-----
Input
2 4
ABCD
ABCE
1 2 3 4

Output
16
Input
3 3
ABC
BCD
CDE
5 4 12

Output
21


-----Note-----

In the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $16$.

In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $5 + 4 + 12 = 21$.

Difficulty: EASY

Solutions:
import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(input()))
c = list(map(int, input().split()))
s = 0
for j in range(m):
	x = dc(int)
	for i in range(n):
		x[l[i][j]] += 1
	s += c[j] * max(x.values())
print(s)


import sys
NM = list(map(int, input().split()))
n = NM[0]
m = NM[1]
choices = []
for _ in range(n):
	choices.append(list(input()))
Choices = [[None for _ in range(n)] for _ in range(m)]
for i in range(m):
	for j in range(n):
		Choices[i][j] = choices[j][i]
res = list(map(int, input().split()))
tot = 0
for i in range(m):
	tot += res[i] * max(Choices[i].count('A'), Choices[i].count('B'), Choices[i].count('C'), Choices[i].count('D'), Choices[i].count('E'))
print(tot)


(l, n) = input().split()
answers = [0, 0, 0, 0, 0] * int(n)
opt_dict = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
for i in range(int(l)):
	temp = input()
	for j in range(int(n)):
		koko = j * 5 + opt_dict[temp[j]]
		answers[j * 5 + opt_dict[temp[j]]] += 1
scoring = list(input().split())
score = 0
for j in range(int(n)):
	score += int(scoring[j]) * max(answers[j * 5:(j + 1) * 5])
print(score)


def read_ints():
	return map(int, input().split(' '))
(n, m) = read_ints()
s = []
for i in range(n):
	s.append(input())
a = list(read_ints())
ans = 0
for i in range(m):
	d = [0 for k in range(5)]
	for j in range(n):
		d[ord(s[j][i]) - ord('A')] += 1
	ans += max(d) * a[i]
print(ans)


(n, m) = map(int, input().split())
mass = [[] for i in range(m)]
for i in range(n):
	x = [k for k in input()]
	for j in range(m):
		mass[j].append(x[j])
maxmass = []
for i in mass:
	maxans = max(i.count('A'), i.count('B'), i.count('C'), i.count('D'), i.count('E'))
	maxmass.append(maxans)
points = [int(i) for i in input().split()]
ans = 0
for i in range(len(maxmass)):
	ans += maxmass[i] * points[i]
print(ans)


(n, m) = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(list(input()))
s = list(map(int, input().split()))
su = 0
for i in range(0, m):
	l = 0
	for u in ['A', 'B', 'C', 'D', 'E']:
		q = 0
		for j in range(0, n):
			if a[j][i] == u:
				q = q + 1
		if q > l:
			l = q
	su = su + l * s[i]
print(su)


from collections import defaultdict as dd, deque, Counter
(n, m) = list(map(int, input().split()))
A = [input() for _ in range(n)]
P = [int(x) for x in input().split()]
r = 0
for a in zip(list(zip(*A)), P):
	c = Counter(a[0])
	r += c.most_common()[0][1] * a[1]
print(r)


(students, questions) = input().split()
(students, questions) = (int(students), int(questions))
answer = []
guide = [[0] * 5 for _ in range(questions)]
ans = 0
for i in range(students):
	x = input()
	answer.append(x)
points = input().split()
for i in range(students):
	for j in range(questions):
		if answer[i][j] == 'A':
			guide[j][0] += 1
		elif answer[i][j] == 'B':
			guide[j][1] += 1
		elif answer[i][j] == 'C':
			guide[j][2] += 1
		elif answer[i][j] == 'D':
			guide[j][3] += 1
		elif answer[i][j] == 'E':
			guide[j][4] += 1
for m in range(len(guide)):
	ans += int(points[m]) * max(guide[m])
print(ans)


i = lambda : map(int, input().split())
(n, m) = i()
a = zip(*[input() for _ in [0] * n])
print(sum((y * max(map(''.join(x).count, 'ABCDE')) for (x, y) in zip(a, i()))))


(n, m) = list(map(int, input().split()))
marks = []
for i in range(n):
	marks.append(input())
c = list(map(int, input().split()))
d = ['A', 'B', 'C', 'D', 'E']
s = 0
for j in range(m):
	demo = [0] * 5
	for i in range(n):
		demo[d.index(marks[i][j])] += 1
	s += max(demo) * c[j]
print(s)


import sys
(n, m) = map(int, input().split())
ans = []
student = [[0, 0, 0, 0, 0] for _ in range(m)]
topSelect = [0, 0, 0, 0, 0]
final = []
for i in range(n):
	ans.append(sys.stdin.readline())
scores = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		student[j][ord(ans[i][j]) - ord('A')] += 1
for v in student:
	idex = v.index(max(v))
	final.append(idex)
s = 0
for i in range(n):
	for j in range(m):
		myAnswer = ord(ans[i][j]) - ord('A')
		if myAnswer == final[j]:
			s += scores[j]
print(s)


from math import *
from collections import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
(n, m) = getl()
l = []
for i in range(n):
	s = input()
	l.append(s)
a = getl()
ans = 0
for j in range(m):
	d = {}
	for i in range(n):
		x = l[i]
		c = x[j]
		if c not in d:
			d[c] = 1
		else:
			d[c] += 1
	m = max(d.values())
	ans += m * a[j]
print(ans)


(n, m) = map(int, input().split())
u = []
for i in range(n):
	u.append(list(input()))
a = list(map(int, input().split()))
ans = 0
for j in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for i in range(n):
		d[u[i][j]] += 1
	ans += a[j] * max(d['A'], d['B'], d['C'], d['D'], d['E'])
print(ans)


(n, m) = map(int, input().split())
S = []
for _ in range(n):
	S += (input(),)
A = [*map(int, input().split())]
max_ = 0
for i in range(m):
	C = [0, 0, 0, 0, 0]
	for j in range(n):
		idx = ord(S[j][i]) - ord('A')
		C[idx] += 1
	max_ += A[i] * max(C)
print(max_)


(n, m) = map(int, input().split())
l = [list(input()) for i in range(n)]
o = list(map(int, input().split()))
a = []
s = 0
for i in range(m):
	c = [0] * 5
	for j in range(n):
		c[ord(l[j][i]) - ord('A')] += 1
	s += max(c) * o[i]
print(s)


(n, m) = list(map(int, input().split()))
answers = [[0 for j in range(5)] for i in range(m)]
for _ in range(n):
	a = input()
	for i in range(m):
		if a[i] == 'A':
			answers[i][0] += 1
		elif a[i] == 'B':
			answers[i][1] += 1
		elif a[i] == 'C':
			answers[i][2] += 1
		elif a[i] == 'D':
			answers[i][3] += 1
		else:
			answers[i][4] += 1
points = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += points[i] * max(answers[i])
print(ans)


(n, tam) = map(int, input().split())
m = [[0 for i in range(5)] for j in range(tam)]
for i in range(n):
	s = input()
	for j in range(tam):
		m[j][ord(s[j]) - 65] += 1
v = [int(i) for i in input().split()]
res = 0
for i in range(tam):
	res += max(m[i]) * v[i]
print(res)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	d[i] = {c: 0 for c in 'ABCDE'}
for i in range(n):
	s = input()
	for j in range(m):
		d[j][s[j]] += 1
a = list(map(int, input().split()))
res = 0
for i in range(m):
	res += max(d[i].values()) * a[i]
print(res)


(n, m) = tuple(map(int, input().split()))
ans = [[] for i in range(n)]
for i in range(n):
	ans[i] = input()
marks = list(map(int, input().split()))
final = 0
for i in range(m):
	freq = [0, 0, 0, 0, 0]
	for j in range(n):
		if ans[j][i] == 'A':
			freq[0] += 1
		if ans[j][i] == 'B':
			freq[1] += 1
		if ans[j][i] == 'C':
			freq[2] += 1
		if ans[j][i] == 'D':
			freq[3] += 1
		if ans[j][i] == 'E':
			freq[4] += 1
	final += max(freq) * marks[i]
print(final)


(n, m) = [int(x) for x in input().split()]
s = []
for i in range(n):
	score = input()
	s.append(score)
p = [int(x) for x in input().split()]
tot = 0
for i in range(m):
	dic = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		dic[s[j][i]] += 1
	max_val = 0
	for l in dic.keys():
		if max_val < dic[l]:
			max_val = dic[l]
	tot += max_val * p[i]
print(tot)


from collections import Counter

def func(s):
	wc = Counter(s)
	q = max(wc.values())
	return q
l = list(map(int, input().split(' ')))
l1 = []
for i in range(l[0]):
	l1.append(input())
l3 = list(map(int, input().split(' ')))
sm = 0
for i in range(l[1]):
	s = ''
	for j in range(l[0]):
		s = s + l1[j][i]
	sm = sm + func(s) * l3[i]
print(sm)


import sys
ansdict = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
fin = sys.stdin
a = [int(i) for i in fin.readline().rstrip('\n').split()]
(students, questions) = (a[0], a[1])
ansC = [[0] * 5 for i in range(questions)]
for i in range(students):
	a = fin.readline().rstrip()
	for h in range(questions):
		ansC[h][ansdict[a[h]]] += 1
points = [int(i) for i in fin.readline().rstrip('\n').split()]
total = 0
for i in range(questions):
	total += points[i] * max(ansC[i])
print(total)


(n, m) = map(int, input().split())
x = [[0] * 26 for _ in range(m)]
for _ in range(n):
	s = input()
	for i in range(m):
		x[i][ord(s[i]) - ord('A')] += 1
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += max(x[i]) * a[i]
print(ans)


(n, m) = [int(i) for i in input().split()]
a = []
for i in range(n):
	x = input()
	a.append(x)
b = [int(i) for i in input().split()]
s = 0
for i in range(m):
	maxx = 0
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[a[j][i]] += 1
		maxx = max(maxx, d[a[j][i]])
	s += b[i] * maxx
print(s)


(n, m) = map(int, input().split())
qwm = [[] for i in range(m)]
for i in range(n):
	string = str(input())
	for j in range(m):
		qwm[j] += string[j]
maxscore = 0
scores = list(map(int, input().split()))
for i in range(m):
	maxcount = max(qwm[i].count('A'), qwm[i].count('B'), qwm[i].count('C'), qwm[i].count('D'), qwm[i].count('E'))
	maxscore += maxcount * scores[i]
print(maxscore)


(n, m) = map(int, input().split())
cnt = list(([0, 0, 0, 0, 0] for _ in range(m)))
for _ in range(n):
	s = input()
	for i in range(m):
		cnt[i][ord(s[i]) - ord('A')] += 1
arr = list(map(int, input().split()))
res = 0
for i in range(m):
	mx = 0
	for j in range(5):
		mx = max(mx, cnt[i][j] * arr[i])
	res += mx
print(res)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, m) = LI()
		sa = [S() for _ in range(n)]
		a = LI()
		r = 0
		for (i, c) in enumerate(a):
			t = collections.Counter((sa[j][i] for j in range(n)))
			r += c * max(t.values())
		rr.append(r)
	return JA(rr, '\n')
print(main())


(n, m) = map(int, input().split())
lis = []
fin = 0
ans = [[0] * 5 for i in range(m + 5)]
for i in range(n):
	a = input()
	lis.append(a)
points = [*map(int, input().split())]
for j in range(m):
	for i in range(n):
		ans[j][ord(lis[i][j]) - ord('A')] += points[j]
	fin += max(ans[j])
print(fin)


(n, m) = [int(x) for x in input().split()]
s = []
ans = 0
for i in range(n):
	s.append(input())
marks = [int(x) for x in input().split()]
for i in range(m):
	x = [0, 0, 0, 0, 0]
	for j in range(n):
		x[ord(s[j][i]) - ord('A')] += 1
	ans += max(x) * marks[i]
print(ans)


import sys
input = sys.stdin.readline
l = list(map(int, input().split()))
n = l[0]
m = l[1]
list1 = {}
l1 = []
dict = {}
for i in range(m):
	dict[i] = {}
for i in range(n):
	s = input()
	for j in range(m):
		dict[j][s[j]] = dict[j].get(s[j], 0) + 1
for j in range(m):
	max1 = 0
	for k in dict[j]:
		max1 = max(max1, dict[j][k])
	l1.append(max1)
l2 = list(map(int, input().split()))
ans = 0
for j in range(m):
	ans += l2[j] * l1[j]
print(ans)


from collections import Counter
(n, m) = list(map(int, input().split()))
l = list()
for i in range(n):
	l.append(list(input()))
a = list(map(int, input().split()))
cnt = 0
for (idx, q_ch) in enumerate(zip(*l)):
	c = Counter(q_ch)
	mc = c.most_common()
	cnt += a[idx] * mc[0][1]
print(cnt)


(n, m) = map(int, input().split())
arrs = list()
for i in range(n):
	arrs.append(str(input()))
point = list(map(int, input().split()))
from collections import defaultdict
dic = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(m)]
for i in range(n):
	for (j, elem) in enumerate(arrs[i]):
		dic[j][elem] += 1
ret = 0
for (i, d) in enumerate(dic):
	temp = 0
	for j in d:
		temp = max(temp, d[j])
	ret += temp * point[i]
print(ret)


(n, m) = map(int, input().split())
p = []
for i in range(m):
	p.append([0, 0, 0, 0, 0])
for i in range(n):
	a = input()
	for j in range(m):
		if a[j] == 'A':
			p[j][0] += 1
		elif a[j] == 'B':
			p[j][1] += 1
		elif a[j] == 'C':
			p[j][2] += 1
		elif a[j] == 'D':
			p[j][3] += 1
		else:
			p[j][4] += 1
w = list(map(int, input().split()))
marks = 0
for k in range(m):
	marks += w[k] * max(p[k])
print(marks)


(n, m) = list(map(int, input().split()))
a = []
for i in range(0, n):
	a.append(input())
b = list(map(int, input().split()))
s = 0
for i in range(0, m):
	c = [0] * 5
	for j in range(0, n):
		c[ord(a[j][i]) - 65] += 1
	s = s + max(c) * b[i]
print(s)


from collections import Counter
(n, m) = map(int, input().split())
st = [input() for i in range(n)]
sc = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	ans += sc[i] * max(Counter((s[i] for s in st)).values())
print(ans)


(n, m) = map(int, input().split())
n_answers = [[0, 0, 0, 0, 0] for _ in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		index = ord(s[j]) - 65
		n_answers[j][index] += 1
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += max(n_answers[i]) * a[i]
print(ans)


def calc(n, m, s, a):
	score = 0
	for j in range(m):
		choix = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
		for i in range(n):
			choix[s[i][j]] += 1
		score += max(choix.values()) * a[j]
	print(score)
l = input()
p = l.split(' ')
(n, m) = (int(p[0]), int(p[1]))
s = []
for i in range(n):
	s.append(input())
l = input()
a = l.split(' ')
for i in range(m):
	a[i] = int(a[i])
calc(n, m, s, a)


(n, m) = [int(x) for x in input().split()]
answ = []
for x in range(m):
	answ.append([0, 0, 0, 0, 0])
for x in range(n):
	a = input()
	for y in range(m):
		if a[y] == 'A':
			answ[y][0] += 1
		elif a[y] == 'B':
			answ[y][1] += 1
		elif a[y] == 'C':
			answ[y][2] += 1
		elif a[y] == 'D':
			answ[y][3] += 1
		elif a[y] == 'E':
			answ[y][4] += 1
points = [int(x) for x in input().split()]
a = 0
for x in range(m):
	a += max(answ[x]) * points[x]
print(a)


def tinh(a, id):
	dem = [0, 0, 0, 0, 0]
	for i in range(n):
		dem[ord(a[i][id]) - ord('A')] += 1
	return max(dem[:6])
(n, m) = map(int, input().split())
a = [list(input().strip()) for _ in range(n)]
b = list(map(int, input().split()))
s = 0
for i in range(m):
	s += b[i] * tinh(a, i)
print(s)


import sys, math, statistics as ss, collections as cc
input = sys.stdin.readline

def qw(List):
	dict = {}
	(count, itm) = (0, '')
	for item in reversed(List):
		dict[item] = dict.get(item, 0) + 1
		if dict[item] >= count:
			(count, itm) = (dict[item], item)
	return itm
(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = list(input())
	s.pop()
	a.append(s)
b = list(map(int, input().split()))
c = 0
for i in range(m):
	q = []
	for j in range(len(a)):
		q.append(a[j][i])
	if len(set(q)) != len(q):
		c = c + q.count(qw(q)) * b[i]
	else:
		c = c + b[i]
print(c)


z = list(map(int, input().split()))
arr = []
for i in range(z[0]):
	y = input()
	rra = []
	for j in y:
		rra.append(j)
	arr.append(rra)
x = list(map(int, input().split()))
count = 0
for i in range(z[1]):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for j in range(z[0]):
		if arr[j][i] == 'A':
			a += 1
		elif arr[j][i] == 'B':
			b += 1
		elif arr[j][i] == 'C':
			c += 1
		elif arr[j][i] == 'D':
			d += 1
		elif arr[j][i] == 'E':
			e += 1
	count += max(a, b, c, d, e) * x[i]
print(count)


def do():
	(n, m) = map(int, input().split(' '))
	if n == 0 or m == 0:
		return 0
	count = [[0] * 5 for _ in range(m)]
	for i in range(n):
		for (j, c) in enumerate(input()):
			count[j][ord(c) - ord('A')] += 1
	scores = [int(c) for c in input().split(' ')]
	res = 0
	for j in range(m):
		res += scores[j] * max(count[j])
	return res
print(do())


I = input
print(sum((x * y for (x, y) in zip((max(map(s.count, 'ABCDE')) for s in zip(*(I() for _ in [0] * int(I().split()[0])))), map(int, I().split())))))


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	x = [0, 0, 0, 0, 0]
	for j in range(n):
		x[ord(s[j][i]) - ord('A')] += 1
	ans += max(x) * a[i]
print(ans)


class CodeforcesTask1201ASolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.answers = []
		self.points = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[0]):
			self.answers.append(input())
		self.points = [int(x) for x in input().split(' ')]

	def process_task(self):
		points = 0
		for q in range(self.n_m[1]):
			a = [self.answers[x][q] for x in range(self.n_m[0])]
			cnts = [a.count(c) for c in list(set(a))]
			points += max(cnts) * self.points[q]
		self.result = str(points)

	def get_result(self):
		return self.result
Solution = CodeforcesTask1201ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
a = zip(*(input() for _ in range(n)))
ans = 0
for (x, y) in zip(a, map(int, input().split())):
	ans = ans + max((x.count(c) for c in 'ABCDE')) * y
print(ans)


import sys
ln = [int(i) for i in input().split(' ')]
n = ln[0]
m = ln[1]
ans = []
for i in range(0, n):
	ans.append(list(sys.stdin.readline().rstrip()))
arr = ['A', 'B', 'C', 'D', 'E']
pts = [int(i) for i in input().split(' ')]
s = 0
for i in range(0, m):
	cts = [0, 0, 0, 0, 0]
	for j in range(0, n):
		cts[arr.index(ans[j][i])] += 1
	s += max(cts) * pts[i]
print(s)


def maxfreq(a):
	d = {}
	for i in range(len(a)):
		d[a[i]] = 0
	for i in range(len(a)):
		d[a[i]] += 1
	maxi = 0
	for key in d:
		maxi = max(maxi, d[key])
	return maxi
(n, m) = map(int, input().split())
k = []
for i in range(n):
	k.append(input())
c = []
for i in range(m):
	p = []
	for j in range(n):
		p.append(k[j][i])
	c.append(p)
a = list(map(int, input().split()))
l = 0
for i in range(len(a)):
	l += maxfreq(c[i]) * a[i]
print(l)


from collections import Counter
(n, m) = map(int, input().split())
d = dict()
for i in range(n):
	s = input()
	for j in range(m):
		try:
			d[j].append(s[j])
		except:
			d[j] = [s[j]]
ans = 0
a = [int(o) for o in input().split()]
for i in range(m):
	f = dict(Counter(d[i]))
	m = 0
	for j in f.values():
		m = max(m, j)
	ans += m * a[i]
print(ans)


from collections import Counter

def readnums():
	return list(map(int, input().split()))

def readwords():
	return input().split()

def iinput():
	return int(input())
(n, m) = readnums()
answers = []
for _ in range(n):
	answers.append(input())
points = readnums()
res = 0
for i in range(m):
	res += Counter([answer[i] for answer in answers]).most_common()[0][1] * points[i]
print(res)


import sys, os, re, datetime
from collections import *
from bisect import *

def mat(v, *dims):

	def submat(i):
		if i == len(dims) - 1:
			return [v for _ in range(dims[-1])]
		return [submat(i + 1) for _ in range(dims[i])]
	return submat(0)
__cin__ = None

def cin():
	try:
		global __cin__
		if __cin__ is None:
			__cin__ = iter(input().split(' '))
		try:
			return next(__cin__)
		except StopIteration:
			__cin__ = iter(input().split(' '))
			return next(__cin__)
	except EOFError:
		return None

def iarr(n=0):
	return [int(v) for v in input().split(' ')]

def farr(n=0):
	return [float(v) for v in input().split(' ')]

def carr(n=0):
	return input()

def sarr(n=0):
	return [v for v in input().split(' ')]

def imat(n, m=0):
	return [iarr() for _ in range(n)]

def fmat(n, m=0):
	return [farr() for _ in range(n)]

def cmat(n, m=0):
	return [input() for _ in range(n)]

def smat(n, m=0):
	return [sarr() for _ in range(n)]

def ilist(n):
	return [int(cin()) for _ in range(n)]

def flist(n):
	return [float(cin()) for _ in range(n)]

def slist(n):
	return [cin() for _ in range(n)]
ans = 0
n = int(cin())
m = int(cin())
r = slist(n)
q = iarr()
for i in range(m):
	best = 0
	for k in range(ord('A'), ord('E') + 1):
		p = 0
		for j in range(n):
			if r[j][i] == chr(k):
				p += 1
		best = max(best, p)
	ans += best * q[i]
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
A = []
for _ in range(n):
	A += [input()]
C = [int(x) for x in input().split()]
result = 0
for i in range(m):
	result += max(Counter([A[j][i] for j in range(n)]).values()) * C[i]
print(result)


l = [int(x) for x in input().split()]
n = l[0]
m = l[1]
ans = 0
l1 = []
for i in range(n):
	x = input()
	l1.append(x)
l2 = [int(x) for x in input().split()]
for j in range(m):
	a = b = c = d = e = 0
	for i in range(n):
		if l1[i][j] == 'A':
			a = a + 1
		elif l1[i][j] == 'B':
			b = b + 1
		elif l1[i][j] == 'C':
			c = c + 1
		elif l1[i][j] == 'D':
			d = d + 1
		else:
			e = e + 1
	ma = max(a, b, c, d, e)
	ans = ans + ma * l2[j]
print(ans)


from itertools import groupby as gb
(n, m) = map(int, input().split())
a = [''] * m
for i in range(n):
	x = input()
	for j in range(m):
		a[j] += x[j]
b = (*map(int, input().split()),)
ans = 0
for i in range(m):
	z = (*map(lambda x: len(list(x[1])), gb(sorted(a[i]))),)
	ans += b[i] * max(z)
print(ans)


from collections import Counter
(n, m) = (int(i) for i in input().split())
answers = [input() for _ in range(n)]
marks = [int(i) for i in input().split()]
max_marks = 0
for (q_num, options) in enumerate(zip(*answers)):
	options = Counter(options)
	max_marks += options.most_common(1)[0][1] * marks[q_num]
print(max_marks)


(n, m) = map(int, input().split())
from collections import defaultdict as dd
from collections import Counter as cc
d = dd(list)
for i in range(n):
	s = input()
	for j in range(m):
		d[j] += [s[j]]
mul = list(map(int, input().split()))
mul = mul[::-1]
m = 0
for i in d:
	d1 = cc(d[i])
	m += max(d1.values()) * mul.pop()
print(m)


l = list(map(int, input().split()))
names = []
for i in range(l[0]):
	names.append(input())
l1 = []
for i in range(l[-1]):
	l2 = []
	for j in range(l[0]):
		l2.append(names[j][i])
	l1.append(l2)
weight = list(map(int, input().split()))
ew = []
score = 0
for i in range(l[-1]):
	if len(set(l1[i])) == len(l1[i]):
		score += weight[i]
	else:
		ew.append(i)
jk = []
for i in ew:
	jk = []
	for j in list(set(l1[i])):
		jk.append(l1[i].count(j))
	score += weight[i] * max(jk)
print(score)


(liczbaStud, liczbaPyt) = input().split()
liczbaStud = int(liczbaStud)
liczbaPyt = int(liczbaPyt)
tabOdp = []
for i in range(liczbaStud):
	tabOdp.append(input())
punkty = input().split()
output = 0
for pyt in range(liczbaPyt):
	dic = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for stud in range(liczbaStud):
		dic[tabOdp[stud][pyt]] += 1
	max = 0
	for x in dic:
		if dic[x] > max:
			max = dic[x]
	output += max * int(punkty[pyt])
print(output)


(n, m) = map(int, input().split())
answ = [input() for _ in range(n)]
weights = list(map(int, input().split()))
total = 0
for task in range(m):
	task_score = {}
	for student in range(n):
		answer = answ[student][task]
		if answer not in task_score:
			task_score[answer] = 0
		task_score[answer] += 1
	total += max(task_score.values()) * weights[task]
print(total)


import sys
import itertools
input = lambda : sys.stdin.readline().rstrip()
(n, m) = map(int, input().split())
arr = [input() for i in range(n)]
score = list(map(int, input().split()))
ans = 0
for i in range(m):
	a = [s[i] for s in arr]
	b = max([a.count(k) for k in 'ABCDE'])
	ans += score[i] * b
print(ans)


(m, n) = map(int, input().split())
a = zip(*(input() for _ in range(m)))
r = 0
for (x, y) in zip(a, map(int, input().split())):
	r += max((x.count(j) for j in 'ABCDE')) * y
print(r)


(n, m) = list(map(int, input().split()))
a = [[0 for j in range(5)] for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		a[j][ord(s[j]) - ord('A')] += 1
sum1 = 0
b = list(map(int, input().split()))
for i in range(m):
	sum1 += b[i] * max(a[i])
print(sum1)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))
import math
from bisect import bisect_left
(n, m) = getList()
ans = [[0 for i in range(5)] for i in range(m)]
for i in range(n):
	s = input().strip()
	for (i, c) in enumerate(s):
		ans[i][['A', 'B', 'C', 'D', 'E'].index(c)] += 1
pts = getList()
res = 0
for (i, a) in enumerate(ans):
	res += pts[i] * max(a)
print(res)


(n, m) = map(int, input().split())
count = []
for i in range(m):
	count.append([0] * 5)
for i in range(n):
	s = input()
	for (j, c) in enumerate(s):
		count[j]['ABCDE'.index(c)] += 1
points = list(map(int, input().split()))
total = sum((point * max(c) for (point, c) in zip(points, count)))
print(total)


def main():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = []
	for i in range(n):
		b = input()
		a.append(list(b))
	point = [int(i) for i in input().split()]
	total = 0
	for i in range(m):
		freq = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
		for j in range(n):
			freq[a[j][i]] += 1
		max = 0
		for j in freq:
			if freq[j] > max:
				max = freq[j]
		total += point[i] * max
	print(total)
main()


(n, m) = map(int, input().split())
answers = []
for i in range(n):
	s = input()
	answers.append(s)
counts = [0] * m
for i in range(m):
	c_a = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		c_a[answers[j][i]] += 1
	counts[i] = max(c_a.values())
balls = list(map(int, input().split()))
s = 0
for i in range(m):
	s += balls[i] * counts[i]
print(s)


(n, m) = map(int, input().split())
maxq = [[0] * 5 for i in range(m)]
for i in range(n):
	l = list(input())
	for q in range(m):
		maxq[q][ord(l[q]) - 65] += 1
points = list(map(int, input().split()))
point = 0
for i in range(m):
	point += max(maxq[i]) * points[i]
print(point)


def mp():
	return map(int, input().split())
(n, m) = mp()
s = [input() for i in range(n)]
a = list(mp())
ans = 0
for j in range(m):
	cnt = [0] * 5
	for i in range(n):
		cnt[ord(s[i][j]) - 65] += 1
	ans += a[j] * max(cnt)
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
ans = []
while n:
	ans.append(list(input()))
	n -= 1
score = list(map(int, input().split()))
total_score = 0
for i in range(m):
	temp = [a[i] for a in ans]
	correc_ans = Counter(temp)
	count_of_ans = correc_ans.most_common(1)
	total_score += score[i] * count_of_ans[0][1]
print(total_score)


(n, m) = [int(x) for x in input().split()]
s = []
for x in range(n):
	s.append(input())
a = [int(x) for x in input().split()]
i = 0
res = 0
for x in range(m):
	abcde = [0, 0, 0, 0, 0]
	for y in range(n):
		if s[y][x] == 'A':
			abcde[0] += 1
		elif s[y][x] == 'B':
			abcde[1] += 1
		elif s[y][x] == 'C':
			abcde[2] += 1
		elif s[y][x] == 'D':
			abcde[3] += 1
		else:
			abcde[4] += 1
	res += max(abcde) * a[i]
	i += 1
print(res)


(n, m) = map(int, input().strip().split())
x = []
maxscore = 0
for i in range(n):
	tmp = input().strip()
	x.append(tmp)
scores = list(map(int, input().strip().split()))
for i in range(m):
	votes = {}
	for j in range(n):
		answer = x[j][i]
		if answer not in votes:
			votes[answer] = 1
		else:
			votes[answer] += 1
	maxscore += max(votes.values()) * scores[i]
print(maxscore)


(alunos, questoes) = map(int, list(input().split()))
questions = [[] for _ in range(questoes)]
for a in range(alunos):
	respostas = list(input())
	for (index, r) in enumerate(respostas):
		questions[index].append(r)
valor = list(input().split())
sun = 0
for (index, q) in enumerate(questions):
	sun += max(q.count('A'), q.count('B'), q.count('C'), q.count('D'), q.count('E')) * int(valor[index])
print(sun)


(n, m) = map(int, input().split())
answers = []
for _ in range(n):
	answers.append(input())
points = list(map(int, input().split()))
totalScore = 0
for i in range(m):
	countA = 0
	countB = 0
	countC = 0
	countD = 0
	countE = 0
	for ans in answers:
		if ans[i] == 'A':
			countA += 1
		elif ans[i] == 'B':
			countB += 1
		elif ans[i] == 'C':
			countC += 1
		elif ans[i] == 'D':
			countD += 1
		elif ans[i] == 'E':
			countE += 1
	totalScore += max(countA, countB, countC, countD, countE) * points[i]
print(totalScore)


(n, m) = input().split()
n = int(n)
m = int(m)
z = []
p = []
h = []
flaga = 0
flagb = 0
flagc = 0
flagd = 0
flage = 0
k = 0
for i in range(n):
	x = input()
	h.append(x)
z = input().split()
for l in range(m):
	z[l] = int(z[l])
i = 0
while i < m:
	s = h[k]
	if s[i] == 'A':
		flaga += 1
		k = k + 1
	if s[i] == 'B':
		flagb += 1
		k = k + 1
	if s[i] == 'C':
		flagc += 1
		k = k + 1
	if s[i] == 'D':
		flagd += 1
		k = k + 1
	if s[i] == 'E':
		flage += 1
		k = k + 1
	if k == n:
		g = max(flaga, flagb, flagc, flagd, flage)
		p.append(g)
		i = i + 1
		k = 0
		flaga = 0
		flagb = 0
		flagc = 0
		flagd = 0
		flage = 0
cost = 0
for i in range(m):
	p[i] = int(p[i])
for i in range(m):
	cost = cost + z[i] * p[i]
print(cost)


R = lambda : map(int, input().split())
(n, m) = R()
L = []
for i in range(n):
	L.append([i for i in input()])
C = list(R())
res = 0
for i in range(m):
	f = [0] * 5
	for j in range(n):
		f[ord(L[j][i]) - ord('A')] += 1
	res += max(f) * C[i]
print(res)


(n, m) = map(int, input().split())
l = [{} for i in range(m)]
for i in range(n):
	s = list(input())
	for j in range(m):
		try:
			l[j][s[j]] += 1
		except:
			l[j][s[j]] = 1
a = list(map(int, input().split()))
c = 0
for i in range(m):
	c += max(list(l[i].values())) * a[i]
print(c)


(n, m) = map(int, input().split())
t = 0
l = []
for i in range(n):
	d = list(input())
	l.append(d)
k = list(map(int, input().split()))
for i in range(m):
	a1 = 0
	b1 = 0
	c1 = 0
	d1 = 0
	e1 = 0
	for j in range(n):
		if l[j][i] == 'A':
			a1 += 1
		elif l[j][i] == 'B':
			b1 += 1
		elif l[j][i] == 'C':
			c1 += 1
		elif l[j][i] == 'D':
			d1 += 1
		elif l[j][i] == 'E':
			e1 += 1
	r = max(a1, b1, c1, d1, e1)
	t += k[i] * r
print(t)


(n, m) = map(int, input().split())
ans = []
cnt = 0
for _ in range(n):
	ans.append(input())
a = list(map(int, input().split()))
for i in range(m):
	A = [0] * 5
	for j in range(n):
		A[ord(ans[j][i]) - 65] += 1
	A.sort(reverse=True)
	cnt += A[0] * a[i]
print(cnt)


(n, m) = map(int, input().split())
t = []
for j in range(n):
	t.append(list(input()))
s = list(map(int, input().split()))
ans = 0
for j in range(m):
	f = {}
	for i in range(n):
		if t[i][j] not in f:
			f[t[i][j]] = 1
		else:
			f[t[i][j]] += 1
	ans += max(f.values()) * s[j]
print(ans)


(n, m) = map(int, input().split())
ds = [{} for _ in range(m)]
for i in range(n):
	a = input()
	for (ind, c) in enumerate(a):
		ds[ind][c] = ds[ind].get(c, 0) + 1
bs = map(int, input().split())
res = 0
for (d, b) in zip(ds, bs):
	res += b * max(d.values())
print(res)


k = input().split()
(n, m) = (int(k[0]), int(k[1]))
empt = []
for i in range(n):
	empt.append(list(input()))
ans = []
for j in range(m):
	d = {}
	for i in range(n):
		d[empt[i][j]] = d.get(empt[i][j], 0) + 1
	ans.append(max(d.values()))
value_list = input().split()
s = 0
for i in range(m):
	s += ans[i] * int(value_list[i])
print(s)


from collections import Counter
ans = []
(n, m) = map(int, input().split())
for _ in range(n):
	ans.append(list(input()))
a = list(map(int, input().split()))
sum = 0
ans = [list(i) for i in zip(*ans)]
for i in range(m):
	sum += a[i] * Counter(ans[i]).most_common(1)[0][1]
print(sum)


s = input()
(n, m) = s.split()
(n, m) = (int(n), int(m))
ans = 0
dik = dict()
for i in range(n):
	p = input()
	for j in range(m):
		dik[str(j) + p[j]] = dik.get(str(j) + p[j], 0) + 1
inp = input()
inp = inp.split()
ps = list(map(int, inp))
for o in range(m):
	ans += ps[o] * max(dik.get(str(o) + 'A', 0), max(dik.get(str(o) + 'B', 0), max(dik.get(str(o) + 'C', 0), max(dik.get(str(o) + 'D', 0), dik.get(str(o) + 'E', 0)))))
print(ans)


from sys import stdin
(n, m) = (int(i) for i in stdin.readline().split())
L = list((list((0 for k in range(0, 5))) for i in range(0, m)))
for i in range(0, n):
	k = stdin.readline()
	for j in range(0, len(k)):
		if k[j] == 'A':
			L[j][0] += 1
		elif k[j] == 'B':
			L[j][1] += 1
		elif k[j] == 'C':
			L[j][2] += 1
		elif k[j] == 'D':
			L[j][3] += 1
		elif k[j] == 'E':
			L[j][4] += 1
D = list()
for i in range(0, m):
	D.append(max(L[i][0], L[i][1], L[i][2], L[i][3], L[i][4]))
score = list((int(i) for i in stdin.readline().split()))
highest = 0
for i in range(0, m):
	highest += score[i] * D[i]
print(highest)


(s, q) = map(int, input().split())
a = [input() for i in range(s)]
b = list(map(int, input().split()))
w = 0
for i in range(q):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(s):
		d[a[j][i]] += 1
	w += max(d.values()) * b[i]
print(w)


def charToInt(c):
	return ord(c) - ord('A')
(n, m) = [int(x) for x in input().split()]
aCnts = [[0 for _ in range(5)] for __ in range(m)]
for _ in range(n):
	s = input()
	for (i, c) in enumerate(s):
		aCnts[i][charToInt(c)] += 1
points = [int(x) for x in input().split()]
ans = 0
for i in range(m):
	ans += points[i] * max(aCnts[i])
print(ans)


x = input()
y = x.split()
z = [int(d) for d in y]
main_arr = []
no_of_students = z[0]
no_of_options = z[1]
sume = 0
for i in range(z[0]):
	p = input()
	q = [d for d in p]
	main_arr.append(q)
t = input()
t_ = t.split()
t__ = [int(d) for d in t_]
for i in range(z[1]):
	lit = []
	unique = []
	county = []
	for j in range(z[0]):
		lit.append(main_arr[j][i])
	for num in lit:
		if num not in unique:
			unique.append(num)
	for num in unique:
		county.append(lit.count(num))
	sume = sume + max(county) * t__[i]
print(sume)


from collections import Counter
(n, m) = list(map(int, input().split()))
l = [Counter() for i in range(m)]
for i in range(n):
	a = input()
	for (c, d) in zip(a, l):
		d[c] += 1
ans = 0
for (p, d) in zip(list(map(int, input().split())), l):
	ans += p * max(d.values())
print(ans)


(n, m) = map(int, input().split())
a = [[0, 0, 0, 0, 0] for i in range(m)]
for t in range(n):
	s = input()
	for i in range(m):
		a[i][ord(s[i]) - 65] += 1
for i in range(m):
	a[i].sort(reverse=True)
arr = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += a[i][0] * arr[i]
print(ans)


def calc(s):
	alpha = [0 for i in range(91)]
	for c in s:
		alpha[ord(c)] = alpha[ord(c)] + 1
	return max(alpha)

def f():
	(n, m) = [int(x) for x in input().split()]
	st_ans = [''] * n
	for i in range(n):
		st_ans[i] = input().strip()
	points = [int(x) for x in input().split()]
	va = [''] * m
	for i in range(m):
		s = ''
		for j in range(n):
			s = s + st_ans[j][i]
		va[i] = s
	maxCommon = [0] * m
	for i in range(m):
		maxCommon[i] = calc(va[i])
	return sum([maxCommon[i] * points[i] for i in range(m)])

def main():
	print(f())
main()


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s
(n, m) = mi()
l = []
for i in range(n):
	x = si()
	l.append(x)
z = li()
x = 0
for i in range(m):
	a = [0] * 26
	for j in range(n):
		a[ord(l[j][i]) - 65] += 1
	x += max(a) * z[i]
print(x)


(n, m) = map(int, input().split())
(responses, marks, ans) = ([input() for i in range(n)], [int(num) for num in input().split()], 0)
arr = [[] for i in range(m)]
for i in range(m):
	for j in range(n):
		arr[i].append(responses[j][i])
for i in range(m):
	ans += max(arr[i].count('A'), arr[i].count('B'), arr[i].count('C'), arr[i].count('D'), arr[i].count('E')) * marks[i]
print(ans)


nm = list(map(int, input().split()))
strings = []
temp = ''
answer = 0
for i in range(nm[0]):
	strings.append(input())
values = [int(x) for x in input().split()]
for i in range(nm[1]):
	cnt = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
	for Str in strings:
		cnt[int(ord(Str[i]) - ord('A'))] += 1
	max_c = [0, 0]
	for (key, value) in cnt.items():
		if value > max_c[0]:
			max_c[1] = key
			max_c[0] = value
	temp += chr(max_c[1] + ord('A'))
for i in range(nm[1]):
	for Str in strings:
		answer += values[i] if Str[i] == temp[i] else 0
print(answer)


(n, m) = list(map(int, input().split()))
s = []
for i in range(m):
	s.append({'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0})
for i in range(n):
	ans = input()
	for j in range(m):
		s[j][ans[j]] += 1
score = list(map(int, input().split()))
for i in range(m):
	score[i] *= max(s[i].values())
print(sum(score))


from collections import defaultdict
(n, m) = input().split()
(n, m) = (int(n), int(m))
arr = [[0 for i in range(5)] for j in range(m)]
for i in range(n):
	ans = input()
	for (q, o) in enumerate(ans):
		arr[q][ord(o) - ord('A')] += 1
marks = list(map(int, input().split(' ')))
ans = 0
for i in range(m):
	ans += max(arr[i]) * marks[i]
print(ans)


(n, m) = map(int, input().split())
d = {}
c = 0
h = []
for _ in range(n):
	k = input()
	for i in range(len(k)):
		if i not in d:
			d[i] = [k[i]]
		else:
			d[i] += k[i]
l = list(map(int, input().split()))
for i in d:
	k = -1
	for j in range(5):
		k = max(k, d[i].count(chr(65 + j)))
	h.append(k)
for i in range(len(h)):
	c += h[i] * l[i]
print(c)


from collections import Counter
IL = lambda : list(map(int, input().split()))
(n, m) = IL()
A = [input() for i in range(n)]
A = list(zip(*A))
V = IL()
print(sum((Counter(a).most_common(1)[0][1] * v for (v, a) in zip(V, A))))


import collections as cl
(n, m) = map(int, input().split())
ans = list(zip(*[input() for _ in range(n)]))
p = list(map(int, input().split()))
print(sum([max(cl.Counter(ans[i]).values()) * p[i] for i in range(m)]))


(n, m) = map(int, input().split())
dic = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(m)]
for i in range(n):
	string = input()
	for j in range(len(string)):
		dic[j][string[j]] += 1
answer = list(map(int, input().split()))
summ = 0
for j in range(m):
	maxxx = 0
	for elem in dic[j]:
		if dic[j][elem] > maxxx:
			maxxx = dic[j][elem]
	summ += maxxx * answer[j]
print(summ)


import sys
input = sys.stdin.readline
count = [[0, 0, 0, 0, 0] for x in range(1007)]
(n, m) = list(map(int, input().split()))
for i in range(n):
	ans = input()
	for j in range(m):
		if ans[j] == 'A':
			count[j][0] += 1
		if ans[j] == 'B':
			count[j][1] += 1
		if ans[j] == 'C':
			count[j][2] += 1
		if ans[j] == 'D':
			count[j][3] += 1
		if ans[j] == 'E':
			count[j][4] += 1
points = list(map(int, input().split()))
ans = 0
for i in range(m):
	maximum = 0
	for j in range(5):
		maximum = max(count[i][j], maximum)
	ans += maximum * points[i]
print(ans)


(n, m) = map(int, input().split())
ans = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(m)]
for _ in range(n):
	l = list(input())
	for i in range(m):
		ans[i][l[i]] += 1
points = list(map(int, input().split()))
total = 0
for i in range(m):
	total += max(list(ans[i].values())) * points[i]
print(total)


from collections import Counter
(p, m) = map(int, input().split())
a = []
for _ in range(p):
	a.append(input())
p = list(map(int, input().split()))
b = list(map(lambda x: max(Counter(x).values()), list(zip(*a))))
s = 0
for i in range(m):
	s += p[i] * b[i]
print(s)


(n, m) = map(int, input().split())
b = []
a = []
x = []
y = 0
for i in range(n):
	a.append(input())
c = list(map(int, input().split()))
for i in range(m):
	p = ''
	for t in range(n):
		p = p + a[t][i]
	b.append(p)
for i in range(m):
	x.append(max([b[i].count('A'), b[i].count('B'), b[i].count('C'), b[i].count('D'), b[i].count('E')]))
for i in range(m):
	y = y + c[i] * x[i]
print(y)


(n, m) = map(int, input().split())
a = [[0 for i in range(5)] for j in range(m)]
for i in range(n):
	s = input()
	for j in range(len(s)):
		a[j][ord(s[j]) - ord('A')] += 1
k = 0
ans = 0
for i in input().split():
	ans += max(a[k]) * int(i)
	k += 1
print(ans)


import operator

def solve():
	(n, m) = list(map(int, input().split()))
	nums = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(m)]
	for i in range(n):
		str = input()
		for j in range(m):
			nums[j][str[j]] += 1
	scores = list(map(int, input().split()))
	ans = 0
	for i in range(m):
		corrects = max(nums[i].items(), key=operator.itemgetter(1))[1]
		ans += corrects * scores[i]
	print(ans)
solve()


import collections
(n, m) = map(int, input().split())
arr = []
for x in range(n):
	arr.append(list(input()))
score = list(map(int, input().split()))
ans = 0
for x in range(m):
	loc = []
	for y in range(n):
		loc.append(arr[y][x])
	(a, b, c, d, e) = (0, 0, 0, 0, 0)
	for i in range(len(loc)):
		if loc[i] == 'A':
			a += 1
		elif loc[i] == 'B':
			b += 1
		elif loc[i] == 'C':
			c += 1
		elif loc[i] == 'D':
			d += 1
		elif loc[i] == 'E':
			e += 1
	cnt = max(a, b, c, d, e)
	ans += cnt * score[x]
print(ans)


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
s = []
for i in range(0, n):
	s.append(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
ans = 0
for j in range(0, m):
	(A, B, C, D, E) = (0, 0, 0, 0, 0)
	for i in range(0, n):
		if s[i][j] == 'A':
			A = A + 1
		if s[i][j] == 'B':
			B = B + 1
		if s[i][j] == 'C':
			C = C + 1
		if s[i][j] == 'D':
			D = D + 1
		if s[i][j] == 'E':
			E = E + 1
	ans = ans + max([A, B, C, D, E]) * a[j]
print(ans)


def mode(M):
	return M.count(max(set(M), key=M.count))
(n, m) = map(int, input().split())
A = [[0 for i in range(n)] for i in range(m)]
for i in range(n):
	temp = str(input())
	for k in range(m):
		A[k][i] = temp[k]
Score = list(map(int, input().split()))
a = 0
for l in range(m):
	a += mode(A[l]) * Score[l]
print(a)


(n, m) = map(int, input().split())
s = []
ans = 0
for i in range(n):
	l = input()
	s.append(l)
marks = list(map(int, input().split()))
p = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
for i in range(m):
	sc = [0, 0, 0, 0, 0]
	for j in range(n):
		sc[p[s[j][i]]] += 1
	ans += max(sc) * marks[i]
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
l = [''] * m
for _ in range(n):
	s = input()
	for i in range(m):
		l[i] += s[i]
x = 0
a = list(map(int, input().split()))
for i in range(m):
	cc = Counter(l[i])
	x += a[i] * max(cc.values())
print(x)


(number_of_students, number_of_questions) = input().split(' ')
number_of_students = int(number_of_students)
number_of_questions = int(number_of_questions)
answers = []
i_counter = 0
while i_counter < number_of_students:
	answers.append(input())
	i_counter += 1
points = input().split(' ')

def check(position: int, array: list):
	diction = {}
	for i in array:
		if i[position] not in diction:
			diction[i[position]] = 1
		else:
			diction[i[position]] += 1
	keys = []
	for i in diction:
		keys.append(i)
	max = 0
	for i in keys:
		if diction[i] >= max:
			max = diction[i]
	return max
result = 0
for i in range(0, number_of_questions):
	result += check(i, answers) * int(points[i])
print(result)


(n, m) = map(int, input().split())
ans = 'ABCDE'
d = dict(((ans[i], i) for i in range(5)))
M = [[0 for _ in range(5)] for _ in range(m)]
for _ in range(n):
	i = 0
	for s in input():
		M[i][d[s]] += 1
		i += 1
a = list(map(int, input().split()))
result = 0
for i in range(m):
	result += a[i] * max(M[i])
print(result)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
(n, m) = [nextInt() for _ in range(2)]
student_ans = [next_str() for _ in range(n)]
a = [nextInt() for _ in range(m)]
count = {i: {j: sum([1 if student_ans[k][i] == j else 0 for k in range(n)]) for j in ['A', 'B', 'C', 'D', 'E']} for i in range(m)}
res = sum([max([a[q] * count[q][c] for c in ['A', 'B', 'C', 'D', 'E']]) for q in range(m)])
print(res)


def keywithmaxval(d):
	v = list(d.values())
	k = list(d.keys())
	return k[v.index(max(v))]
inp = input().split()
n = int(inp[0])
m = int(inp[1])
ans = []
l = []
for i in range(m):
	dic = dict.fromkeys(['A', 'B', 'C', 'D', 'E'], 0)
	l.append(dic)
for n0 in range(n):
	s = input()
	for i in range(len(s)):
		l[i][s[i]] += 1
points = [int(i) for i in input().split()]
sm = 0
for i in range(m):
	k = keywithmaxval(l[i])
	sm += l[i][k] * points[i]
print(sm)


from collections import Counter
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
scores = [int(i) for i in input().split()]
q = list(map(list, zip(*a)))
(j, res) = (0, 0)
for _ in q:
	c = Counter(_)
	res = res + c.most_common()[0][1] * scores[j]
	j += 1
print(res)


from collections import defaultdict as dd
(n, m) = map(int, input().strip().split())
ans = dd(dict)
for i in range(0, n):
	f = input().strip()
	for j in range(0, m):
		try:
			ans[j][f[j]] += 1
		except:
			ans[j][f[j]] = 1
points = 0
score = list(map(int, input().strip().split()))
for j in range(0, m):
	points = points + max(ans[j].values()) * score[j]
print(points)


(a, b) = map(int, input().split())
list1 = [input() for i in range(a)]
list2 = []
for i in zip(*list1):
	maximum = 0
	for j in set(i):
		maximum = max(i.count(j), maximum)
	list2.append(maximum)
list3 = map(int, input().split())
print(sum((i * j for (i, j) in zip(list2, list3))))


(n, m) = map(int, input().split())
m1 = [0 for i in range(n)]
for _ in range(n):
	m1[_] = list(input())
t = list(map(int, input().split()))
max_marks = 0
(a, b, c, d) = (0, 0, 0, 0)
for j in range(m):
	l = [row[j] for row in m1]
	(a, b, c, d, e) = (l.count('A'), l.count('B'), l.count('C'), l.count('D'), l.count('E'))
	max_marks += t[j] * max(a, b, c, d, e)
print(max_marks)


from sys import stdin, stdout
(N, M) = [int(x) for x in stdin.readline().split()]
data = [[0] * 5 for _ in range(M)]
for i in range(N):
	s = input()
	for j in range(M):
		if s[j] == 'A':
			data[j][0] += 1
		if s[j] == 'B':
			data[j][1] += 1
		if s[j] == 'C':
			data[j][2] += 1
		if s[j] == 'D':
			data[j][3] += 1
		if s[j] == 'E':
			data[j][4] += 1
arr = [int(x) for x in stdin.readline().split()]
res = 0
for i in range(M):
	m = max(data[i])
	res += m * arr[i]
print(res)


(students, questions) = tuple(map(int, input().split(' ')))
questionMaps = []

def getQuestionMap():
	return {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
for i in range(questions):
	questionMaps.append(getQuestionMap())
for i in range(students):
	answerSheet = input()
	for j in range(questions):
		questionMaps[j][answerSheet[j]] += 1

def findAnswerFor(thisMap):
	maxCount = 0
	for letter in 'ABCDE':
		maxCount = max(maxCount, thisMap[letter])
	return maxCount
points = tuple(map(int, input().split(' ')))
classScore = 0
for i in range(questions):
	classScore += findAnswerFor(questionMaps[i]) * points[i]
print(classScore)


from collections import defaultdict
(K, N) = map(int, input().split())
List = []
for i in range(K):
	temp = input()
	List.append(temp)
Cost = [int(x) for x in input().split()]
Ans = 0
for i in range(N):
	X = []
	Dict = defaultdict(int)
	for j in range(len(List)):
		X.append(List[j][i])
	for p in X:
		Dict[p] += 1
	Max = 0
	for t in Dict.keys():
		Max = max(Max, Dict[t])
	Ans += Cost[i] * Max
print(Ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
choices = []
for _ in range(n):
	choices.append(input().rstrip())
scores = list(map(int, input().split()))
ans = 0
for i in range(m):
	freq = {}
	for choice in choices:
		if choice[i] not in freq:
			freq[choice[i]] = 1
		else:
			freq[choice[i]] += 1
	ans += max(freq.values()) * scores[i]
print(ans)


from collections import Counter
R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
(n, m) = R1()
results = [input() for _ in range(n)]
values = R1()
res = 0
for i in range(m):
	res += values[i] * max(Counter((s[i] for s in results)).values())
print(res)


(n, m) = map(int, input().split())
s = [0] * n
l = [[0] * 5 for i in range(m)]
ans = 0
for i in range(0, n):
	s[i] = input()
a = list(map(int, input().split()))
i = 0
k = 0
while i < m:
	mx = 0
	for j in range(0, n):
		k = ord(s[j][i]) - 65
		l[i][k] += 1
	for j in range(5):
		mx = max(mx, l[i][j])
	ans += mx * a[i]
	i += 1
print(ans)


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
S = [input() for i in range(n)]
a = list(map(int, input().split()))
from collections import defaultdict
ans = 0
for i in range(m):
	dd = defaultdict(int)
	for j in range(n):
		dd[S[j][i]] += 1
	max_num = 0
	for key in dd:
		max_num = max(dd[key], max_num)
	ans += max_num * a[i]
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
l = []
for x in range(n):
	l.append(input().strip())
points = list(map(int, input().split()))
cnts = [0 for i in range(m)]
t = [0, 0, 0, 0, 0]
for i in range(m):
	t = [0, 0, 0, 0, 0]
	for x in l:
		choice = x[i]
		t[ord(choice) - 65] += 1
	cnts[i] = max(t)
print(sum((i[0] * i[1] for i in zip(points, cnts))))


from collections import Counter

def main():
	(n, m) = [int(i) for i in input().split()]
	s = [input() for i in range(n)]
	a = [int(i) for i in input().split()]
	s_zip = [[i[j] for i in s] for j in range(m)]
	freq = [Counter(i).most_common()[0][1] for i in s_zip]
	print(sum([a[i] * freq[i] for i in range(m)]))
main()


import sys
from collections import defaultdict

def main():
	(n, m) = map(int, input().split())
	cnt = [defaultdict(int) for _ in range(m)]
	for _ in range(n):
		for (i, x) in enumerate(input()):
			cnt[i][x] += 1
	w = list(map(int, input().split()))
	print(sum((w[i] * max(cnt[i].values()) for i in range(m))))
main()


(n, m) = list(map(int, input().split()))
d = dict()
l = []
l = [0] * m
for i in range(m):
	l[i] = dict()
	l[i]['A'] = 0
	l[i]['B'] = 0
	l[i]['C'] = 0
	l[i]['D'] = 0
	l[i]['E'] = 0
for j in range(n):
	a = input()
	j = 0
	for i in range(len(a)):
		l[j][str(a[i])] += 1
		j += 1
lp = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += lp[i] * max([j for j in l[i].values()])
print(ans)


(n, m) = map(int, input().split())
l = []
ans = 0
for i in range(n):
	l.append(list(input()))
marks = list(map(int, input().split()))
for i in range(m):
	(ca, cb, cc, cd, ce) = (0, 0, 0, 0, 0)
	for j in range(n):
		if l[j][i] == 'A':
			ca += 1
		if l[j][i] == 'B':
			cb += 1
		if l[j][i] == 'C':
			cc += 1
		if l[j][i] == 'D':
			cd += 1
		if l[j][i] == 'E':
			ce += 1
	ans += max(ca, cb, cc, cd, ce) * marks[i]
print(ans)


(n, m) = map(int, input().split())
all_ans = []
for i in range(n):
	ans = input()
	all_ans.append(ans)
scores = list(map(int, input().split()))
ans = 0
for i in range(m):
	dic = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(0, n):
		dic[all_ans[j][i]] += 1
	max_c = 1
	max_c = max(max_c, dic['A'], dic['B'], dic['C'], dic['D'], dic['E'])
	ans += max_c * scores[i]
print(ans)


(n, q) = map(int, input().split())
lst = []
for i in range(n):
	s = input()
	lst.append(s)
pts = list(map(int, input().split()))
w = 0
for i in range(q):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[lst[j][i]] += 1
	w += max(d.values()) * pts[i]
print(w)


(n, m) = map(int, input().split())
x = ''
for i in range(n):
	l = str(input())
	x += l
ans = []
z = []
L = list(map(int, input().split()))
for j in range(0, m, 1):
	for i in range(j, n * m, m):
		z.append(x[i])
	ans.append(max(z.count('A'), z.count('B'), z.count('C'), z.count('D'), z.count('E')))
	z = []
Ans = 0
for i in range(m):
	Ans += ans[i] * L[i]
print(Ans)


(n, m) = [int(i) for i in input().split()]
dic = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
questoes = [{l: 0 for l in ('A', 'B', 'C', 'D', 'E')} for i in range(m)]
for i in range(n):
	r = list(input())
	for (ind, v) in enumerate(r):
		questoes[ind][v] += 1
pontos = [int(i) for i in input().split()]
soma = 0
for i in range(m):
	soma += max(questoes[i].values()) * pontos[i]
print(soma)


import sys
fi = sys.stdin
s = fi.readline()[0:-1]
(n, m) = [int(si) for si in s.split(' ')]
ans = []
for i in range(n):
	s = fi.readline()[0:-1]
	ans.append(s)
s = fi.readline()[0:-1]
scores = [int(si) for si in s.split(' ')]
fi.close()
max_scores = 0
for qi in range(m):
	marks = {}
	for ni in range(n):
		if marks.get(ans[ni][qi]) is None:
			marks[ans[ni][qi]] = 1
		else:
			marks[ans[ni][qi]] = marks[ans[ni][qi]] + 1
	vmax = 0
	for q in marks.keys():
		if vmax < marks[q]:
			vmax = marks[q]
	max_scores = max_scores + vmax * scores[qi]
print(max_scores)


[n, m] = list(map(int, input().split()))
mi = []
for i in range(n):
	mi.append(list(input()))
mark = list(map(int, input().split()))
ans = 0
for i in range(m):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for j in range(n):
		if mi[j][i] == 'A':
			a = a + 1
		if mi[j][i] == 'B':
			b = b + 1
		if mi[j][i] == 'C':
			c = c + 1
		if mi[j][i] == 'D':
			d = d + 1
		if mi[j][i] == 'E':
			e = e + 1
	res = max(a, b, c, d, e)
	ans = ans + res * mark[i]
print(ans)


def splitter(word):
	return [char for char in word]

def most_common(lst):
	return max(set(lst), key=lst.count)
nm = input()
nm = nm.split()
n = int(nm[0])
m = int(nm[1])
grades = []
tally = int(0)
for i in range(n):
	grades.append(input())
	grades[i] = splitter(grades[i])
grade2 = list(zip(*grades))
values = input()
values = values.split()
for i in range(m):
	holder = grade2[i].count(most_common(grade2[i])) * int(values[i])
	tally = tally + holder
print(tally)


(n, m) = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(input())
ans = 0
ent = list(map(int, input().split()))
count = [0] * 5
for i in range(m):
	for j in range(n):
		count[ord(arr[j][i]) - 65] += ent[i]
	ans += max(count)
	count = [0, 0, 0, 0, 0]
print(ans)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	ss = input()
	ss = list(ss)
	s.append(ss)
sss = map(int, input().split())
sss = list(sss)
d = []
e = []
g = []
for j in range(m):
	for i in range(n):
		d.append(s[i][j])
	e.append(d.count('A'))
	e.append(d.count('B'))
	e.append(d.count('C'))
	e.append(d.count('D'))
	e.append(d.count('E'))
	g.append(max(e))
	e.clear()
	d.clear()
c = 0
for i in range(len(g)):
	c = c + g[i] * sss[i]
print(c)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	x = input()
	a.append(x)
s = list(map(int, input().split()))
c = 0
for i in range(m):
	m = {}
	for j in range(n):
		if a[j][i] in m:
			m[a[j][i]] += 1
		else:
			m[a[j][i]] = 1
	v = list(m.values())
	c += max(v) * s[i]
print(c)


(n, m) = map(int, input().split())
s = ''
for i in range(n):
	s = s + str(input())
j = 0
pts = list(map(int, input().split()))
answer = 0
for k in range(int(m)):
	j = k
	l = []
	while j < len(s):
		l.append(s[j])
		j = j + m
	ans = max(set(l), key=l.count)
	answer = answer + l.count(ans) * pts[k]
print(answer)


(n, m) = input().split(' ')
ans_list = []
for i in range(int(n)):
	ans_list.append(input())
marks_list = list(map(int, input().split()))
maxii = 0
for j in range(int(m)):
	count_dict = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for i in range(int(n)):
		count_dict[ans_list[i][j]] += 1
	count_list = map(int, list(count_dict.values()))
	maxii += max(count_list) * marks_list[j]
print(maxii)


(a, b) = map(int, input().split())
A = []
for i in range(b):
	A.append([0, 0, 0, 0, 0])
for i in range(a):
	q = input()
	for j in range(b):
		A[j][ord(q[j]) - 65] += 1
k = 0
C = list(map(int, input().split()))
for i in range(b):
	k += C[i] * max(A[i])
print(k)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def solve():
	(n, m) = takeivr()
	arr = []
	for i in range(n):
		arr.append(takesr())
	arr_1 = takeiar()
	ans = 0
	for i in range(m):
		dict_1 = dd(lambda : 0)
		for j in range(n):
			dict_1[arr[j][i]] += 1
		ans += max(dict_1.values()) * arr_1[i]
	print(ans)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


(n, m) = list(map(int, input().split()))
mat = []
for i in range(n):
	l = list(map(str, input()))
	mat.append(l)
points = list(map(int, input().split()))
d = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
ans = 0
for i in range(m):
	l = [0] * 5
	for j in range(n):
		x = mat[j][i]
		l[d[x]] += 1
	for j in range(5):
		l[j] = l[j] * points[i]
	ans += max(l)
print(ans)


(n, m) = map(int, input().split())
a = []
ans = 0
for i in range(n):
	a.append(list(input()))
scores = list(map(int, input().split()))
for i in range(m):
	answers = dict.fromkeys(list('ABCDE'), 0)
	ma = 0
	for j in range(n):
		answers[a[j][i]] += 1
		if answers[a[j][i]] > ma:
			ma = answers[a[j][i]]
	ans += scores[i] * ma
print(ans)


(n, m) = map(int, input().split())
x = []
for i in range(n):
	s = input()
	x.append(s)
oz = list(map(int, input().split()))
ot = 0
for i in range(m):
	d = dict()
	d['A'] = 0
	d['B'] = 0
	(d['C'], d['D'], d['E']) = (0, 0, 0)
	for j in x:
		s = j[i]
		d[s] += 1
	s = max(d.items(), key=lambda d: d[1])
	ot += int(s[-1]) * oz[i]
print(ot)


s = input()
n = int(s.split()[0])
m = int(s.split()[1])
lst1 = []
for i in range(n):
	lst1.append(input())
lst2 = list(map(int, input().split()))
mark = 0
for j in range(m):
	lst3 = [0, 0, 0, 0, 0]
	for i in range(n):
		if lst1[i][j] == 'A':
			lst3[0] += 1
		elif lst1[i][j] == 'B':
			lst3[1] += 1
		elif lst1[i][j] == 'C':
			lst3[2] += 1
		elif lst1[i][j] == 'D':
			lst3[3] += 1
		elif lst1[i][j] == 'E':
			lst3[4] += 1
	mark += max(lst3) * lst2[j]
print(mark)


(n, m) = [int(i) for i in input().split()]
S = []
for i in range(n):
	S.append(input())
K = [int(i) for i in input().split()]
summ = 0
for i in range(m):
	P = ''
	for j in range(n):
		P += S[j][i]
	summ += K[i] * max(P.count('A'), P.count('B'), P.count('C'), P.count('D'), P.count('E'))
print(summ)


import sys
(n, m) = map(int, sys.stdin.readline().split())
ans = []
for i in range(m):
	ans.append({})
for i in range(n):
	student_answers = sys.stdin.readline().strip()
	for answer_index in range(len(student_answers)):
		try:
			ans[answer_index][student_answers[answer_index]] += 1
		except:
			ans[answer_index][student_answers[answer_index]] = 1
points = sys.stdin.readline().split()
points = [int(x) for x in points]
max_points = 0
for question_num in range(len(ans)):
	mx = 0
	for letter in ans[question_num]:
		if mx < ans[question_num][letter]:
			mx = ans[question_num][letter]
	max_points += mx * points[question_num]
print(max_points)


(n, m) = input().split()
(n, m) = map(int, [n, m])
ans_list = [input() for i in range(n)]
scores_list = input()
scores_list = list(map(int, scores_list.split(' ')))
list1 = []
ans = ''
c = 0
for j in range(m):
	for k in range(n):
		ans += ans_list[k][j]
	list1.append(ans)
	ans = ''
c1 = 0
for l in list1:
	a_counter = l.count('A')
	b_counter = l.count('B')
	c_counter = l.count('C')
	d_counter = l.count('D')
	e_counter = l.count('E')
	c += max(a_counter, b_counter, c_counter, d_counter, e_counter) * scores_list[c1]
	c1 += 1
print(c)


(n, t) = map(int, input().split())
w = []
i = 0
while i < n:
	a = str(input())
	w.append(a)
	i += 1
b = list(map(int, input().split()))
i = 0
s = 0
while i < t:
	c = ''
	j = 0
	while j < n:
		c += w[j][i]
		j += 1
	c = sorted(c)
	tb = 1
	bg = 1
	j = 1
	while j < len(c):
		if c[j] == c[j - 1]:
			tb += 1
		else:
			if tb > bg:
				bg = tb
			tb = 1
		j += 1
	if tb > bg:
		bg = tb
	s += bg * b[i]
	i += 1
print(s)


(n, m) = map(int, input().split())
a = [[0] * 5 for i in range(m)]
d = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
for _ in range(n):
	s = input()
	for i in range(len(s)):
		a[i][d[s[i]]] += 1
b = list(map(int, input().split()))
print(sum((max(a[i]) * b[i] for i in range(len(a)))))


(n, m) = map(int, input().split())
answers = [input() for _ in range(n)]
a = list(map(int, input().split()))
cnt = [[0, 0, 0, 0, 0] for _ in range(m)]
for i in range(m):
	for j in answers:
		cnt[i][ord(j[i]) - ord('A')] += 1
s = 0
for i in range(m):
	s += max(cnt[i]) * a[i]
print(s)


import collections
import operator
nu = list(map(int, input().split(' ')))
n = nu[0]
m = nu[1]
ans = []
for i in range(n):
	an = input()
	ans.append(an)
marks = list(map(int, input().split(' ')))
b = len(ans[0])

def add(temp):
	s = []
	for i in range(0, len(temp)):
		s.append(temp[i][0])
	s1.append(s)
s1 = []
while b != 0:
	add(ans)
	for i in range(len(ans)):
		ans[i] = ans[i][1:]
	b -= 1
mc = []
for j in range(len(s1)):
	dd = dict(collections.Counter(s1[j]))
	mc.append(dd)
for i in range(len(mc)):
	sorted_x = sorted(mc[i].items(), key=operator.itemgetter(1))
	mc[i] = sorted_x
sum1 = 0
hh = 0
for j in range(len(mc)):
	a = mc[j][len(mc[j]) - 1][1]
	sum1 += a * marks[hh]
	hh += 1
print(sum1)


(n, m) = map(int, input().split())
s = []
for _ in range(n):
	s.append(input())
a = list(map(int, input().split()))
answer = 0
for i in range(m):
	counter = {}
	for j in range(n):
		counter[s[j][i]] = counter.get(s[j][i], 0) + 1
	answer += a[i] * max(counter.values())
print(answer)


(n, m) = (int(i) for i in input().split())
s = 0
l = ['' for i in range(n)]
for i in range(n):
	l[i] = input()
l1 = [int(i) for i in input().split()]
for i in range(m):
	l2 = [0] * 5
	for j in range(n):
		l2[ord(l[j][i]) - 65] += 1
	s += l1[i] * max(l2)
print(s)


(n, m) = map(int, input().split())
number = []
for i in range(m):
	number.append([0, 0, 0, 0, 0])
for i in range(n):
	s = input()
	for j in range(m):
		number[j][ord(s[j]) - 65] += 1
max_number = []
for i in number:
	max_number.append(max(i))
score = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += score[i] * max_number[i]
print(ans)


import sys
from collections import Counter
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
li = [list(input()) for i in range(n)]
li = list(zip(*li))
answer = list(map(int, input().split()))
summ = 0
for i in range(m):
	summ += Counter(list(li[i])).most_common(1)[0][1] * answer[i]
print(summ)


In = input().strip().split(' ')
n = int(In[0])
m = int(In[1])
b = [0 for i in range(n)]
C = [[0] * 5 for i in range(m)]
num = [0 for i in range(n)]
for i in range(n):
	b[i] = input()
	for j in range(m):
		C[j][ord(b[i][j]) - ord('A')] += 1
ans = 0
score = input().strip().split(' ')
for i in range(m):
	mx = 0
	for j in range(5):
		mx = max(mx, C[i][j])
	ans += mx * int(score[i])
print(ans)


(n, m) = map(int, input().split())
strs = []
pesos = []
aux = ''
for i in range(n):
	aux = str(input())
	strs.append(aux)
pesos = list(map(int, input().split()))
maps = []
for i in range(m):
	maps.append({'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0})
	for j in range(n):
		maps[i][strs[j][i]] += 1
out = 0
for i in range(m):
	maximum = -1
	for key in maps[i].keys():
		maximum = max(maximum, maps[i][key])
	out += maximum * pesos[i]
print(out)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
p = list(map(int, input().split()))
ans = 0
for i in range(m):
	a = [0] * 5
	for j in range(n):
		a[ord(s[j][i]) - 65] += 1
	x = max(a)
	ans += p[i] * x
print(ans)


alumni = input().split(' ')
answers = []
for i in range(len(alumni)):
	alumni[i] = int(alumni[i])
for i in range(alumni[0]):
	answers.append(input())
vals = input().split(' ')
score = 0
for i in range(len(vals)):
	vals[i] = int(vals[i])
for i in range(alumni[1]):
	dic = {}
	for j in range(alumni[0]):
		if answers[j][i] in dic:
			dic[answers[j][i]] += 1
		else:
			dic[answers[j][i]] = 1
	maxx = 0
	for a in dic:
		if dic[a] > maxx:
			maxx = dic[a]
	score += maxx * vals[i]
print(score)


(n, m) = (int(i) for i in input().split())
ans = []
for i in range(n):
	k = input()
	ans.append(list(k))
a = [int(i) for i in input().split()]
ma = 0
for i in range(m):
	b = [ans[j][i] for j in range(n)]
	c = []
	count = 0
	for j in range(n):
		if b[j] not in c:
			c.append(b[j])
			k = b.count(b[j])
			if count <= k:
				count = k
	ma = ma + count * a[i]
print(ma)


def solve(n, m, l, q):
	ans = 0
	i = 0
	j = 0
	for i in range(m):
		x1 = [0] * 5
		for j in range(n):
			if l[j][i] == 'A':
				x1[0] = x1[0] + 1
			elif l[j][i] == 'B':
				x1[1] = x1[1] + 1
			elif l[j][i] == 'C':
				x1[2] = x1[2] + 1
			elif l[j][i] == 'D':
				x1[3] = x1[3] + 1
			elif l[j][i] == 'E':
				x1[4] = x1[4] + 1
		x2 = 0
		j = 0
		for j in range(5):
			x2 = max(x2, x1[j])
		ans = ans + x2 * q[i]
		j = 0
	return ans
y = list(map(int, input().split()))
n = y[0]
m = y[1]
i = 0
l = []
for i in range(n):
	s1 = input()
	l.append(s1)
q = list(map(int, input().split()))
ans = solve(n, m, l, q)
print(ans)


from collections import defaultdict
(n, m) = list(map(int, input().split(' ')))
a = []
sum = 0
for i in range(n):
	s = input()
	a.append(s)
p = list(map(int, input().split(' ')))
for i in range(m):
	Dict = defaultdict(int)
	for j in range(n):
		Dict[a[j][i]] += 1
	sum += max(Dict.values()) * p[i]
print(sum)


(n, m) = map(int, input().split())
from collections import Counter
l = []
for i in range(n):
	a = input()
	l.append(a)
mar = list(map(int, input().split()))
cost = 0
for j in range(m):
	al = []
	for i in range(n):
		al.append(l[i][j])
	a = al.count('A')
	b = al.count('B')
	c = al.count('C')
	d = al.count('D')
	e = al.count('E')
	cost += max(a, b, c, d, e) * mar[j]
print(cost)


z = []
(n, m) = map(int, input().split())
for _ in range(n):
	s = input()
	z.append(s)
p1 = list(map(int, input().split()))
k = list(zip(*z))
p = s = 0
d = {}
for x in range(m):
	for y in k[x]:
		if y in d:
			d[y] += 1
		else:
			d[y] = 1
	for q in d:
		if d[q] > p:
			p = d[q]
	s += p * p1[x]
	p = 0
	d = {}
print(s)


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
from collections import Counter
LIST = [[] for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		LIST[j].append(s[j])
SCORE = list(map(int, input().split()))
ANS = 0
for i in range(m):
	ANS += max(Counter(LIST[i]).values()) * SCORE[i]
print(ANS)


[n, m] = list(map(int, input().rstrip().split()))
res = []
for i in range(n):
	res.append(input())
points = list(map(int, input().rstrip().split()))
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = [0 for i in range(m)]
d = [0 for i in range(m)]
e = [0 for i in range(m)]
for i in range(n):
	for j in range(m):
		if res[i][j] == 'A':
			a[j] += 1
		elif res[i][j] == 'B':
			b[j] += 1
		elif res[i][j] == 'C':
			c[j] += 1
		elif res[i][j] == 'D':
			d[j] += 1
		elif res[i][j] == 'E':
			e[j] += 1
massimi = []
for i in range(m):
	massimi.append(max(a[i], b[i], c[i], d[i], e[i]))
risultato = [massimi[i] * points[i] for i in range(m)]
print(sum(risultato))


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(input()))
marks = list(map(int, input().split()))
su = 0
for i in range(m):
	lp = []
	for j in range(n):
		lp.append(l[j][i])
	su += max(lp.count('A'), lp.count('B'), lp.count('C'), lp.count('D'), lp.count('E')) * marks[i]
print(su)


(n, m) = [int(i) for i in input().split()]
answers = []
s = 0
for i in range(n):
	answers.append(input())
correct = [int(i) for i in input().split()]
for i in range(m):
	chast = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for l in answers:
		chast[l[i]] += 1
	s += max(chast.values()) * correct[i]
print(s)


from collections import Counter
(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(input()))
marks = list(map(int, input().split()))
ma = 0
for i in range(m):
	x = []
	for j in range(n):
		x.append(a[j][i])
	d = dict(Counter(x))
	d = list(d.values())
	ma += marks[i] * max(d)
print(ma)


(n, m) = map(int, input().strip().split(' '))
lst = []
lst2 = []
for i in range(n):
	t = input()
	t = list(t)
	lst.append(t)
lst1 = list(map(int, input().strip().split(' ')))
s = 0
for i in range(m):
	lst2.append([item[i] for item in lst])
for i in range(m):
	t1 = max(set(lst2[i]), key=lst2[i].count)
	s += lst2[i].count(t1) * lst1[i]
print(s)


(n, m) = map(int, input().split())
answers = [input() for f in range(n)]
points = list(map(int, input().split()))
total = 0
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[answers[j][i]] += 1
	total += max(d.values()) * points[i]
print(total)


(n, m) = map(int, input().split())
ss = []
for _ in range(n):
	ss.append(input())
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	d = {}
	for x in [s[i] for s in ss]:
		d[x] = d.get(x, 0) + 1
	ans += max(d.values()) * a[i]
print(ans)


(n, m) = map(int, input().split())
answer = list()
for i in range(n):
	answer.append(input())
qu = list(map(int, input().split()))
s = 0
for i in range(m):
	res = [0, 0, 0, 0, 0]
	for j in range(n):
		res[ord(answer[j][i]) - 65] += 1
	s += max(res) * qu[i]
print(s)


import sys
import math
input = sys.stdin.readline
(n, m) = map(int, input().strip().split())
ans = 0
x = []
for i in range(n):
	x.append(input())
a = list(map(int, input().strip().split()))
for i in range(m):
	dema = demb = demc = demd = deme = 0
	for str in x:
		if str[i] == 'A':
			dema += 1
		elif str[i] == 'B':
			demb += 1
		elif str[i] == 'C':
			demc += 1
		elif str[i] == 'D':
			demd += 1
		else:
			deme += 1
	ans += a[i] * max(dema, max(demb, max(demc, max(demd, deme))))
print(ans)


(n, m) = list(map(int, input().split()))
l1 = []
for i in range(n):
	l1.append(input().strip())
a = list(map(int, input().split()))
res = 0
for i in range(m):
	(A, B, C, D, E) = (0, 0, 0, 0, 0)
	for j in range(n):
		if l1[j][i] == 'A':
			A += 1
		if l1[j][i] == 'B':
			B += 1
		if l1[j][i] == 'C':
			C += 1
		if l1[j][i] == 'D':
			D += 1
		if l1[j][i] == 'E':
			E += 1
	res += max(A, B, C, D, E) * a[i]
print(res)


(n, m) = map(int, input().split())
s = []
for i in range(0, n):
	temp = list(input())
	s.append(temp)
a = list(map(int, input().split()))
ans = 0
for i in range(0, m):
	temp = {}
	for j in range(0, n):
		if s[j][i] in temp:
			temp[s[j][i]] += 1
		else:
			temp[s[j][i]] = 1
	ans = ans + max(temp.values()) * a[i]
print(ans)


(n, m) = list(map(int, input().split(' ')))
mas = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		mas[j][s[j]] += 1
a = list(map(int, input().split(' ')))
summ = 0
for i in range(m):
	summ += max(mas[i].values()) * a[i]
print(summ)


(n, m) = map(int, input().split())
a = []
d = [{} for i in range(m)]
ans = [0] * m
for i in range(n):
	c = input()
	for j in range(m):
		d[j][c[j]] = d[j].get(c[j], 0) + 1
		ans[j] = max(ans[j], d[j][c[j]])
b = list(map(int, input().split()))
res = 0
for i in range(m):
	res += b[i] * ans[i]
print(res)


(n, m) = map(int, input().split())
c = list()
d = list()
for i in range(n):
	c.append(input())
z = list(map(int, input().split()))
sum1 = 0
for j in range(m):
	d = dict()
	for k in range(n):
		if c[k][j] in d:
			d[c[k][j]] += 1
		else:
			d[c[k][j]] = 1
	largest = 0
	for k in d:
		if d[k] > largest:
			largest = d[k]
	sum1 += largest * z[j]
print(sum1)


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(input())
g = [int(x) for x in input().split()]
for i in range(m):
	k = [0] * 5
	for j in range(n):
		if l[j][i] == 'A':
			k[0] += 1
		elif l[j][i] == 'B':
			k[1] += 1
		elif l[j][i] == 'C':
			k[2] += 1
		elif l[j][i] == 'D':
			k[3] += 1
		else:
			k[4] += 1
	g[i] = g[i] * max(k)
print(sum(g))


import sys
input = lambda : sys.stdin.readline().strip()

def most(ls):
	d = {i: 0 for i in ls}
	for i in ls:
		d[i] += 1
	M = max(d.values())
	for (k, v) in d.items():
		if v == M:
			return k
(n, m) = map(int, input().split())
cnt = []
for i in range(m):
	cnt.append([])
d = {'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5}
for i in range(n):
	s = input()
	for j in range(m):
		cnt[j].append(d[s[j]])
ls2 = list(map(int, input().split()))
print(sum((ls2[i] * cnt[i].count(most(cnt[i])) for i in range(m))))


def compute(input_data):

	def get_most_freq(loc_data, loc_quest_num):
		loc_dict = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
		for line in loc_data:
			loc_dict[line[loc_quest_num]] += 1
		return max(loc_dict.values())
	lines = input_data.split('\n')
	(stud_count, quest_count) = map(int, lines[0].split(' '))
	quest_price = list(map(int, lines[-1].split(' ')))
	data = lines[1:-1]
	result_score = 0
	for quest_num in range(quest_count):
		result_score += quest_price[quest_num] * get_most_freq(data, quest_num)
	print(result_score)
	return result_score
string = input() + '\n'
(n, m) = string.split(' ')
for gl_line in range(int(n)):
	string += input() + '\n'
string += input()
compute(string)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [''.join((a[j][i] for j in range(n))) for i in range(m)]
prices = list(map(int, input().split()))
s = 0
for (i, question) in enumerate(b):
	d = {}
	for answer in question:
		d[answer] = d.get(answer, 0) + 1
	s += max(d.values()) * prices[i]
print(s)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor, log
from bisect import bisect_right, bisect_left, bisect
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)
MOD = 1000000007
PMOD = 998244353
N = 10 ** 6
LOGN = 30
alp = 'abcdefghijklmnopqrstuvwxyz'
T = 1
for _ in range(T):
	(n, m) = list(map(int, stdin.readline().rstrip().split()))
	a = []
	for i in range(n):
		s = list(stdin.readline().strip('\n'))
		a.append(s)
	p = list(map(int, stdin.readline().rstrip().split()))
	ans = 0
	for j in range(m):
		d = {}
		for i in range(n):
			if a[i][j] not in d:
				d[a[i][j]] = 1
			else:
				d[a[i][j]] += 1
		ans += max(d.values()) * p[j]
	print(ans)


a = input().split()
a = [int(i) for i in a]
n = a[0]
m = a[1]
l = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	x = input()
	for j in range(m):
		l[i][j] = x[j]
inp = list(map(int, input().split()))
sumi = 0
from collections import Counter
for j in range(m):
	x = [l[i][j] for i in range(n)]
	c = Counter(x)
	sumi += inp[j] * max(c.values())
print(sumi)


(n, m) = list(map(int, input().split()))
a = [''] * m
total_sum = 0
for i in range(n):
	x = input()
	for p in range(m):
		a[p] += x[p]
q = list(map(int, input().split()))
for k in range(m):
	a[k] = list(a[k])
	a[k].sort()
	a[k] = ''.join(a[k])
	(cur_min, cur_max) = (0, 1)
	for h in range(n - 1):
		if a[k][h] == a[k][h + 1]:
			cur_max += 1
		else:
			if cur_min < cur_max or cur_min == 0:
				cur_min = cur_max
			cur_max = 1
	if cur_min > cur_max:
		cur_max = cur_min
	total_sum += cur_max * q[k]
print(total_sum)


(students, questions) = [int(x) for x in input().split()]
cquestions = list()
ans = list()
for i in range(students):
	inp = list()
	temp = input()
	for j in range(questions):
		inp.append(temp[j])
	ans.append(inp)
for i in range(questions):
	A = 0
	B = 0
	C = 0
	D = 0
	E = 0
	for j in range(students):
		if ans[j][i] == 'A':
			A += 1
		if ans[j][i] == 'B':
			B += 1
		if ans[j][i] == 'C':
			C += 1
		if ans[j][i] == 'D':
			D += 1
		if ans[j][i] == 'E':
			E += 1
	cquestions.append(int(max(A, B, C, D, E)))
points = [int(x) for x in input().split()]
answer = 0
for i in range(questions):
	answer += int(cquestions[i] * points[i])
print(answer)


h = [int(i) for i in input().split()][:2]
n = h[0]
m = h[1]
l = []
for i in range(n):
	h = str(input())
	l.append(h)
marks = [int(i) for i in input().split()][:m]
sum = 0
for i in range(0, m):
	h = []
	for j in range(0, len(l)):
		h.append(l[j][i])
	h1 = []
	c = 0
	for k in h:
		if k not in h1:
			te = h.count(k)
			if te > c:
				c = te
			h1.append(k)
	sum = sum + c * marks[i]
print(sum)


fst = list(map(int, input().split()))
answers = ['' for i in range(fst[0])]
for i in range(fst[0]):
	answers[i] = input()
value = list(map(int, input().split()))
ans = 0
for i in range(len(value)):
	counter = {}
	for j in range(len(answers)):
		if answers[j][i] in counter:
			counter[answers[j][i]] += 1
		else:
			counter[answers[j][i]] = 1
	ans += value[i] * max(counter.values())
print(ans)


from sys import stdin, stdout

def solve(inp, out):
	(n, m) = map(int, inp().split())
	p = [[0] * 5 for i in range(m)]
	k = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
	for i in range(n):
		s = inp()
		for j in range(m):
			p[j][k[s[j]]] += 1
	g = list(map(int, inp().split()))
	ans = 0
	for i in range(m):
		ans += max(p[i]) * g[i]
	out(str(ans))

def main():
	inp = stdin.readline
	out = stdout.write
	t = 0
	if t == 0:
		test = 1
	else:
		test = int(inp())
	for _ in range(test):
		solve(inp, out)
main()


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
cost = list(map(int, input().split()))
ans = 0
for i in range(m):
	mx = 0
	for c in 'ABCDEF':
		cnt = 0
		for j in range(n):
			if s[j][i] == c:
				cnt += 1
		mx = max(mx, cnt)
	ans += mx * cost[i]
print(ans)


(n, m) = map(int, input().split())
s = [[0 for i in range(5)] for j in range(m)]
for i in range(n):
	q = input()
	for j in range(m):
		s[j][ord(q[j]) - 65] += 1
a = list(map(int, input().split()))
cnt = 0
for i in range(m):
	x = max(s[i])
	cnt += x * a[i]
print(cnt)


(n, m) = map(int, input().strip().split())
A = [0] * m
B = [0] * m
C = [0] * m
D = [0] * m
E = [0] * m
for i in range(n):
	x = input().strip()
	for j in range(m):
		if x[j] == 'A':
			A[j] = A[j] + 1
		if x[j] == 'B':
			B[j] = B[j] + 1
		if x[j] == 'C':
			C[j] = C[j] + 1
		if x[j] == 'D':
			D[j] = D[j] + 1
		if x[j] == 'E':
			E[j] = E[j] + 1
a = list(map(int, input().strip().split()))
s = 0
for i in range(m):
	s = s + a[i] * max(A[i], B[i], C[i], D[i], E[i])
print(s)


(n, m) = map(int, input().split())
lst = [0] * n
for i in range(n):
	lst[i] = input()
marks = list(map(int, input().split()))
itog = 0
for i in range(m):
	fDict = {}
	for j in lst:
		if j[i] in fDict.keys():
			fDict[j[i]] += 1
		else:
			fDict[j[i]] = 1
	val = max(fDict.values())
	itog += val * marks[i]
print(itog)


(n, m) = map(int, input().split(' '))
arr = []
maximum = 0
for i in range(0, n):
	arr.append(list(input()))
mark = list(map(int, input().split(' ')))
for j in range(0, m):
	cntA = 0
	cntB = 0
	cntC = 0
	cntD = 0
	cntE = 0
	cntF = 0
	cnt = mark[j]
	for i in range(0, n):
		if arr[i][j] == 'A':
			cntA += 1
		if arr[i][j] == 'B':
			cntB += 1
		if arr[i][j] == 'C':
			cntC += 1
		if arr[i][j] == 'D':
			cntD += 1
		if arr[i][j] == 'E':
			cntE += 1
		if arr[i][j] == 'F':
			cntF += 1
	maximum = maximum + max(cntA, cntB, cntC, cntD, cntE, cntF) * cnt
print(maximum)


ints = [int(x) for x in input().split()]
z = [[0, 0, 0, 0, 0] for i in range(ints[1])]
alpha = 'ABCDE'
for i in range(ints[0]):
	r = input()
	for j in range(ints[1]):
		z[j][alpha.index(r[j])] += 1
scores = [int(x) for x in input().split()]
for i in range(ints[1]):
	scores[i] = scores[i] * max(z[i])
print(sum(scores))


(n, m) = map(int, input().split())
p = []
ans = 0
for i in range(n):
	p.append(input())
A = list(map(int, input().split()))
for j in range(m):
	h = []
	for i in range(n):
		h.append(p[i][j])
	ans += A[j] * max(h.count('A'), h.count('B'), h.count('C'), h.count('D'), h.count('E'))
print(ans)


import sys
input = sys.stdin.readline
(n, m) = [int(i) for i in input().split()]
dict1 = {}
for i in range(m):
	dict1[i] = {}
for i in range(n):
	str1 = list(input())
	for j in range(m):
		if str1[j] in dict1[j]:
			dict1[j][str1[j]] += 1
		else:
			dict1[j][str1[j]] = 1
score = [int(i) for i in input().split()]
sum = 0
for i in range(m):
	sum += max(dict1[i].values()) * score[i]
print(sum)


from collections import Counter
from functools import reduce
(n, m) = [int(x) for x in input().split()]
scrs = [input() for _ in range(n)]
a = [int(x) for x in input().split()]
cnts = [Counter([x[i] for x in scrs]).most_common(1)[0][1] for i in range(m)]
print(reduce(lambda x, y: x + y[0] * y[1], zip(cnts, a), 0))


class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(n, m) = Read.list_int()
	ans = []
	for i in range(n):
		ans.append(input())
	b = Read.list_int()
	result = 0
	for i in range(m):
		f = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
		for j in range(n):
			f[ans[j][i]] += 1
		max_f = 0
		for k in f.values():
			if k > max_f:
				max_f = k
		result += max_f * b[i]
	print(result)
query_count = 1
for j in range(query_count):
	solve()


from collections import Counter
(nb_students, nb_question) = [int(x) for x in input().split()]
solved = [[x for x in input()] for _ in range(nb_students)]
vals = [max(Counter(x).values()) for x in zip(*solved)]
points = [int(x) for x in input().split()]
print(sum([x * y for (x, y) in zip(vals, points)]))


(n, m) = list(map(int, input().split()))
l = [1] * m
for i in range(0, m):
	l[i] = dict()
for i in range(0, n):
	s = input()
	for j in range(0, m):
		l[j][s[j]] = l[j].get(s[j], 0) + 1
a = list(map(int, input().split()))
s = 0
for j in range(0, m):
	s = max(l[j].values()) * a[j] + s
print(s)


t = [int(x) for x in input().split()]
n = t[0]
q = t[1]
l1 = [[0 for x in range(5)] for x in range(q)]
for x in range(n):
	s = list(input())
	a = 'ABCDE'
	i = 0
	while i < len(s):
		l1[i][a.index(s[i])] += 1
		i += 1
m = [int(x) for x in input().split()]
ans = 0
for x in range(len(m)):
	ans += m[x] * max(l1[x])
print(ans)


inp = input()
inp = inp.split(' ')
n = int(inp[0])
m = int(inp[1])
list_answer = []
list_marks = []
for i in range(n):
	list_answer.append(input())
list_marks = input()
list_marks = list_marks.split(' ')
output = []
ans = 0
K = 0
for i in range(m):
	option = [0, 0, 0, 0, 0]
	for j in range(n):
		if list_answer[j][i] == 'A':
			option[0] += 1
		elif list_answer[j][i] == 'B':
			option[1] += 1
		elif list_answer[j][i] == 'C':
			option[2] += 1
		elif list_answer[j][i] == 'D':
			option[3] += 1
		elif list_answer[j][i] == 'E':
			option[4] += 1
	output.append(int(max(option)) * int(list_marks[i]))
ans = sum(output)
print(int(ans))


from collections import Counter
from operator import mul
(n, _) = map(int, input().split())
S = [input() for _ in range(n)]
max_matches = [max(Counter(answers).values()) for answers in zip(*S)]
print(sum(map(mul, map(int, input().split()), max_matches)))


(n, m) = map(int, input().split())
data = []
for i in range(n):
	data.append(list(input()))
marks = list(map(int, input().split()))
rez = []
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[data[j][i]] += 1
	tm = 0
	for c in d:
		tm = max(tm, d[c])
	rez.append(tm)
ans = 0
for i in range(m):
	ans += rez[i] * marks[i]
print(ans)


(n, m) = map(int, input().split())
b = [0, 0, 0, 0, 0]
a = []
ans = 0
for i in range(n):
	a.append(input())
d = list(map(int, input().split()))
for j in range(m):
	b = [0 for k in range(5)]
	for i in range(n):
		if a[i][j] == 'A':
			b[0] += 1
		elif a[i][j] == 'B':
			b[1] += 1
		elif a[i][j] == 'C':
			b[2] += 1
		elif a[i][j] == 'D':
			b[3] += 1
		elif a[i][j] == 'E':
			b[4] += 1
	ans += d[j] * max(b)
print(ans)


(n, m) = map(int, input().split())
ar = []
for _ in range(n):
	ar.append(input())
vl = list(map(int, input().split()))
c = 0
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[ar[j][i]] += 1
	z = max(d['A'], d['B'], d['C'], d['D'], d['E'])
	c += z * vl[i]
print(c)


(n, m) = map(int, input().split())
answers = []
for i in range(n):
	s = input()
	answers.append(s)
scores = list(map(int, input().split()))
res = 0
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[answers[j][i]] += 1
	m = 1
	for k in d:
		m = max(m, d[k])
	res += m * scores[i]
print(res)


import collections
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
p = []
for j in range(m):
	s = ''
	for i in range(n):
		s += l[i][j]
	p.append(s)
l = [int(x) for x in input().split()]
count = 0
for i in range(len(l)):
	x = dict(collections.Counter(p[i]))
	x = list(x.values())
	count += l[i] * max(x)
print(count)


(n, m) = map(int, input().split())
tmp = [''] * m
final = 0
z = ('A', 'B', 'C', 'D', 'E')
for i in range(n):
	temp = input()
	for j in range(m):
		tmp[j] += temp[j]
score = list(map(int, input().split()))
for i in range(m):
	final += max((tmp[i].count(k) for k in z)) * score[i]
print(final)


(n, m) = list(map(int, input().strip().split(' ')))
students = []
for _ in range(n):
	students += [input()]
scores = list(map(int, input().strip().split(' ')))
ans = 0
from collections import defaultdict
for i in range(m):
	dic = defaultdict(int)
	for j in range(n):
		dic[students[j][i]] += 1
	ans += max([dic[x] for x in dic]) * scores[i]
print(ans)


(n, m) = map(int, input().split())
C = [0] * m * 5
sum = 0
for i in range(n):
	a = str(input())
	for i in range(m):
		if a[i] == 'A':
			C[i * 5] += 1
		elif a[i] == 'B':
			C[i * 5 + 1] += 1
		elif a[i] == 'C':
			C[i * 5 + 2] += 1
		elif a[i] == 'D':
			C[i * 5 + 3] += 1
		elif a[i] == 'E':
			C[i * 5 + 4] += 1
B = input().split()
for j in range(m):
	sum += max(C[5 * j], C[5 * j + 1], C[5 * j + 2], C[5 * j + 3], C[5 * j + 4]) * int(B[j])
print(sum)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
a = [0 for i in range(m)]
b = [] + a
c = [] + a
d = [] + a
e = [] + a
for i in range(n):
	temp = input()
	for j in range(m):
		if temp[j] == 'A':
			a[j] += 1
		elif temp[j] == 'B':
			b[j] += 1
		elif temp[j] == 'C':
			c[j] += 1
		elif temp[j] == 'D':
			d[j] += 1
		elif temp[j] == 'E':
			e[j] += 1
score = input().split()
final = 0
for i in range(m):
	maxim = max(a[i], b[i], c[i], d[i], e[i])
	tempsc = int(score[i])
	final += maxim * tempsc
print(final)


(n, m) = map(int, input().split())
answers = [dict() for x in range(m)]
for i in range(n):
	s = input()
	for j in range(len(s)):
		if s[j] not in answers[j]:
			answers[j][s[j]] = 1
		else:
			answers[j][s[j]] += 1
a = list(map(int, input().split()))
ans = 0
for i in range(len(answers)):
	vals = answers[i].values()
	ans += max(vals) * a[i]
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
x = []
y = []
for i in range(n):
	x.append(list(input()))
for i in zip(*x):
	y.append(max(Counter(i).values()))
print(sum((u * v for (u, v) in zip(y, map(int, input().split())))))


def main():
	(n, m) = map(int, input().split(' '))
	l = []
	ans = 0
	for _ in range(n):
		l.append(input())
	scores = list(map(int, input().split(' ')))
	for i in range(m):
		a = b = c = d = e = 0
		for k in range(n):
			if l[k][i] == 'A':
				a += 1
			elif l[k][i] == 'B':
				b += 1
			elif l[k][i] == 'C':
				c += 1
			elif l[k][i] == 'D':
				d += 1
			elif l[k][i] == 'E':
				e += 1
		ans += max([a, b, c, d, e]) * scores[i]
	print(ans)
main()


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append(input())
val = list(map(int, input().split()))
ans = 0
for i in range(m):
	cnt = [0] * 5
	for j in range(n):
		cnt[ord(a[j][i]) - 65] += 1
	ans += max(cnt) * val[i]
print(ans)


(n, m) = map(int, input().split())
d = []
for i in range(m):
	d.append({})
for i in range(n):
	s = input()
	for j in range(len(s)):
		if s[j] not in d[j]:
			d[j][s[j]] = 0
		d[j][s[j]] += 1
a = list(map(int, input().split()))
res = 0
for i in range(m):
	mm = 0
	for k in d[i]:
		mm = max(mm, d[i][k])
	res += mm * a[i]
print(res)


from collections import Counter
(n, m) = (int(s) for s in input().split())
s = []
for j in range(n):
	s.append(input())
a = [int(i) for i in input().split()]
y = list(zip(*s))
ans = 0
for i in range(m):
	count = Counter(y[i])
	ans = ans + count.most_common()[0][1] * int(a[i])
print(ans)


(n, m) = list(map(int, input().split()))
test = {}
for i in range(n):
	test[i] = list(input())
score = list(map(int, input().split()))
end = 0
for i in range(m):
	answers = []
	for k in range(len(test)):
		answers.append(test[k][i])
	a = [0, 0, 0, 0, 0]
	for j in answers:
		if j == 'A':
			a[0] += 1
		elif j == 'B':
			a[1] += 1
		elif j == 'C':
			a[2] += 1
		elif j == 'D':
			a[3] += 1
		elif j == 'E':
			a[4] += 1
	end += max(a) * score[i]
print(end)


import sys
(n, m) = map(int, sys.stdin.readline().split())
a = [[0 for x in range(5)] for y in range(m)]
for i in range(n):
	s = sys.stdin.readline()
	for j in range(m):
		ch = s[j]
		a[j][ord(ch) - 65] += 1
p = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(m):
	mx = 0
	for j in range(5):
		mx = a[i][j] if a[i][j] > mx else mx
	ans = ans + mx * p[i]
print(ans)


(n, m) = map(int, input().split())
arr = [0] * n
for i in range(n):
	arr[i] = input()
ppq = list(map(int, input().split()))
total_points = 0
for que in range(m):
	max_ans = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	max_occurence = 0
	for s in range(n):
		cao = max_ans[arr[s][que]] + 1
		if cao > max_occurence:
			max_occurence = cao
		max_ans[arr[s][que]] = cao
	total_points += ppq[que] * max_occurence
print(total_points)


def mostcommon(string, i, marks):
	A = B = C = D = E = 0
	for ans in string:
		if ans[i] == 'A':
			A += 1
		if ans[i] == 'B':
			B += 1
		if ans[i] == 'C':
			C += 1
		if ans[i] == 'D':
			D += 1
		if ans[i] == 'E':
			E += 1
	k = max(A, B, C, D, E) * int(marks[i])
	return k
(n, m) = input().split(' ')
n = int(n)
m = int(m)
string = []
marks = []
total = 0
for i in range(n):
	string.append(input())
mark = input()
for i in range(m):
	marks = mark.split(' ')
	marks[i] = int(marks[i])
for i in range(m):
	total = total + mostcommon(string, i, marks)
print(total)


from collections import defaultdict
line1 = input().split(' ')
(n, m) = (int(line1[0]), int(line1[1]))
res = []
for i in range(n):
	res.append(input())
points = input().split()
points = [int(x) for x in points]
total = 0
for q in range(m):
	map = defaultdict(int)
	for s in range(n):
		map[res[s][q]] += 1
	total += max(map.values()) * points[q]
print(total)


answers = []
grades = []
choices = []
optimistic = 0
for i in range(5):
	choices.append(0)
(n, m) = list(map(int, input().split(' ')))
for i in range(n):
	answers.append(input())
grades = list(map(int, input().split(' ')))
for i in range(m):
	for k in range(5):
		choices[k] = 0
	for j in range(n):
		choices[ord(answers[j][i]) - 65] += 1
	optimistic += max(choices) * grades[i]
print(optimistic)


(n, m) = input().split()
n = int(n)
m = int(m)
answer = []
for _ in range(n):
	a = input()
	answer.append(a)
points = [int(x) for x in input().split()]
res = 0
for i in range(m):
	arr = [0, 0, 0, 0, 0]
	for j in range(n):
		if answer[j][i] == 'A':
			arr[0] += 1
		if answer[j][i] == 'B':
			arr[1] += 1
		if answer[j][i] == 'C':
			arr[2] += 1
		if answer[j][i] == 'D':
			arr[3] += 1
		if answer[j][i] == 'E':
			arr[4] += 1
	res += max(arr) * points[i]
print(res)


(n, m) = map(int, input().split())
reg = [[0] * 5 for i in range(m)]
g = ord('A')
for i in range(n):
	a = input()
	for j in range(m):
		reg[j][ord(a[j]) - g] += 1
ans = 0
vals = list(map(int, input().split()))
for i in range(m):
	ans += vals[i] * max(reg[i])
print(ans)


(n, m) = map(int, input().split())
answers = []
for _ in range(n):
	answers.append(input())
points = list(map(int, input().split()))
res = 0
for i in range(m):
	same_answers = [0] * 5
	for answer in answers:
		same_answers[ord(answer[i]) - ord('A')] += 1
	res += max(same_answers) * points[i]
print(res)


(n, m) = map(int, input().split())
arr = [[0] * 5 for i in range(m)]
for i in range(n):
	j = 0
	for ch in input():
		if ch == 'A':
			arr[j][0] = arr[j][0] + 1
		elif ch == 'B':
			arr[j][1] = arr[j][1] + 1
		elif ch == 'C':
			arr[j][2] = arr[j][2] + 1
		elif ch == 'D':
			arr[j][3] = arr[j][3] + 1
		elif ch == 'E':
			arr[j][4] = arr[j][4] + 1
		j += 1
balls = [int(i) for i in input().split()]
sum = 0
for i in range(len(balls)):
	sum += balls[i] * max(arr[i])
print(sum)


mn = input().split()
m = int(mn[1])
n = int(mn[0])
k = [[''] for i in range(m)]
for _ in range(n):
	s = input()
	for i in range(len(k)):
		k[i] = [k[i][0] + s[i]]
c = list(map(int, input().split()))
count = []
globe = 0
for i in range(len(k)):
	count = []
	count = count + [k[i][0].count('A')]
	count = count + [k[i][0].count('B')]
	count = count + [k[i][0].count('C')]
	count = count + [k[i][0].count('D')]
	count = count + [k[i][0].count('E')]
	max1 = max(count)
	max1 = max1 * c[i]
	globe = globe + max1
print(globe)


(n, m) = map(int, input().split())
answers = [input() for _ in range(n)]
scores = map(int, input().split())
result = 0
for i in range(m):
	counts = [0] * 5
	for s in answers:
		counts[ord(s[i]) - ord('A')] += 1
	result += next(scores) * max(counts)
print(result)


from collections import Counter
(n, m) = map(int, input().split())
us = {}
for i in range(n):
	string = input()
	for i in range(len(string)):
		try:
			us[i + 1]
		except KeyError:
			us[i + 1] = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
		us[i + 1][string[i]] += 1
arr = [int(i) for i in input().split()]
s = 0
for i in range(len(arr)):
	m = max(us[i + 1].values())
	s += m * arr[i]
print(s)


from collections import Counter
(n, m) = map(int, input().split())
mat = []
ans = 0
for i in range(n):
	mat.append([x for x in input()])
marks = list(map(int, input().split()))
for i in range(m):
	s = Counter([mat[j][i] for j in range(n)])
	ans += max(s.values()) * marks[i]
print(ans)


(n, m) = list(map(int, input().split()))
rep = [input() for i in range(n)]
notes = list(map(int, input().split()))
maxi = 0
for i in range(m):
	L = []
	for k in rep:
		L.append(k[i])
	L1 = set(L)
	m = max([L.count(x) for x in L1])
	maxi += m * notes[i]
print(maxi)


nm = input().split()
(n, m) = (eval(nm[0]), eval(nm[1]))
ls = [[0] * 5 for i in range(0, m)]
for i in range(0, n):
	st = input()
	for k in range(0, m):
		if st[k] == 'A':
			ls[k][0] += 1
		elif st[k] == 'B':
			ls[k][1] += 1
		elif st[k] == 'C':
			ls[k][2] += 1
		elif st[k] == 'D':
			ls[k][3] += 1
		else:
			ls[k][4] += 1
score = input().split()
maxls = list(map(max, ls))
result = 0
for i in range(0, m):
	result += eval(score[i]) * maxls[i]
print(result)


def solve(results, points):
	max_points = 0
	for col in range(len(points)):
		a = [['A', 0], ['B', 0], ['C', 0], ['D', 0], ['E', 0]]
		for row in range(len(results)):
			a[ord(results[row][col]) - ord('A')][1] += 1
		(question, count) = sorted(a, key=lambda x: x[1], reverse=True)[0]
		max_points += count * points[col]
	return max_points

def main():
	(n, m) = map(int, input().strip().split())
	results = [list(input().strip()) for _ in range(n)]
	points = [int(x) for x in input().strip().split()]
	print(solve(results, points))
main()


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
c = list(map(int, input().split()))
sum = 0
for i in range(m):
	d = dict()
	for j in range(n):
		if a[j][i] in d:
			d[a[j][i]] += 1
		else:
			d[a[j][i]] = 1
	sum += max([i for i in d.values()]) * c[i]
print(sum)


from collections import Counter
(n, m) = list(map(int, input().split()))
a = [[0 for i in range(n)] for i in range(m)]
for i in range(n):
	b = list(map(str, input()))
	for (ind, el) in enumerate(b):
		a[ind][i] = el
point = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += point[i] * Counter(a[i]).most_common(1)[0][1]
print(ans)


(n, m) = map(int, input().split())
a = [[0, 0, 0, 0, 0] for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		if s[j] == 'A':
			a[j][0] += 1
		elif s[j] == 'B':
			a[j][1] += 1
		elif s[j] == 'C':
			a[j][2] += 1
		elif s[j] == 'D':
			a[j][3] += 1
		else:
			a[j][4] += 1
b = input().split()
ans = 0
for k in range(m):
	ans += max(a[k]) * int(b[k])
print(ans)


a = input()
a = a.split()
students = int(a[0])
questions = int(a[1])
ans = []
for i in range(students):
	x = input()
	ans.append(x)
weights = input()
weights = weights.split()
for i in range(len(weights)):
	weights[i] = int(weights[i])
n = []
for i in range(questions):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for j in range(students):
		if ans[j][i] == 'A':
			a += 1
		if ans[j][i] == 'B':
			b += 1
		if ans[j][i] == 'C':
			c += 1
		if ans[j][i] == 'D':
			d += 1
		if ans[j][i] == 'E':
			e += 1
	n.append(max(a, b, c, d, e))
total = 0
for i in range(len(n)):
	total += n[i] * weights[i]
print(total)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
res = 0
a = list(map(int, input().split()))
for i in range(m):
	temp = [t[i] for t in s]
	max_cnt = max([sum([t == c for t in temp]) for c in 'ABCDE'])
	res += max_cnt * a[i]
print(res)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m) = get_ints()
mat = []
for i in range(n):
	string = input()
	mat.append(string)
score = get_array()
ans = 0
for i in range(m):
	mydict = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		mydict[mat[j][i]] += 1
	ans += score[i] * max(mydict.values())
print(ans)


(n, m) = map(int, input().split())
answers = []
for x in range(n):
	answers.append(input())
points = list(map(int, input().split()))
counting = [[0 for i in range(5)] for j in range(m)]
for x in range(len(answers)):
	for i in range(m):
		if answers[x][i] == 'A':
			counting[i][0] += 1
		elif answers[x][i] == 'B':
			counting[i][1] += 1
		elif answers[x][i] == 'C':
			counting[i][2] += 1
		elif answers[x][i] == 'D':
			counting[i][3] += 1
		elif answers[x][i] == 'E':
			counting[i][4] += 1
total = 0
for question in range(len(counting)):
	best_count = max(counting[question])
	total += best_count * points[question]
print(total)


from collections import Counter
(n, m) = map(int, input().split())
answers = []
for _ in range(n):
	answers.append(list(input()))
scores = list(map(int, input().split()))
res = 0
for i in range(m):
	temp = [a[i] for a in answers]
	c = Counter(temp)
	res += scores[i] * c.most_common(1)[0][1]
print(res)


l = list(map(int, input().split(' ')))
s = l[0]
q = l[1]
ans = [['x' for x in range(q)] for y in range(s)]
for i in range(s):
	st = input()
	for j in range(len(st)):
		ans[i][j] = st[j]
marks = list(map(int, input().split(' ')))
tot = 0
for i in range(q):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(s):
		d[ans[j][i]] += 1
	mx = 0
	for (k, v) in d.items():
		if v > mx:
			mx = v
	tot += mx * marks[i]
print(tot)


import sys
(n, m) = map(int, input().split())
s = [list() for _ in range(n + 1)]
for i in range(n):
	s[i] = list(input())
b = list(map(int, input().split()))
res = 0
for j in range(m):
	d = [0 for _ in range(256)]
	for i in range(n):
		d[ord(s[i][j])] += 1
	res += max(d) * b[j]
print(res)


(n, m) = map(int, input().split())
mass = []
for i in range(m):
	mass.append([])
	for j in range(5):
		mass[i].append(0)
for i in range(n):
	s = input()
	for j in range(m):
		mass[j][ord(s[j]) - ord('A')] += 1
ans = []
s = input().split()
for i in range(m):
	ans.append(int(s[i]))
cor = 0
for i in range(m):
	r = max(mass[i][0], mass[i][1], mass[i][2], mass[i][3], mass[i][4])
	cor += r * ans[i]
print(cor)


(n, m) = [int(x) for x in input().split()]
ans = []
for i in range(m):
	ans.append({})
for _ in range(n):
	s = input()
	for i in range(m):
		if s[i] in ans[i]:
			ans[i][s[i]] += 1
		else:
			ans[i][s[i]] = 1
result = 0
points = [int(x) for x in input().split()]
for i in range(m):
	result += points[i] * max(ans[i].values())
print(result)


(n, m) = list(map(int, input().split()))
rep = [input() for i in range(n)]
notes = list(map(int, input().split()))
maxi = 0
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for k in rep:
		d[k[i]] += 1
	m = max(d.values())
	maxi += m * notes[i]
print(maxi)


(n, m) = map(int, input().split())
ans = [[0, 0, 0, 0, 0] for i in range(m)]
d = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
for i in range(n):
	numb = 0
	for elem in input():
		key = d[elem]
		ans[numb][key] += 1
		numb += 1
res = 0
i = 0
for bal in list(map(int, input().split())):
	res += max(ans[i]) * bal
	i += 1
print(res)


(students, questions) = [int(x) for x in input().split()]
scores = [[0] * 5 for _ in range(questions)]
for _ in range(students):
	answers = input().strip()
	for (ind, char) in enumerate(answers):
		scores[ind][ord(char) - ord('A')] += 1
points = [int(x) for x in input().split()]
total = 0
for q in range(questions):
	total += max(scores[q]) * points[q]
print(total)


from collections import Counter

def solve(n, m, a, r):
	s = 0
	for i in range(m):
		x = ''.join((a[j][i] for j in range(n)))
		c = Counter(x)
		y = max(c.items(), key=lambda x: x[1])
		s += y[1] * r[i]
	return s

def main():
	(n, m) = list(map(int, input().split()))
	a = [input() for i in range(n)]
	r = list(map(int, input().split()))
	print(solve(n, m, a, r))
main()


(n, m) = map(int, input().split())
s = []
for i in range(n):
	x = list(input())
	s.append(x)
mark = list(map(int, input().split()))
ans = 0
for i in range(m):
	l = []
	for j in s:
		l.append(j[i])
	a = l.count('A')
	b = l.count('B')
	c = l.count('C')
	d = l.count('D')
	e = l.count('E')
	ans = ans + max(a, b, c, d, e) * mark[i]
print(ans)


(n, m) = [int(i) for i in input().split()]
A = []
for i in range(n):
	s = input()
	A.append(s)
pts = [int(i) for i in input().split()]
nets = []
freq = [0] * 26
ans = 0
for i in range(m):
	freq = [0] * 26
	for j in range(n):
		freq[ord(A[j][i]) - ord('A')] += 1
	ans += max(freq) * pts[i]
print(ans)


from collections import *
R = lambda : map(int, input().split())
(n, m) = R()
print(sum((max(x.values()) * a for (x, a) in zip(map(Counter, zip(*(input() for _ in [0] * n))), R()))))


(n, m) = map(int, input().split(' '))
mass = []
for i in range(n):
	mass.append(str(input()))
maxx = list(map(int, input().split(' ')))
masss = []
for i in range(m):
	g = ''
	for j in range(n):
		g += mass[j][i] + ' '
	masss.append(g)
mm = []
h = 0
for i in range(len(masss)):
	mm.append(masss[i].count('A'))
	mm.append(masss[i].count('B'))
	mm.append(masss[i].count('C'))
	mm.append(masss[i].count('D'))
	mm.append(masss[i].count('E'))
	h += max(mm) * maxx[i]
	mm.clear()
print(h)


(n, m) = map(int, input().split())
si = [input() for i in range(n)]
ai = list(map(int, input().split()))
alth = 'ABCDE'
ans = 0
for i in range(m):
	nums = [0] * len(alth)
	for j in range(n):
		nums[alth.find(si[j][i])] += 1
	ans += max(nums) * ai[i]
print(ans)


(n, m) = map(int, input().split())
count = [[0] * 5 for _ in range(m)]
for _ in range(n):
	s = input()
	for i in range(len(s)):
		count[i][ord(s[i]) - ord('A')] += 1
cost = list(map(int, input().split()))
res = 0
for i in range(m):
	res += cost[i] * max(count[i])
print(res)


(n, q) = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(input())
s = list(map(int, input().split()))
res = 0
for i in range(q):
	t = [0] * 5
	for j in range(n):
		t[ord(a[j][i]) - ord('A')] += 1
	res += s[i] * max(t)
print(res)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
a = list(input().split())
sum = 0
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in l:
		d[j[i]] = d[j[i]] + 1
	sum = sum + max(d.values()) * int(a[i])
print(sum)


n = input()
n = n.split()
a = []
for i in n:
	a.extend([int(i)])
ans = []
listans = []
ques = []
for i in range(a[0]):
	sub = input()
	ans.extend([sub])
score = input()
score = score.split()
scores = []
for i in score:
	scores.extend([int(i)])
for j in range(a[0]):
	holder2 = []
	holder2.clear()
	for i in ans[j]:
		holder2.extend([i])
	listans.extend([holder2])
for c in range(a[1]):
	tracker = 0
	holder = {}
	letterlist = []
	lib = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	holder.clear()
	letterlist.clear()
	for i in range(a[0]):
		letter = ans[i][c]
		letterlist.extend([letter])
	for b in letterlist:
		lib[b] += 1
	max_key = max(lib, key=lib.get)
	holder = lib[max_key]
	ques.extend([holder])
points = 0
for i in range(a[1]):
	points += ques[i] * scores[i]
print(points)


(n, m) = map(int, input().split())
sushiW = [[o for o in input()] for k in range(n)]
pon = [int(k) for k in input().split()]
sump = 0
for k in range(m):
	count = [0, 0, 0, 0, 0]
	for o in range(n):
		lapshichka = sushiW[o][k]
		if lapshichka == 'A':
			count[0] += 1
		elif lapshichka == 'B':
			count[1] += 1
		elif lapshichka == 'C':
			count[2] += 1
		elif lapshichka == 'D':
			count[3] += 1
		elif lapshichka == 'E':
			count[4] += 1
	count.sort()
	sump += count[4] * pon[k]
print(sump)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
a = [*map(int, input().split())]
answer = 0
for i in range(m):
	z = [0, 0, 0, 0, 0]
	for j in range(n):
		z[ord(s[j][i]) - ord('A')] += 1
	answer += max(z) * a[i]
print(answer)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
a = []
for i in range(0, n):
	a.append(input())
b = input().split(' ')
for i in range(0, len(b)):
	b[i] = int(b[i])
ans = 0
for i in range(0, m):
	mx = 0
	for cor in ['A', 'B', 'C', 'D', 'E']:
		cnt = 0
		for j in range(0, n):
			if a[j][i] == cor:
				cnt += b[i]
		if cnt > mx:
			mx = cnt
	ans += mx
print(ans)


import math
from decimal import Decimal
import heapq

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = list(map(int, input().split()))
	return (n, m)

def dva():
	(n, m) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, m) = list(map(int, input().split()))
a = []
for i in range(n):
	s = input()
	a.append(s)
b = list(map(int, input().split()))
ans = 0
for j in range(m):
	d = {}
	for i in range(n):
		c = a[i][j]
		d[c] = d.get(c, 0) + 1
	tc = max(d.values()) * b[j]
	ans += tc
print(ans)


(n, m) = map(int, input().split())
S = [input() for i in range(n)]
A = list(map(int, input().split()))
C = [[0] * 5 for i in range(m)]
for i in range(n):
	s = S[i]
	for j in range(m):
		C[j][ord(s[j]) - ord('A')] += 1
ans = 0
for i in range(m):
	ans += max(C[i]) * A[i]
print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def binary_search(data, val, le):
	test = le
	if val >= data[-1]:
		return [test - 1, test - 1]
	elif val <= data[0]:
		return [0, 0]
	high_index = test - 1
	low_index = 0
	while high_index > low_index:
		index = (high_index + low_index) // 2
		sub = data[index]
		if data[low_index] == val:
			return [low_index, low_index]
		elif sub == val:
			return [index, index]
		elif data[high_index] == val:
			return [high_index, high_index]
		elif sub > val:
			if high_index == index:
				return sorted([high_index, low_index])
			high_index = index
		else:
			if low_index == index:
				return sorted([high_index, low_index])
			low_index = index
	return sorted([high_index, low_index])
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split(' '))
l = [input() for i in range(n)]
arr = list(map(int, input().split(' ')))
x = []
for i in range(k):
	d = {}
	for j in range(n):
		d[l[j][i]] = d.get(l[j][i], 0) + 1
	x.append(max(d.values()))
s = 0
for i in range(k):
	s += x[i] * arr[i]
print(s)


import sys
from collections import Counter

def readline():
	return sys.stdin.readline().rstrip()
(students, qs) = readline().split()
students = int(students)
qs = int(qs)
ans = []
counters = []
for i in range(qs):
	counters.append(Counter())
for i in range(students):
	ans.append(readline())
	for j in range(qs):
		counters[j][ans[i][j]] += 1
points = readline().split()
points.reverse()
sum = 0
for ctr in counters:
	sum += ctr.most_common(1)[0][1] * int(points.pop())
print(sum)


(n, q) = map(int, input().split())
a = [[0 for i in range(27)] for j in range(q + 1)]
s = [' ' for i in range(n + 2)]
for i in range(n):
	s[i] = input()
b = list(map(int, input().split()))
for i in range(n):
	for j in range(q):
		t = ord(s[i][j]) - ord('A')
		a[j][t] = a[j][t] + 1
cnt = 0
for i in range(q):
	cnt += max(a[i]) * b[i]
print(cnt)


(x, y) = map(int, input().split())
p = [[] for _ in range(y)]
for i in range(x):
	m = input()
	for j in range(y):
		p[j].append(m[j])
n = list(map(int, input().split()))
k = 0
for i in range(y):
	l = set(p[i])
	mx = 0
	for j in l:
		mx = max(mx, p[i].count(j))
	k += mx * n[i]
print(k)


def exams(marks, points):
	ans = 0
	for i in zip(*marks):
		c = most_freq(i)
		ans += points.pop(0) * c
	return ans

def most_freq(answer):
	di = {}
	for i in answer:
		if i in di:
			di[i] += 1
		else:
			di[i] = 1
	return max(list(di.values()))
(n, m) = list(map(int, input().split()))
marks = []
for i in range(n):
	marks.append(input())
points = list(map(int, input().split()))
print(exams(marks, points))


(n, m) = map(int, input().split())
array = []
for i in range(n):
	array.append(input())
pts = list(map(int, input().split()))
total = 0
for i in range(m):
	ch = [0] * 5
	for j in range(n):
		ch[ord(array[j][i]) - ord('A')] += 1
	total += pts[i] * max(ch)
print(total)


from collections import Counter
(n, m) = map(int, input().split())
answers = [input() for _ in range(n)]
prices = list(map(int, input().split()))
result = 0
for i in range(m):
	counter = Counter([answers[j][i] for j in range(n)])
	top = counter.most_common(1)[0]
	result += top[1] * prices[i]
print(result)


(n, m) = [int(s) for s in input().split(' ')]
answers = []
for i in range(m):
	answers.append({'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0})
cnt = 0
for i in range(n):
	s = input()
	for j in range(m):
		answers[j][s[j]] += 1
scores = [int(s) for s in input().split(' ')]
for j in range(m):
	cnt += max(answers[j].values()) * scores[j]
print(cnt)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())
(n, m) = mi()
p = []
for _ in range(n):
	p.append(input())
x = li()
k = 0
s = 0
for i in range(m):
	a = b = c = d = e = 0
	for j in range(n):
		if p[j][i] == 'A':
			a += 1
		elif p[j][i] == 'B':
			b += 1
		elif p[j][i] == 'C':
			c += 1
		elif p[j][i] == 'D':
			d += 1
		elif p[j][i] == 'E':
			e += 1
	s += max(a, b, c, d, e) * x[k]
	k += 1
print(s)


(n, k) = map(int, input().split())
a = [input() for i in range(n)]
ans = 0
b = [int(i) for i in input().split()]
d = {}
for j in range(k):
	for i in range(n):
		if a[i][j] in d:
			d[a[i][j]] += 1
		else:
			d[a[i][j]] = 1
	maximum = max(d, key=d.get)
	ans += b[j] * d[maximum]
	d = {}
print(ans)


(n, m) = (int(i) for i in input().split())
s = []
z = 0
for i in range(n):
	s.append(list(input()))
a = [int(i) for i in input().split()]
for i in range(m):
	test = [0 for j in range(5)]
	for j in range(n):
		if s[j][i] == 'A':
			test[0] += 1
		elif s[j][i] == 'B':
			test[1] += 1
		elif s[j][i] == 'C':
			test[2] += 1
		elif s[j][i] == 'D':
			test[3] += 1
		else:
			test[4] += 1
	z += max(test) * a[i]
print(z)


(n, m) = map(int, input().split())
a = []
for i in range(m):
	a.append([0, 0, 0, 0, 0])
for i in range(n):
	b = input()
	for j in range(len(b)):
		a[j][ord(b[j]) - 65] += 1
a1 = list(map(int, input().split()))
k = 0
for i in range(m):
	k += max(a[i]) * a1[i]
print(k)


(nb_student, nb_questions) = list(map(lambda x: int(x), input('').split(' ')))
ans_students = []
for k in range(nb_student):
	ans_students.append(list(input('')))
ai = list(map(lambda x: int(x), input('').split(' ')))
count_asw = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for k in range(nb_questions)]
for ans in ans_students:
	for (q_number, a) in enumerate(ans):
		count_asw[q_number][a] += 1
max_points = 0
for (i, ans) in enumerate(count_asw):
	max_ans = max(ans.values())
	max_points += max_ans * ai[i]
print(max_points)


def get_ints():
	return list(map(int, input().split()))
(N, M) = get_ints()
a = [input() for i in range(N)]
s = get_ints()
ans = 0
for i in range(M):
	d = {}
	for row in a:
		c = ord(row[i]) - 65
		if c in d:
			d[c] += 1
		else:
			d[c] = 1
	ans += max(d.values()) * s[i]
print(ans)


def main():
	(n, m) = [int(v) for v in input().split()]
	freq = {}
	for i in range(n):
		ans = input()
		for (i, a) in enumerate(ans):
			if i not in freq:
				freq[i] = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
			freq[i][a] += 1
	points = [int(v) for v in input().split()]
	max_s = 0
	for (i, p) in enumerate(points):
		max_s += p * max(freq[i].values())
	print(max_s)
main()


(n, m) = map(int, input().split())
l = []
for i in range(n):
	x = input()
	l += [x]
l1 = list(map(int, input().split()))
sum1 = 0
for i in range(m):
	subl = [l[j][i] for j in range(n)]
	d = {}
	for k in subl:
		if k not in d:
			d[k] = 1
		else:
			d[k] += 1
	l2 = sorted(list(d.values()))
	sum1 += l2[len(l2) - 1] * l1[i]
print(sum1)


from collections import Counter
(N, M) = map(int, input().split())
S = [input() for i in range(N)]
A = list(map(int, input().split()))
ans = 0
for i in range(M):
	b = [S[j][i] for j in range(N)]
	c = sorted(Counter(b).values(), reverse=True)
	ans += c[0] * A[i]
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
ll = []
for i in range(n):
	ans = input()
	ll.append(ans)
marks = list(map(int, input().split()))
each = list(zip(*ll))
val = 0
for i in range(m):
	ct = Counter(each[i])
	val += max(dict(ct).values()) * marks[i]
print(val)


(n, m) = map(int, input().split())
L = [''] * m
for k in range(n):
	s = input()
	for j in range(m):
		L[j] += s[j]
L1 = [k for k in map(int, input().split())]
suma = 0
for k in range(m):
	a = max(L[k].count('A'), L[k].count('B'), L[k].count('C'), L[k].count('D'), L[k].count('E'))
	suma += a * L1[k]
print(suma)


stu_ex = input().split(' ')
(student, exam) = [int(a) for a in stu_ex]
ans = [[0, 0, 0, 0, 0] for i in range(0, exam)]
for i in range(student):
	std_ans = input().strip()
	for (j, c) in enumerate(std_ans):
		ans[j][ord(c) - ord('A')] += 1
score = [int(a) for a in input().split(' ')]
max_score = 0
for i in range(exam):
	max_score += score[i] * max(ans[i])
print(max_score)


from collections import Counter
(n, m) = map(int, input().split())
main = [''] * m
for stud in range(n):
	s = str(input())
	for ques in range(m):
		l = main[ques]
		l += s[ques]
		main[ques] = l
a = list(map(int, input().split()))
total = 0
for i in range(m):
	l = main[i]
	res = Counter(l)
	mx = max(res.values())
	total += mx * a[i]
print(total)


(a, b) = list(map(int, input().split()))
ans = []
for i in range(a):
	ans.append(input())
mark = list(map(int, input().split()))
sum = 0
d = {}
c = 0
for i in range(b):
	for e in 'ABCDE':
		d[e] = 0
	for j in ans:
		d[j[i]] += 1
	ma = 0
	for j in d:
		if d[j] > ma:
			ma = d[j]
	d.clear()
	sum += mark[c] * ma
	c += 1
print(sum)


(m, n) = map(int, input().split(' '))
a = []
s = 0
for i in range(m):
	a.append(input())
b = [int(x) for x in input().split(' ')]
for i in range(n):
	c = ''
	d = {}
	for j in range(m):
		c = c + a[j][i]
	for k in c:
		d[k] = d.get(k, 0) + 1
	s += b[i] * max(d.values())
print(s)


(n, m) = list(map(int, input().split()))
l = []
for i in range(m):
	l.append({})
for i in range(n):
	a = list(input())
	for i in range(m):
		l[i][a[i]] = l[i].get(a[i], 0) + 1
arr = list(map(int, input().split()))
c = 0
for i in range(m):
	m = max(l[i].values())
	c += arr[i] * m
print(c)


def main():
	import sys
	(n, m) = map(int, input().split())
	strs = [input() for _ in range(n)]
	scores = list(map(int, input().split()))
	ans = 0
	for i in range(m):
		cnt = [0] * 5
		for j in range(n):
			cnt[ord(strs[j][i]) - ord('A')] += 1
		ans += scores[i] * max(cnt)
	print(ans)
	return 0
main()


(n, m) = map(int, input().split())
list1 = []
for i in range(n):
	list1.append(list(input()))
marks = list(map(int, input().split()))
d = {}
for j in range(0, m):
	d.update({j + 1: [0, 0, 0, 0, 0]})
	for i in range(n):
		if list1[i][j] == 'A':
			d[j + 1][0] += 1
		elif list1[i][j] == 'B':
			d[j + 1][1] += 1
		elif list1[i][j] == 'C':
			d[j + 1][2] += 1
		elif list1[i][j] == 'D':
			d[j + 1][3] += 1
		elif list1[i][j] == 'E':
			d[j + 1][4] += 1
total = 0
for i in range(m):
	total += marks[i] * max(d[i + 1])
print(total)


from collections import defaultdict
(n, m) = map(int, input().split())
answers = defaultdict()
for _ in range(n):
	answers[_] = input()
values = list(map(int, input().split()))
ans = 0
for i in range(m):
	temp_list = []
	for j in range(n):
		temp_list.append(answers[j][i])
	uniq = set(temp_list)
	maxCount = 0
	for u in uniq:
		countU = temp_list.count(u)
		if countU > maxCount:
			maxCount = countU
	ans += values[i] * maxCount
print(ans)


def func(a):
	b = 0
	c = 0
	d = 0
	e = 0
	f = 0
	for i in range(len(a)):
		if a[i] == 'A':
			b = b + 1
		elif a[i] == 'B':
			c = c + 1
		elif a[i] == 'C':
			d = d + 1
		elif a[i] == 'D':
			e = e + 1
		elif a[i] == 'E':
			f = f + 1
	return max(b, c, d, e, f)
(n, m) = list(map(int, input().strip().split()))
a = []
for i in range(n):
	a.append(input())
b = list(map(int, input().strip().split()))
c = []
d = []
for k in range(m):
	d = []
	for j in range(n):
		d.append(a[j][k])
	c.append(d)
e = []
s = 0
for l in range(m):
	e.append(func(c[l]))
	s = s + e[l] * b[l]
print(s)


from collections import Counter
x = '2 4\nABCD\nABCE\n1 2 3 4'

def f(string):

	def c(x=(r for r in string.splitlines())):
		return next(x)
	return c
source = input

def transpose(l):
	return map(list, zip(*l))
(n, m) = map(int, source().split())
students = list(transpose((list(source()) for i in range(n))))
points = list(map(int, source().split()))
print(sum((max(Counter(students[i]).values()) * points[i] for i in range(m))))


def counter(arr, k):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for i in range(n):
		if arr[i][k] == 'A':
			a += 1
		elif arr[i][k] == 'B':
			b += 1
		elif arr[i][k] == 'C':
			c += 1
		elif arr[i][k] == 'D':
			d += 1
		else:
			e += 1
	return max(a, b, c, d, e)
(n, m) = map(int, input().split())
arr = []
for i in range(n):
	s = input()
	arr.append(s)
marks = list(map(int, input().split()))
ans = 0
for i in range(m):
	c = counter(arr, i)
	ans += marks[i] * c
print(ans)


from collections import defaultdict
from collections import Counter
(a, b) = list(map(int, input().split()))
cnt = [defaultdict() for i in range(b)]
for i in range(a):
	s = input()
	for j in range(b):
		try:
			cnt[j][s[j]] += 1
		except:
			cnt[j][s[j]] = 1
tot = 0
finarr = list(map(int, input().split()))
for i in range(b):
	tot += max(cnt[i].values()) * finarr[i]
print(tot)


(n, m) = map(int, input().split())
b = []
l = 'ABCDE'
for i in range(m):
	b.append([0, 0, 0, 0, 0])
for i in range(n):
	a = list(str(input()))
	for j in range(m):
		b[j][l.index(a[j])] += 1
p = list(map(int, input().split()))
E = 0
for i in range(m):
	E += p[i] * max(b[i])
print(E)


a = 'ABCDE'
answer_dict = {a[i]: i for i in range(5)}
(n, m) = map(int, input().split())
answers = []
for i in range(m):
	answers.append([0, 0, 0, 0, 0])
for i in range(n):
	inp = str(input())
	for j in range(m):
		letter = inp[j]
		index = answer_dict[letter]
		answers[j][index] += 1
values = [int(x) for x in input().split()]
final = 0
for i in range(m):
	final += max(answers[i]) * values[i]
print(final)


(n, m) = map(int, input().split())
ans = []
for i in range(n):
	ans.append(input())
pnt = list(map(int, input().split()))
scr = 0
for i in range(m):
	tmp = {}
	for j in range(n):
		tmp[ans[j][i]] = tmp.get(ans[j][i], 0) + 1
	tmp = sorted([(k, v) for (v, k) in tmp.items()], reverse=True)
	scr = scr + pnt[i] * tmp[0][0]
print(scr)


(n, m) = [int(x) for x in input().split()]
answer = [[0] * 5 for i in range(m)]
for j in range(n):
	a = input()
	for i in range(m):
		item = a[i]
		if item == 'A':
			answer[i][0] += 1
		elif item == 'B':
			answer[i][1] += 1
		elif item == 'C':
			answer[i][2] += 1
		elif item == 'D':
			answer[i][3] += 1
		else:
			answer[i][4] += 1
b = [int(x) for x in input().split()]
arr = 0
for i in range(m):
	arr += max(answer[i]) * b[i]
print(arr)


(n, m) = [int(x) for x in input().split()]
ans = []
for i in range(n):
	ans.append(list(input()))
score = 0
points = [int(x) for x in input().split()]
for i in range(m):
	maxx = 0
	a = None
	count = [0] * 5
	for j in range(n):
		count[ord(ans[j][i]) - 65] += 1
		if maxx < count[ord(ans[j][i]) - 65]:
			maxx = count[ord(ans[j][i]) - 65]
	score = score + points[i] * maxx
print(score)


(n, m) = map(int, input().split())
(s, d) = ([], [])
e = set()
r = [0, 0, 0, 0, 0]
a = 0
for i in range(n):
	s.append(input())
pm = [int(i) for i in input().split()]
for i in range(m):
	for j in range(n):
		if s[j][i] == 'A':
			r[0] += 1
		elif s[j][i] == 'B':
			r[1] += 1
		elif s[j][i] == 'C':
			r[2] += 1
		elif s[j][i] == 'D':
			r[3] += 1
		else:
			r[4] += 1
	d.append(max(r))
	r = [0 for i in range(5)]
for i in range(m):
	a += pm[i] * d[i]
print(a)


(n, m) = list(map(int, input().split()))
fridge = list()
for i in range(n):
	fridge.append(input())
grade = list(map(int, input().split()))
counter = 0
for i in range(m):
	b = ''
	for j in range(n):
		b += fridge[j][i]
	s = max(b.count('A'), b.count('B'), b.count('C'), b.count('D'), b.count('E'))
	counter = counter + s * grade[i]
print(counter)


from sys import stdin
from collections import *

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, m) = arr_inp(1)
(arr, cost, ans) = ([input() for i in range(n)], arr_inp(1), 0)
for i in range(m):
	mem = Counter()
	for j in range(n):
		mem[arr[j][i]] += 1
	ans += mem.most_common(1)[0][1] * cost[i]
print(ans)


(n, m) = map(int, input().split())
t = []
ans = 0
for i in range(n):
	ss = input()
	t.append(ss)
k = list(map(int, input().split()))
for i in range(m):
	e = [0, 0, 0, 0, 0]
	for j in range(n):
		if t[j][i] == 'A':
			e[0] += 1
		elif t[j][i] == 'B':
			e[1] += 1
		elif t[j][i] == 'C':
			e[2] += 1
		elif t[j][i] == 'D':
			e[3] += 1
		else:
			e[4] += 1
	ans += max(e) * k[i]
print(ans)


from sys import stdin, stdout, exit
(n, m) = list(map(int, stdin.readline().split()))
cts = [[0] * 5 for i in range(m)]
for i in range(n):
	s = stdin.readline().strip()
	for (j, c) in enumerate(s):
		cts[j][ord(c) - ord('A')] += 1
a = list(map(int, stdin.readline().split()))
ans = 0
for j in range(m):
	ans += max(cts[j]) * a[j]
stdout.write(str(ans) + '\n')


(q, s) = ([], 0)
(a, b) = map(int, input().split())
for x in range(a):
	q.append(list(input()))
l = list(map(int, input().split()))
for x in range(b):
	(w, r) = ([], [])
	for y in range(a):
		w.append(q[y][x])
	e = list(set(w))
	r = [w.count(e[z]) for z in range(len(e))]
	s += max(r) * l[x]
print(s)


(n, m) = map(int, input().split())
data = [input() for _ in range(n)]
a = list(map(int, input().split()))
result = 0
for i in range(m):
	check = [0] * 5
	for j in range(n):
		check[ord(data[j][i]) - ord('A')] += 1
	result += max(check) * a[i]
print(result)


(n, m) = map(int, input().split())
x = []
for i in range(n):
	s = input()
	x.append(s)
c = 0
a = list(map(int, input().split()))
for j in range(m):
	y = []
	for i in range(n):
		y.append(x[i][j])
	b = []
	d = list(set(y))
	for k in range(len(d)):
		b.append(y.count(d[k]))
	c += max(b) * a[j]
print(c)


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
arr = []
alpha = []
for h in range(m + 1):
	alpha.append([])
	for h1 in range(7):
		alpha[h].append(0)
for i in range(n):
	s = input()
	for p in range(len(s)):
		alpha[p][ord(s[p]) - 64] += 1
	arr.append(s)
alpha.insert(0, [])
arr.insert(0, '')
t = input()
value = t.split(' ')
value.insert(0, 0)
index = 0
for j in range(1, m + 1):
	value[j] = int(value[j])
ans = 0
for k in range(1, m + 1):
	maxm = max(alpha[k])
	num = alpha[k].index(maxm)
	ans = ans + maxm * value[k]
print(ans)


def mostFrequent(arr, n):
	arr.sort()
	max_count = 1
	res = arr[0]
	curr_count = 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			curr_count += 1
		else:
			if curr_count > max_count:
				max_count = curr_count
				res = arr[i - 1]
			curr_count = 1
	if curr_count > max_count:
		max_count = curr_count
		res = arr[n - 1]
	return res
a = list(map(int, input().split()))
b = []
for i in range(a[0]):
	b.append(input())
c = list(map(int, input().split()))
score = 0
for i in range(a[1]):
	templist = []
	for j in range(a[0]):
		templist.append(b[j][i])
	n = len(templist)
	maxop = mostFrequent(templist, n)
	countop = templist.count(maxop)
	score = score + countop * c[i]
print(score)


(n, m) = map(int, input().split())
L = []
for _ in range(n):
	L.append(input())
mrks = list(map(int, input().split()))
total = 0
for i in range(m):
	freq = [0, 0, 0, 0, 0]
	for j in range(n):
		if L[j][i] == 'A':
			freq[0] += 1
		elif L[j][i] == 'B':
			freq[1] += 1
		elif L[j][i] == 'C':
			freq[2] += 1
		elif L[j][i] == 'D':
			freq[3] += 1
		else:
			freq[4] += 1
	total += mrks[i] * max(freq)
print(total)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')
from itertools import permutations

def main():
	(n, m) = ria()
	s = []
	for _ in range(n):
		s.append([ord(x) - ord('A') for x in rs()])
	a = ria()
	ans = 0
	for j in range(m):
		best = 0
		for x in range(5):
			cnt = 0
			for i in range(n):
				cnt += a[j] if s[i][j] == x else 0
			best = max(best, cnt)
		ans += best
	wi(ans)
main()


(n, m) = [int(i) for i in input().split()]
data = []
for i in range(n):
	data.append(input())
data2 = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	counter = [0] * 5
	for j in range(n):
		counter[ord(data[j][i]) - 65] += 1
	ans += data2[i] * max(counter)
print(ans)


(n, m) = input().split()
n = int(n)
m = int(m)
dic = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
ans_l = []
while n > 0:
	ans = input()
	l = list(ans)
	ans_l.append(l)
	n -= 1
inp = input()
score = [int(ele) for ele in inp.split()]
res = 0
for i in range(m):
	countA = 0
	countB = 0
	countC = 0
	countD = 0
	countE = 0
	for ele in ans_l:
		if ele[i] == 'A':
			countA += 1
		elif ele[i] == 'B':
			countB += 1
		elif ele[i] == 'C':
			countC += 1
		elif ele[i] == 'D':
			countD += 1
		else:
			countE += 1
	maxi = max(countA, countB, countC, countD, countE)
	res += maxi * score[i]
print(res)


(n, m) = list(map(int, input().split()))
answers = list()
for i in range(n):
	answers.append(input())
points = list(map(int, input().split()))
score = 0
for i in range(m):
	dic = dict()
	for j in range(n):
		if answers[j][i] in dic:
			dic[answers[j][i]] += 1
		else:
			dic[answers[j][i]] = 1
	val = dic.values()
	max = 0
	for j in val:
		if j > max:
			max = j
	score += points[i] * max
print(score)


(n, m) = [int(x) for x in input().split(' ')]
lst = [{} for i in range(m)]
while n:
	n = n - 1
	s = input()
	for i in range(len(s)):
		if lst[i].get(s[i]) != None:
			lst[i][s[i]] = lst[i][s[i]] + 1
		else:
			lst[i][s[i]] = 1
value = [int(x) for x in input().split(' ')]
sumi = 0
for i in range(len(lst)):
	maxi = 0
	for key in lst[i]:
		if lst[i][key] > maxi:
			maxi = lst[i][key]
	sumi = sumi + maxi * value[i]
print(sumi)


from collections import defaultdict
(n, m) = map(int, input().split())
p = []
l = defaultdict(list)
for i in range(n):
	s = str(input())
	for j in range(m):
		l[j].append(s[j])
a = list(map(int, input().split()))
j = 0
ans = 0
for i in range(m):
	k = max(l[j].count('A'), l[j].count('B'), l[j].count('C'), l[j].count('D'), l[j].count('E'))
	ans = ans + k * a[j]
	j = j + 1
print(ans)


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	a = []
	s = input()
	for j in range(m):
		a.append(s[j])
	matrix.append(a)
q = list(map(int, input().split()))
A = 0
B = 0
C = 0
D = 0
E = 0
ans = 0
for i in range(m):
	for j in range(n):
		if matrix[j][i] == 'A':
			A += 1
		elif matrix[j][i] == 'B':
			B += 1
		elif matrix[j][i] == 'C':
			C += 1
		elif matrix[j][i] == 'D':
			D += 1
		else:
			E += 1
	ans += q[i] * max(A, B, C, D, E)
	A = 0
	B = 0
	C = 0
	D = 0
	E = 0
print(ans)


(n, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * m
d = [0] * m
e = [0] * m
ka = 0
for u in range(n):
	s = input()
	for i in range(m):
		if s[i] == 'A':
			a[i] += 1
		elif s[i] == 'B':
			b[i] += 1
		elif s[i] == 'C':
			c[i] += 1
		elif s[i] == 'D':
			d[i] += 1
		elif s[i] == 'E':
			e[i] += 1
l = list(map(int, input().split()))
for j in range(m):
	ka += l[j] * max(a[j], b[j], c[j], d[j], e[j])
print(ka)


(n, m) = list(map(int, input().split()))[:2]
s = []
for i in range(n):
	tmp = input()
	s.append(tmp)
a = list(map(int, input().split()))
count = [{c: 0 for c in ['A', 'B', 'C', 'D', 'E']} for _ in range(m)]
for ans in s:
	for (i, c) in enumerate(ans):
		count[i][c] += 1
total = 0
for i in range(m):
	tmp = 0
	for c in count[i].keys():
		tmp = max(tmp, count[i][c])
	total += tmp * a[i]
print(total)


(n, m) = map(int, input().split())
r = []
for _ in range(n):
	s = input()
	r.append(s)
l = list(map(int, input().split()))
sum = 0
for i in range(m):
	s = {r[j][i]: 0 for j in range(n)}
	for k in range(n):
		s[r[k][i]] += 1
	x = max(s.values())
	if x != 1:
		sum += x * l[i]
	else:
		sum += l[i]
print(sum)


lis = list(input().split())
(n, m) = (int(lis[0]), int(lis[1]))
a = []
res = 0
for i in range(n):
	a.append(input())
s = list(map(int, input().split()))
for i in range(m):
	cnt = [0] * 5
	for j in range(n):
		cnt[ord(a[j][i]) - ord('A')] += 1
	res += s[i] * max(cnt)
print(res)


(n, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * m
d = [0] * m
e = [0] * m
sum = 0
for _ in range(n):
	s = input()
	for i in range(m):
		if s[i] == 'A':
			a[i] += 1
		elif s[i] == 'B':
			b[i] += 1
		elif s[i] == 'C':
			c[i] += 1
		elif s[i] == 'D':
			d[i] += 1
		elif s[i] == 'E':
			e[i] += 1
arr = [int(x) for x in input().split()]
for j in range(m):
	sum += arr[j] * max(a[j], b[j], c[j], d[j], e[j])
print(sum)


import math
import sys
import re
(n, m) = map(int, input().rstrip().split())
l1 = []
for x in range(n):
	s = input()
	l1.append(s)
l2 = list(map(int, input().rstrip().split()))
total = 0
for i in range(m):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for j in l1:
		if j[i] == 'A':
			a = a + 1
		elif j[i] == 'B':
			b = b + 1
		elif j[i] == 'C':
			c = c + 1
		elif j[i] == 'D':
			d = d + 1
		elif j[i] == 'E':
			e = e + 1
	mx = max(a, b, c, d, e)
	total = total + mx * l2[i]
print(total)


from collections import Counter
(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
a = [*zip(*a)]
res = [*map(lambda v: Counter(v).most_common(1)[0][1], a)]
vals = [*map(int, input().split())]
ret = 0
for i in range(len(res)):
	ret += vals[i] * res[i]
print(ret)


(n, m) = map(int, input().split())
a = []
ans1 = 0
for i in range(n):
	a.append(input())
ans = list(map(int, input().split()))
for i in range(m):
	d = {}
	ma = -1
	for j in range(n):
		d[a[j][i]] = d.get(a[j][i], 0) + 1
		ma = max(ma, d[a[j][i]])
	ans1 += ma * ans[i]
print(ans1)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(input()))
ans = 0
s = list(map(int, input().split()))
for i in range(m):
	a = []
	p = []
	mj = []
	for j in range(n):
		a.append(l[j][i])
	for k in a:
		if k not in mj:
			mj.append(k)
			p.append(a.count(k))
	t = max(p)
	if max(p) == 1:
		ans += s[i]
	else:
		ans += t * s[i]
print(ans)


(n, m) = map(int, input().split())
ans = []
for i in range(n):
	ans.append(list(input()))

def most_common(lst):
	return max(set(lst), key=lst.count)
ans = [[ans[j][i] for j in range(len(ans))] for i in range(len(ans[0]))]
scores = list(map(int, input().split()))
res = []
for col in ans:
	res.append(most_common(col))
tot = 0
for i in range(len(res)):
	tot += ans[i].count(res[i]) * scores[i]
print(tot)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
import io
import os
input = sys.stdin.readline
import random
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(1):
	(n, m) = cin()
	d = dd(dict)
	for i in range(n):
		s = sin()
		for j in range(m):
			d[j][s[j]] = d[j].get(s[j], 0) + 1
	l = ain()
	ans = 0
	for i in range(m):
		ans += l[i] * max(d[i].values())
	print(ans)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
answers = []
for i in range(m):
	answers.append({'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0})
for i in range(n):
	ones_ans = input()
	for j in range(m):
		answers[j][ones_ans[j]] += 1
for i in range(m):
	max_i = max(answers[i]['A'], answers[i]['B'])
	max_i = max(max_i, answers[i]['C'])
	max_i = max(max_i, answers[i]['D'])
	max_i = max(max_i, answers[i]['E'])
	answers[i] = max_i
ans = 0
points = input().split()
for i in range(m):
	ans += answers[i] * int(points[i])
print(ans)


(n, m) = map(int, input().split())
An = []
summ = 0
for i in range(n):
	An.append(input())
D = list(map(int, input().split()))
for i in range(m):
	B = [0, 0, 0, 0, 0]
	for j in range(n):
		s = An[j]
		ss = s[i]
		if ss == 'A':
			B[0] += 1
		elif ss == 'B':
			B[1] += 1
		elif ss == 'C':
			B[2] += 1
		elif ss == 'D':
			B[3] += 1
		elif ss == 'E':
			B[4] += 1
	B.sort()
	summ += B[4] * D[i]
print(summ)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
(n, m) = get_int_list()
answers = [0] * n
for i in range(n):
	answers[i] = get_string()
score = get_int_list()
max_answer = [0] * m
for j in range(m):
	max_response = [0, 0, 0, 0, 0]
	for i in range(n):
		if answers[i][j] == 'A':
			max_response[0] += 1
		elif answers[i][j] == 'B':
			max_response[1] += 1
		elif answers[i][j] == 'C':
			max_response[2] += 1
		elif answers[i][j] == 'D':
			max_response[3] += 1
		else:
			max_response[4] += 1
		max_answer[j] = max(max_response) * score[j]
print(sum(max_answer))


(n, m) = map(int, input().split())
l = []
for x in range(n):
	l.append(input())
marks = list(map(int, input().split()))
question = 0
total = 0
while question < m:
	(a_cou, b_cou, c_cou, d_cou, e_cou) = (0, 0, 0, 0, 0)
	for num in l:
		if num[question] == 'A':
			a_cou += 1
		elif num[question] == 'B':
			b_cou += 1
		elif num[question] == 'C':
			c_cou += 1
		elif num[question] == 'D':
			d_cou += 1
		else:
			e_cou += 1
	total += max(a_cou, b_cou, c_cou, d_cou, e_cou) * marks[question]
	question += 1
print(total)


(n, m) = map(int, input().split())
S = []
for i in range(n):
	S.append(input())
mark = list(map(int, input().split()))
ans = 0
for q in range(m):
	A = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for i in range(n):
		A[S[i][q]] += 1
	ans += max(A.values()) * mark[q]
print(ans)


(n, m) = map(int, input().split())
ans = [{} for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		if s[j] not in ans[j]:
			ans[j][s[j]] = 0
		ans[j][s[j]] += 1
points = list(map(int, input().split()))
res = 0
for i in range(m):
	x = ans[i]
	o = 0
	for (k, v) in x.items():
		if v > o:
			o = v
	res += points[i] * o
print(res)


(n, m) = map(int, input().split())
s = ['' for i in range(n)]
for i in range(n):
	s[i] = input()
a = []
a = list(map(int, input().split()))
C = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
M = 0
for j in range(m):
	for i in range(n):
		C[s[i][j]] += 1
	Ma = 0
	for k in C.keys():
		Ma = max(Ma, C[k])
		C[k] = 0
	M += Ma * a[j]
print(M)


(n, k) = map(int, input().split())
a = []
s = 0
for i in range(n):
	b = list(input())
	a.append(b)
c = list(map(int, input().split()))
for i in range(k):
	s += max(([a[j][i] for j in range(n)].count(d) for d in ['A', 'B', 'C', 'D', 'E'])) * c[i]
print(s)


(n, m) = (int(x) for x in input().split())
ar = []
for i in range(n):
	ar.append(input())
br = [int(x) for x in input().split()]
ans = 0
for i in range(m):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for j in range(n):
		if ar[j][i] == 'A':
			a += 1
		elif ar[j][i] == 'B':
			b += 1
		elif ar[j][i] == 'C':
			c += 1
		elif ar[j][i] == 'D':
			d += 1
		else:
			e += 1
	ans += max(a, b, c, d, e) * br[i]
print(ans)


def input(f):
	(n, m) = map(int, f.readline().split())
	s = [None for _ in range(n)]
	for i in range(n):
		s[i] = f.readline()
	a = list(map(int, f.readline().split()))
	return (n, m, s, a)

def solve(n, m, s, a):
	res = 0
	for i in range(m):
		best = 0
		for c in ['A', 'B', 'C', 'D', 'E']:
			cnt = 0
			for j in range(n):
				if s[j][i] == c:
					cnt += 1
			best = max(best, cnt)
		res += a[i] * best
	return res
import sys
print(solve(*input(sys.stdin)))


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
(n, m) = rints()
s = [input() for _ in range(n)]
a = rints()
t = 0
for i in range(m):
	c = [0] * 5
	for si in s:
		c[ord(si[i]) - ord('A')] += 1
	t += a[i] * max(c)
print(t)


(n, m) = map(int, input().split())
a = []
s = 0
for i in range(n):
	a.append(input())
b = list(map(int, input().split()))
for i in range(m):
	s += max(([a[j][i] for j in range(n)].count(h) for h in ['A', 'B', 'C', 'D', 'E'])) * b[i]
print(s)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
marks = list(map(int, input().split()))
answer = 0
for i in range(m):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for j in range(n):
		if s[j][i] == 'A':
			a += 1
		elif s[j][i] == 'B':
			b += 1
		elif s[j][i] == 'C':
			c += 1
		elif s[j][i] == 'D':
			d += 1
		elif s[j][i] == 'E':
			e += 1
	maxu = max(a, b, c, d, e)
	answer += maxu * marks[i]
print(answer)


from math import sqrt
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, m) = mi()
b = []
for i in range(n):
	s = si()
	b.append(list(s))
a = li()
c1 = 0
d = {}
for i in range(m):
	d['A'] = 0
	d['B'] = 0
	d['C'] = 0
	d['D'] = 0
	d['E'] = 0
	for j in range(n):
		d[b[j][i]] += 1
	b1 = []
	for k in d:
		b1.append(d[k])
	m = max(b1)
	c1 += a[i] * m
print(c1)


from statistics import mode
from collections import Counter
s = str(input(''))
(n, m) = s.split(' ')
n = int(n)
m = int(m)
s = [''] * n
for i in range(0, n):
	s[i] = str(input(''))
w = [int(x) for x in str(input('')).split(' ')]
total = 0
for i in range(0, m):
	answers = Counter([x[i] for x in s])
	total += answers.most_common(1)[0][1] * w[i]
print(total)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
d = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for k in range(m)]
for i in range(n):
	x = input()
	for j in range(m):
		d[j][x[j]] += 1
scores = input().split(' ')
total_max = 0
for i in range(m):
	total_max += max([j for j in d[i].values()]) * int(scores[i])
print(total_max)


(studentnum, answerlen) = [int(x) for x in input().split(' ')]
answers = []
for i in range(studentnum):
	answers.append(input())
values = [int(x) for x in input().split(' ')]
optimalization = [[0, 0, 0, 0, 0] for i in range(answerlen)]
for i in answers:
	for k in range(answerlen):
		if i[k] == 'A':
			optimalization[k][0] += 1
		elif i[k] == 'B':
			optimalization[k][1] += 1
		elif i[k] == 'C':
			optimalization[k][2] += 1
		elif i[k] == 'D':
			optimalization[k][3] += 1
		else:
			optimalization[k][4] += 1
res = 0
for i in range(answerlen):
	res += max(optimalization[i]) * values[i]
print(res)


from collections import defaultdict
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(input()))
c = list(map(int, input().split()))
ans = 0
t = 0
for i in range(m):
	d = {}
	for j in range(n):
		if l[j][i] not in d.keys():
			d[l[j][i]] = 1
		else:
			d[l[j][i]] += 1
	d = sorted(d.items(), key=lambda x: x[1], reverse=True)
	ans += d[0][1] * c[t]
	t = t + 1
print(ans)


(n, m) = list(map(int, input().split()))
A = []
Ans = 0
for _ in range(n):
	A.append(input())
Val = list(map(int, input().split()))
D = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
for i in range(m):
	D = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		D[A[j][i]] += 1
	Max = max(list(D.values()))
	Ans += Val[i] * Max
print(Ans)


(n, m) = [int(i) for i in input().split()]

def ent(s):
	if s == 'A':
		return 0
	if s == 'B':
		return 1
	if s == 'C':
		return 2
	if s == 'D':
		return 3
	if s == 'E':
		return 4
rep = []
for _ in range(m):
	rep.append([0] * 5)
for _ in range(n):
	s = input()
	for k in range(len(s)):
		rep[k][ent(s[k])] += 1
score = [int(i) for i in input().split()]
f = 0
for i in range(m):
	f += score[i] * max(rep[i])
print(f)


from sys import stdin
input = stdin.readline
(n, m) = map(int, input().split())
d = {}
for i in 'ABCDE':
	d[i] = [0] * m
for i in range(n):
	s = input()
	for j in range(m):
		d[s[j]][j] += 1
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	c = 0
	for j in 'ABCDE':
		c = max(c, d[j][i])
	ans += c * a[i]
print(ans)


(n, m) = map(int, input().split())
cc = []
for j in range(m):
	cc.append([0, 0, 0, 0, 0])
for i in range(n):
	line = input()
	for j in range(m):
		cc[j][ord(line[j]) - 65] += 1
score = list(map(int, input().split()))
s = 0
for j in range(m):
	s += score[j] * max(cc[j])
print(s)


stu_ex = input().split(' ')
(student, exam) = [int(a) for a in stu_ex]
ans = [[0, 0, 0, 0, 0] for i in range(0, exam)]
for i in range(0, student):
	std_ans = input()
	for j in range(0, exam):
		choose = 0
		if std_ans[j] == 'B':
			choose = 1
		elif std_ans[j] == 'C':
			choose = 2
		elif std_ans[j] == 'D':
			choose = 3
		elif std_ans[j] == 'E':
			choose = 4
		ans[j][choose] += 1
score = [int(a) for a in input().split(' ')]
max_score = 0
for i in range(0, exam):
	max_score += score[i] * max(ans[i])
print(max_score)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, m) = invr()
	frequency = list()
	for i in range(m):
		frequency.append({'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0})
	for i in range(n):
		a = insr()
		for j in range(m):
			x = a[j]
			frequency[j][x] += 1
	c = inlt()
	ans = 0
	for i in range(m):
		fr = frequency[i]
		ans += max(fr['A'], fr['B'], fr['C'], fr['D'], fr['E']) * c[i]
	print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
S = []
for i in range(n):
	S.append(input())
A = [int(i) for i in input().split()]
import collections
ans = 0
for i in range(m):
	SS = []
	for j in range(n):
		SS.append(S[j][i])
	ans += A[i] * collections.Counter(SS).most_common()[0][1]
print(ans)


(N, M) = map(int, input().split())
studs = [input() for x in range(N)]
S = list(map(int, input().split()))
ans = 0
for i in range(M):
	num = [0] * 5
	for j in range(N):
		num[ord(studs[j][i]) - ord('A')] += 1
	ans += S[i] * max(num)
print(ans)


(n, m) = map(int, input().split())
g = [0] * n
for i in range(n):
	g[i] = input()
a = list(map(int, input().split()))
end = 0
for i in range(m):
	temp = [t[i] for t in g]
	maxt = max([sum([t == c for t in temp]) for c in 'ABCDE'])
	end += maxt * a[i]
print(end)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
from collections import defaultdict, Counter
(n, m) = minput()
d = defaultdict(Counter)
for _ in range(n):
	option = input()
	for j in range(m):
		d[j][option[j]] += 1
a = linput()
k = total = 0
for i in d:
	total += d[i].most_common()[0][1] * a[k]
	k += 1
print(total)


(stud, quest) = [int(x) for x in input().split()]
student_answers = []
for i in range(stud):
	student_answers.append(input())
scores = [int(x) for x in input().split()]
total = 0
for i in range(quest):
	count = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	max = 0
	for k in range(stud):
		count[student_answers[k][i]] += 1
		if count[student_answers[k][i]] > max:
			max = count[student_answers[k][i]]
	total += max * scores[i]
print(total)


(n, m) = map(int, input().split(' '))
y = []
for i in range(n):
	s = input()
	y.append(s)
y1 = list(map(int, input().split()))
count = 0
for i in range(m):
	c = []
	for j in range(n):
		c.append(y[j][i])
	x = max(c.count('A'), c.count('B'), c.count('C'), c.count('D'), c.count('E'))
	count += x * y1[i]
print(count)


(n, x) = [int(x) for x in input().split()]
m = []
for i in range(n):
	m.append(input())
a = list(map(int, input().split()))
ans = 0
for j in range(x):
	na = nb = nc = nd = ne = 0
	for i in range(n):
		if m[i][j] == 'A':
			na += 1
		elif m[i][j] == 'B':
			nb += 1
		elif m[i][j] == 'C':
			nc += 1
		elif m[i][j] == 'D':
			nd += 1
		elif m[i][j] == 'E':
			ne += 1
	ans += a[j] * max(na, nb, nc, nd, ne)
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
l = [input() for _ in range(n)]
s = [*map(int, input().split())]
res = 0
for i in range(m):
	res += s[i] * max(Counter((a[i] for a in l)).values())
print(res)


(n, s) = list(map(int, input().split()))
answers = []
for _ in range(n):
	answers.append(list(input()))
answers = list(zip(*answers))
numbers = list(map(int, input().split()))
ind = 0
ANS = 0
for q in answers:
	counter = dict.fromkeys(q, 0)
	for i in q:
		counter[i] += 1
	maxQ = max(list(counter.values()))
	ANS += maxQ * numbers[ind]
	ind += 1
print(ANS)


(n, m) = map(int, input().split())
mas = [[0] * 5 for i in range(m)]
for i in range(n):
	t = input()
	for j in range(m):
		if t[j] == 'A':
			mas[j][0] += 1
		if t[j] == 'B':
			mas[j][1] += 1
		if t[j] == 'C':
			mas[j][2] += 1
		if t[j] == 'D':
			mas[j][3] += 1
		if t[j] == 'E':
			mas[j][4] += 1
k = list(map(int, input().split()))
ans = 0
for i in range(m):
	s = max(mas[i])
	ans += s * k[i]
print(ans)


import sys
from collections import Counter
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	li = [[] for _ in range(m)]
	for i in range(n):
		s = input().strip()
		for j in range(m):
			li[j].append(s[j])
	L = list(map(int, input().split()))
	ans = 0
	for i in range(m):
		ans += max(Counter(li[i]).values()) * L[i]
	print(ans)
solve()


(n, m) = map(int, input().split())
l = [''] * m
for _ in range(n):
	s = input()
	for i in range(m):
		l[i] += s[i]
li = list(map(int, input().split()))
ans = 0
for i in range(m):
	l1 = list(l[i])
	s = set(l1)
	mx = []
	for y in s:
		mx.append(l1.count(y))
	mxx = max(mx)
	ans += mxx * li[i]
print(ans)


(n, m) = input().split()
n = int(n)
m = int(m)
ans = []
for i in range(n):
	a = input().strip()
	ans.append(a)
w = input().split()
w = [int(i) for i in w]
s = [dict() for _ in range(m)]
for a in ans:
	for i in range(m):
		if a[i] in s[i]:
			s[i][a[i]] += 1
		else:
			s[i][a[i]] = 1
total = 0
for i in range(m):
	v = max(list(s[i].values()))
	total += w[i] * v
print(total)


(n, m) = list(map(int, input().split()))
sts = [[0, 0, 0, 0, 0] for _ in range(m)]
for i in range(n):
	s = input()
	for (j, c) in enumerate(s):
		sts[j][int(ord(c[0]) - ord('A'))] += 1
ansval = list(map(int, input().split()))
for i in range(m):
	for j in range(5):
		sts[i][j] *= ansval[i]
sm = 0
for i in range(m):
	sm += max(sts[i])
print(sm)


import sys

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	points = ['A', 'B', 'C', 'D', 'E']
	lst = [0] * n
	for i in range(n):
		lst[i] = input()
	ans = list(map(int, sys.stdin.readline().split()))
	isum = 0
	for i in range(m):
		lstcount = [0] * 5
		for j in range(n):
			index = points.index(lst[j][i])
			lstcount[index] += 1
		isum += max(lstcount) * ans[i]
	sys.stdout.write(str(isum))
main()


import operator
(n, m) = map(int, input().split())
lit = []
for i in range(n):
	x = list(input())
	lit.append(x)
wait = list(map(int, input().split()))
dict1 = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
count = 0
for i in range(m):
	for j in range(n):
		dict1[lit[j][i]] += 1
	count += max(dict1.values()) * wait[i]
	dict1 = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
print(count)


(n, m) = [int(x) for x in input().split(' ')]
arr = []
for _ in range(n):
	s = input()
	arr.append(s)
scores = [int(x) for x in input().split(' ')]
ans = 0
for x in range(m):
	counter = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for item in arr:
		counter[item[x]] += 1
	ans += scores[x] * max(counter.values())
print(ans)


(n, m) = map(int, input().split())
ans = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(m)]
for j in range(n):
	line = input()
	for i in range(m):
		ans[i][line[i]] += 1
marks = list(map(int, input().split()))
out = 0
for i in range(m):
	out += marks[i] * max(ans[i].values())
print(out)


(n, m) = map(int, input().split())
L = []
ans = 0
for i in range(n):
	L.append(list(input()))
Marks = list(map(int, input().split()))
for i in range(m):
	countA = 0
	countB = 0
	countC = 0
	countD = 0
	countE = 0
	for j in range(n):
		if L[j][i] == 'A':
			countA += 1
		if L[j][i] == 'B':
			countB += 1
		if L[j][i] == 'C':
			countC += 1
		if L[j][i] == 'D':
			countD += 1
		if L[j][i] == 'E':
			countE += 1
	ans += max(countA, countB, countC, countD, countE) * Marks[i]
print(ans)


def int_multiple():
	return [int(c) for c in input().split()]

def int_single():
	return int(input())

def str_multiple():
	return [c for c in input().split()]

def str_single():
	return input()
(n, m) = int_multiple()
aa = []
for j in range(m):
	d = [0] * 5
	aa.append(d)
ans = []
for i in range(n):
	temp_a = str_single()
	for j in range(m):
		aa[j][ord(temp_a[j]) - 65] += 1
vals = int_multiple()
res = 0
for i in range(m):
	res += max(aa[i]) * vals[i]
print(res)


from sys import stdin
(n, m) = map(int, stdin.readline().strip().split())
s = []
dp = [[0, 0, 0, 0, 0] for i in range(m)]
for i in range(n):
	s.append(stdin.readline().strip())
	for j in range(m):
		dp[j][ord(s[i][j]) - ord('A')] += 1
s1 = list(map(int, stdin.readline().strip().split()))
arr = ['A', 'B', 'C', 'D', 'E']
ans = 0
for i in range(m):
	ans += max(dp[i][0] * s1[i], dp[i][1] * s1[i], dp[i][2] * s1[i], dp[i][3] * s1[i], dp[i][4] * s1[i])
print(ans)


nm = input().split()
(n, m) = (int(nm[0]), int(nm[1]))
a = []
for i in range(n):
	a.append(str(input()))
arr = list(map(int, input().split()))
s = 0
for i in range(m):
	b = []
	for j in range(n):
		b.append(a[j][i])
	c = max(b.count('A'), b.count('B'), b.count('C'), b.count('D'), b.count('E'))
	s += c * arr[i]
print(s)


x = input()
x = x.split()
n = int(x[0])
m = int(x[1])
q = []
k = []
total = 0
for i in range(0, n):
	q.append(input())
y = input()
y = y.split()
for i in range(0, m):
	k.clear()
	for j in q:
		k.append(j[i])
	a = k.count('A')
	b = k.count('B')
	c = k.count('C')
	d = k.count('D')
	e = k.count('E')
	z = [a, b, c, d, e]
	z.sort(reverse=True)
	total += int(y[i]) * int(z[0])
print(total)


(n, m) = map(int, input().split())
s = []
ans = []
for _ in range(n):
	s.append(input())
for i in range(m):
	a = [0, 0, 0, 0, 0]
	for j in range(n):
		if s[j][i] == 'A':
			a[0] += 1
		elif s[j][i] == 'B':
			a[1] += 1
		elif s[j][i] == 'C':
			a[2] += 1
		elif s[j][i] == 'D':
			a[3] += 1
		else:
			a[4] += 1
	ans.append(max(a))
q = list(map(int, input().split()))
total = 0
for i in range(m):
	total += q[i] * ans[i]
print(total)


(x, y) = map(int, input().split())
dict = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
vals = []
l = []
for i in range(x):
	l.append(input())
for j in range(y):
	for m in range(x):
		dict[l[m][j]] += 1
	vals.append(dict[max(dict.keys(), key=lambda k: dict[k])])
	dict = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
mult = list(map(int, input().split()))
sum = 0
for g in range(y):
	sum += mult[g] * vals[g]
print(sum)


(n, m) = (int(x) for x in input().split())
answers = [input() for x in range(n)]
points = [int(x) for x in input().split()]
ans = 0
for i in range(m):
	count = [0] * 5
	for j in range(n):
		count[ord(answers[j][i]) - ord('A')] += 1
	ans += max(count) * points[i]
print(ans)


from collections import Counter
(n, m) = [int(i) for i in input().split()]
arr = [Counter() for _ in range(m)]
for _ in range(n):
	for (i, c) in enumerate(input()):
		arr[i][c] += 1
p = [int(i) for i in input().split()]
ans = 0
for (r, cntr) in zip(p, arr):
	ans += r * cntr.most_common(1)[0][1]
print(ans)


from collections import Counter

def mostCommon(lst):
	return [Counter(col).most_common(1)[0][0] for col in zip(*lst)]
(n, m) = map(int, input().split())
a = [list(map(str, input())) for i in range(n)]
ma = list(map(int, input().split()))
aa = mostCommon(a)
l = [0] * m
for i in range(n):
	for j in range(m):
		if a[i][j] == aa[j]:
			l[j] += 1
ans = 0
for i in range(m):
	ans += l[i] * ma[i]
print(ans)


(n, m) = map(int, input().split())
Q = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
L = [[0, 0, 0, 0, 0] for i in range(m)]
for i in range(n):
	k = input()
	for j in range(m):
		L[j][Q[k[j]]] += 1
A = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += A[i] * max(L[i])
print(ans)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, m) = mapin()
d = {j: {i: 0 for i in 'ABCDE'} for j in range(m)}
for i in range(n):
	s = input()
	for j in range(m):
		d[j][s[j]] += 1
z = listin()
ans = 0
for i in range(m):
	ans += max(list(d[i].values())) * z[i]
print(ans)


(stds, ques) = map(int, input().split(' '))
ans = [input() for i in range(stds)]
score = list(map(int, input().split(' ')))
std_choice = []
for i in range(ques):
	choice = ''.join([s[i] for s in ans])
	std_choice.append(choice)

def option(choice):
	return max([choice.count(i) for i in 'ABCDE'])
print(sum([option(std_choice[i]) * score[i] for i in range(ques)]))


a = list(map(int, input().split()))
c = []
x = 0
for i in range(a[0]):
	b = input()
	c.append(b)
n = list(map(int, input().split()))
for i in range(a[1]):
	d = []
	for j in range(a[0]):
		d.append(c[j][i])
	f = max(d.count('A'), d.count('B'), d.count('C'), d.count('D'), d.count('E'))
	x = x + f * n[i]
print(x)


a = [{} for i in range(1005)]
(n, m) = list(map(lambda x: int(x), input().split()))
for i in range(n):
	s = input()
	for (j, c) in enumerate(s):
		if a[j].get(c) is None:
			a[j][c] = 1
		else:
			a[j][c] += 1
ans = 0
for (i, e) in enumerate(input().split()):
	a[i] = sorted(a[i].values(), reverse=True)
	ans += int(e) * a[i][0]
print(ans)


(n, m) = map(int, input().split())
lst = [[0 for x in range(5)] for x in range(m)]
for i in range(n):
	k = input()
	for s in range(len(k)):
		lst[s][ord(k[s]) - 65] += 1
r = list(map(int, input().split()))
count = 0
for i in range(m):
	count += max(lst[i]) * r[i]
print(count)


(n, m) = [int(i) for i in input().split()]
answer = []
individual = []
points = []
mode = [0] * m
total = 0
for i in range(n):
	answer.append(input())
points = [int(p) for p in input().split()]
for i in range(m):
	ans = ''
	for j in range(len(answer)):
		ans += answer[j][i]
	individual.append(sorted(ans))
if n == 1:
	print(sum(points))
	exit()
for i in range(len(individual)):
	counter = 1
	for j in range(1, len(individual[i])):
		if individual[i][j] == individual[i][j - 1]:
			counter += 1
		else:
			counter = 1
		mode[i] = max(mode[i], counter)
for i in range(len(mode)):
	total += mode[i] * points[i]
print(total)


def increase(cnt, letter):
	if letter not in cnt:
		cnt[letter] = 1
	else:
		cnt[letter] += 1
(n, m) = list(map(int, input().split()))
strings = []
for i in range(n):
	strings.append(input())
points = list(map(int, input().split()))
ans = 0
for qu in range(m):
	cnt = {}
	mx = 0
	for person in range(n):
		increase(cnt, strings[person][qu])
		mx = max(mx, cnt[strings[person][qu]])
	ans += points[qu] * mx
print(ans)


from collections import Counter
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
b = list(map(int, input().split()))
cnt = []
ans = []
result = 0
for i in range(m):
	temp = []
	for j in range(n):
		temp.append(a[j][i])
	cnt.append(temp)
for i in range(len(cnt)):
	temp = Counter(cnt[i])
	temp1 = temp.most_common(1)[0][0]
	ans.append(temp1)
for i in range(len(ans)):
	result = result + cnt[i].count(ans[i]) * b[i]
print(result)


def translate(answers):
	answer_list = list(answers)
	answer_num = list()
	for i in answer_list:
		answer_num.append(ord(i) - ord('A'))
	return answer_num
input_arr = [int(i) for i in input().split(' ')]
n = input_arr[0]
m = input_arr[1]
score_card = list()
for i in range(m):
	score_card.append(list())
	for j in range(5):
		score_card[i].append(0)
maximum_ans = list()
for i in range(n):
	answers = translate(input())
	for j in range(m):
		score_card[j][answers[j]] += 1
		if i == 0:
			maximum_ans.append(score_card[j][answers[j]])
		if score_card[j][answers[j]] > maximum_ans[j]:
			maximum_ans[j] = score_card[j][answers[j]]
points = [int(i) for i in input().split(' ')]
max_sum = 0
for i in range(len(points)):
	max_sum += maximum_ans[i] * points[i]
print(max_sum)


(n, m) = input().split()
n = int(n)
m = int(m)
A = [0] * m
B = [0] * m
C = [0] * m
D = [0] * m
E = [0] * m
output = 0
for i in range(0, n):
	a = input()
	for j in range(0, m):
		if a[j] == 'A':
			A[j] = A[j] + 1
		elif a[j] == 'B':
			B[j] = B[j] + 1
		elif a[j] == 'C':
			C[j] = C[j] + 1
		elif a[j] == 'D':
			D[j] = D[j] + 1
		else:
			E[j] = E[j] + 1
b = list(map(int, input().split()))
for i in range(0, m):
	output = output + b[i] * max(A[i], B[i], C[i], D[i], E[i])
print(output)


(n, m) = map(int, input().split())
l = [[] for _ in range(m)]
for i in range(n):
	ll = list(input())
	for j in range(m):
		l[j].append(ll[j])
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	ma = 0
	for j in ['A', 'B', 'C', 'D', 'E']:
		ma = max(l[i].count(j), ma)
	ans += a[i] * ma
print(ans)


(n, m) = [int(x) for x in input().split()]
answers = []
for i in range(n):
	ans = input()
	answers.append(ans)
score = [int(x) for x in input().split()]
total = 0
for i in range(m):
	dic = dict()
	for j in range(n):
		key = answers[j][i]
		if key not in dic:
			dic[key] = 0
		dic[key] += 1
	maxo = 0
	for key in dic:
		if dic[key] > maxo:
			maxo = dic[key]
	total += maxo * score[i]
print(total)


line1 = input()
tmp1 = line1.split(' ')
(n, m) = (int(tmp1[0]), int(tmp1[1]))
cnt = [dict(A=0, B=0, C=0, D=0, E=0) for _ in range(m)]
for __ in range(n):
	line = input()
	for (idx, c) in enumerate(line):
		cnt[idx][c] += 1
line2 = input()
dd = [int(i) for i in line2.split(' ')]
ans = 0
for (item, d) in zip(cnt, dd):
	a = max(item['A'], item['B'], item['C'], item['D'], item['E'])
	ans += a * d
print(ans)


from sys import stdin
option = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}

def main():
	(n, m) = map(int, stdin.readline().split())
	answers = list()
	for _ in range(n):
		answers.append(stdin.readline().strip())
	aux = list()
	for u in range(m):
		tmp = [0, 0, 0, 0, 0]
		for v in range(n):
			tmp[option[answers[v][u]]] += 1
		aux.append(max(tmp))
	points = list(map(int, stdin.readline().split()))
	ans = 0
	for i in range(m):
		ans += points[i] * aux[i]
	print(ans)
main()


maxsum = 0
(a, b) = map(int, input().split())
tests = []
for i in range(a):
	tests += [input()]
price = list(map(int, input().split()))
quantity = [0] * b
for i in range(b):
	s = ''
	for j in range(a):
		s += tests[j][i]
	maxsum += price[i] * max(s.count('A'), s.count('B'), s.count('C'), s.count('D'), s.count('E'))
print(maxsum)


from collections import Counter
(n, m) = list(map(int, input().split()))
s = [input() for _ in range(n)]
s = [*list(zip(*s))]
a = [*list(map(int, input().split()))]
print(sum((x.most_common(1)[0][1] * y for (x, y) in zip(list(map(Counter, s)), a))))


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(input())
marks = list(map(int, input().split()))
hash = [[0, 0, 0, 0, 0] for i in range(m)]
for j in range(m):
	for i in range(n):
		hash[j][ord(arr[i][j]) - 65] += 1
ans = 0
for i in range(m):
	ans += max(hash[i]) * marks[i]
print('%d\n' % ans)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
(n, m) = get_int_list()
answers = [0] * n
for i in range(n):
	answers[i] = get_string()
score = get_int_list()
max_answer = [0] * m
for j in range(m):
	max_response = [0, 0, 0, 0, 0]
	for i in range(n):
		max_response[ord(answers[i][j]) - ord('A')] += 1
	max_answer[j] = max(max_response) * score[j]
print(sum(max_answer))


(n, m) = map(int, input().split())
answers = []
for i in range(n):
	answers.append(input())
values = list(map(int, input().split()))
maximum = []
for i in range(m):
	counta = 0
	countb = 0
	countc = 0
	countd = 0
	counte = 0
	for j in range(n):
		if answers[j][i] == 'A':
			counta += 1
		elif answers[j][i] == 'B':
			countb += 1
		elif answers[j][i] == 'C':
			countc += 1
		elif answers[j][i] == 'D':
			countd += 1
		else:
			counte += 1
	maximum.append(max(counta, countb, countc, countd, counte))
max_points = 0
for i in range(m):
	max_points += maximum[i] * values[i]
print(max_points)


(n, m) = map(int, input().split())
a = [list(input()) for i in range(n)]
count = [[0 for i in range(5)] for i in range(m)]
b = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		count[j][ord(a[i][j]) - ord('A')] += 1
ans = 0
for i in range(m):
	ans += max(count[i]) * b[i]
print(ans)


from collections import defaultdict
import operator
(n, m) = map(int, input().split())
rec = [{} for i in range(m)]
for i in range(m):
	rec[i] = defaultdict(lambda : 0, rec[i])
answers = []
for i in range(n):
	answers.append(list(input()))
scores = list(map(int, input().split()))
for i in range(n):
	for j in range(m):
		rec[j][answers[i][j]] += 1
ans = 0
for i in range(m):
	ans += scores[i] * max(rec[i].items(), key=operator.itemgetter(1))[1]
print(ans)


from collections import Counter

def main():
	(n, m) = map(int, input().split())
	answers = []
	for i in range(n):
		answers.append(input().strip())
	scores = list(map(int, input().split()))
	maxscore = 0
	for i in range(m):
		c = Counter((answer[i] for answer in answers))
		maxscore += c.most_common()[0][1] * scores[i]
	return maxscore
print(main())


(n, k) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
a = list(map(int, input().split()))
ans = 0
for i in range(k):
	b = [0] * 5
	for j in range(n):
		b[ord(s[j][i]) - ord('A')] += 1
	tmp = 0
	for j in range(5):
		tmp = max(tmp, b[j])
	ans += tmp * a[i]
print(ans)


(n, m) = map(int, input().split())
Answers = [0] * m
for i in range(n):
	a = input()
	for j in range(m):
		if i == 0:
			Answers[j] = [0, 0, 0, 0, 0]
		Answers[j][ord(a[j]) - ord('A')] += 1
marks = list(map(int, input().split()))
maxs = 0
for i in range(m):
	maxs += max(Answers[i][0], Answers[i][1], Answers[i][2], Answers[i][3], Answers[i][4]) * marks[i]
print(maxs)


(n, m) = map(int, input().rstrip().split())
marks = []
for i in range(n):
	marks.append(input())
a = list(map(int, input().rstrip().split()))
su = 0
for i in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		d[marks[j][i]] += 1
	mx = 0
	for k in d.keys():
		if d[k] > mx:
			mx = d[k]
	su += mx * a[i]
print(su)


(n, m) = map(int, input().split(' '))
answer = []
count = [[0, 0, 0, 0, 0] for i in range(m)]
for i in range(n):
	answer.append(input())
	for j in range(m):
		count[j][ord(answer[i][j]) - ord('A')] += 1
coin = list(map(int, input().split(' ')))
res = 0
for i in range(m):
	res += coin[i] * max(count[i])
print(res)


string = input()
ret = 0
val = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
nm = string.split()
freqs = [[0] * 5 for i in range(int(nm[1]))]
for i in range(int(nm[0])):
	string1 = input()
	for j in range(len(string1)):
		freqs[j][val[string1[j]]] += 1
string2 = input()
points = string2.split()
for i in range(int(nm[1])):
	ret += int(points[i]) * max(freqs[i][0], freqs[i][1], freqs[i][2], freqs[i][3], freqs[i][4])
print(ret)


import itertools

def input_ints():
	return list(map(int, input().split()))

def output_list(v):
	print(' '.join((str(x) for x in v)))

def main():
	(n, m) = input_ints()
	s = []
	for i in range(n):
		s.append(input())
	a = input_ints()
	ans = 0
	for j in range(m):
		x = ''.join((s[i][j] for i in range(n)))
		c = max((x.count(p) for p in 'ABCDE'))
		ans += c * a[j]
	print(ans)
main()


def transpose(l1, l2):
	for i in range(len(l1[0])):
		row = []
		for item in l1:
			row.append(item[i])
		l2.append(row)
	return l2
(n, m) = map(int, input().split())
l1 = []
l2 = []
for i in range(n):
	s = input()
	k = list(s)
	l1.append(k)
l3 = list(map(int, input().split()))
l2 = transpose(l1, l2)
sum = 0
diff = []

def most_frequent(List):
	return max(set(List), key=List.count)
for i in range(len(l2)):
	o = most_frequent(l2[i])
	diff.append(l2[i].count(o))
for i in range(m):
	sum = sum + diff[i] * l3[i]
print(sum)


(n, m) = map(int, input().split())
ch = []
i = 0
while i < n:
	i += 1
	s = list(input())
	ch.append(s)
a = list(map(int, input().split()))
sol = 0
for j in range(m):
	ask = [0] * 5
	for i in range(n):
		ask[ord(ch[i][j]) - 65] += 1
	sol += max(ask) * a[j]
print(sol)


(n, m) = map(int, input().split())
answers = [[0] * 5 for _ in range(m)]
for i in range(n):
	s = input()
	for j in range(len(s)):
		answers[j][ord(s[j]) % 5] += 1
s = 0
imp = list(map(int, input().split()))
for i in range(len(answers)):
	s += imp[i] * max(answers[i])
print(s)


(n, m) = map(int, input().split())
cnt = [None] * m
for i in range(m):
	cnt[i] = [0, 0, 0, 0, 0]
for i in range(n):
	s = input()
	for j in range(m):
		cnt[j][ord(s[j]) - ord('A')] += 1
l = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += l[i] * max(cnt[i])
print(ans)


(a, b) = map(int, input().split())
ss = []
for _ in range(a):
	s = input()
	ss.append(s)
arr = [int(i) for i in input().split()]
doi = 0
for i in range(b):
	arr1 = [0] * 5
	for j in range(a):
		arr1[ord(ss[j][i]) - 65] += 1
	doi += max(arr1) * arr[i]
print(doi)


import collections
(n, m) = list(map(int, input().split()))
options = [input() for i in range(n)]
marks = list(map(int, input().split()))
total_marks = 0
for i in range(0, m):
	cnt = collections.Counter()
	for student in options:
		cnt[student[i]] += 1
	total_marks += max(cnt.values()) * marks[i]
print(total_marks)


(n, m) = [int(i) for i in input().split()]
mas = [[0 for i in range(5)] for j in range(m)]
answer = 0
for i in range(n):
	s = input()
	for j in range(m):
		if s[j] == 'A':
			c = 0
		elif s[j] == 'B':
			c = 1
		elif s[j] == 'C':
			c = 2
		elif s[j] == 'D':
			c = 3
		else:
			c = 4
		mas[j][c] += 1
c = [int(i) for i in input().split()]
for i in range(m):
	answer += max(mas[i]) * c[i]
print(answer)


(n, m) = [int(i) for i in input().split()]
s = [input() for i in range(n)]
a = [int(i) for i in input().split()]
res = 0
tmp = []
for j in range(m):
	t = ''
	for i in range(n):
		t += s[i][j]
	tmp.append(t)
for i in range(len(tmp)):
	marks = [tmp[i].count(k) for k in 'ABCDE']
	m = max(marks)
	res += m * a[i]
print(res)


def most_frequent(items):
	d = {}
	(count, itm) = (0, '')
	for item in reversed(items):
		d[item] = d.get(item, 0) + 1
		if d[item] >= count:
			(count, itm) = (d[item], item)
	return count
(n, m) = map(int, input().split())
answers = []
for _ in range(n):
	answers.append(input())
weights = list(map(int, input().split()))
res = 0
for i in range(m):
	l = [x[i] for x in answers]
	count = most_frequent(l)
	res += count * weights[i]
print(res)


(n, m) = [int(x) for x in input().split()]
A = [0] * 1010
B = [0] * 1010
C = [0] * 1010
D = [0] * 1010
E = [0] * 1010
for case in range(n):
	answers = input()
	for ansi in range(len(answers)):
		ans = answers[ansi]
		if ans == 'A':
			A[ansi] += 1
		elif ans == 'B':
			B[ansi] += 1
		elif ans == 'C':
			C[ansi] += 1
		elif ans == 'D':
			D[ansi] += 1
		elif ans == 'E':
			E[ansi] += 1
points = [int(x) for x in input().split()]
sum = 0
for i in range(len(points)):
	best = max(A[i], max(B[i], max(C[i], max(D[i], E[i]))))
	sum += best * points[i]
print(sum)


(n, m) = map(int, input().split())
answs = [[0] * 5 for i in range(m)]
for i in range(n):
	ians = input()
	for j in range(m):
		answs[j][ord(ians[j]) - ord('A')] += 1
bst = [0] * m
for i in range(m):
	maxj = -1
	maxsum = -1
	for j in range(5):
		if answs[i][j] > maxsum:
			maxj = j
			maxsum = answs[i][j]
	bst[i] = maxj
W = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += W[i] * answs[i][bst[i]]
print(ans)


def find_appear(alist):
	char = ['A', 'B', 'C', 'D', 'E']
	result = [0] * 5
	for i in range(len(alist)):
		for j in range(5):
			if alist[i] == char[j]:
				result[j] += 1
	return max(result)
(n, m) = map(int, input().split())
result = []
char = ['A', 'B', 'C', 'D', 'E']
max_point = 0
for i in range(m):
	result.append([0, 0, 0, 0, 0])
for i in range(n):
	answer = input()
	for j in range(m):
		for k in range(5):
			if answer[j] == char[k]:
				result[j][k] += 1
				break
point_table_raw = input().split()
point_table = [int(x) for x in point_table_raw]
for i in range(m):
	max_point += max(result[i]) * point_table[i]
print(max_point)


import collections
(n, m) = map(int, input().split())
A = []
for _ in range(n):
	s = input()
	A.append(s)
B = []
for j in range(m):
	p = ''
	for i in range(n):
		p += A[i][j]
	B.append(p)
C = [int(x) for x in input().split()]
Res = 0
for i in range(m):
	Res += C[i] * max(collections.Counter(B[i]).values())
print(Res)


def ImportantExam(n, m):
	l = []
	for i in range(n):
		l.append(input())
	score = [int(x) for x in input().split()]
	ans = 0
	for i in range(m):
		s = dict()
		for j in range(n):
			if l[j][i] in s:
				s[l[j][i]] += 1
			else:
				s[l[j][i]] = 1
		ans += max(s.values()) * score[i]
	print(ans)
(n, m) = (int(x) for x in input().split())
ImportantExam(n, m)


(n, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * m
d = [0] * m
e = [0] * m
for i in range(n):
	s = input()
	for j in range(len(s)):
		if s[j] == 'A':
			a[j] += 1
		elif s[j] == 'B':
			b[j] += 1
		elif s[j] == 'C':
			c[j] += 1
		elif s[j] == 'D':
			d[j] += 1
		else:
			e[j] += 1
mk = [int(mk) for mk in input().split()]
marks = 0
for i in range(m):
	marks += max(a[i], b[i], c[i], d[i], e[i]) * mk[i]
print(marks)


(n, m) = map(int, input().split())
from collections import defaultdict
(l, summ) = ([defaultdict(int) for i in range(m)], 0)
for i in range(n):
	(ans, k) = (input(), 0)
	for j in ans:
		l[k][j] += 1
		k += 1
val = list(map(int, input().split()))
for i in range(m):
	summ += val[i] * max(l[i].values())
print(summ)


(n, m) = map(int, input().split())
c2ix = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
counts = [[0 for _ in range(5)] for _ in range(m)]
for _ in range(n):
	s = input()
	for (i, c) in enumerate(s):
		counts[i][c2ix[c]] += 1
a = list(map(int, input().split()))
result = 0
for (i, ai) in enumerate(a):
	result += ai * max(counts[i])
print(result)


possible_ans = list('ABCDE')
(n, m) = map(int, input().split())
ans2f = [dict([(a, 0) for a in possible_ans]) for _ in range(m)]
for _ in range(n):
	ans = list(input())
	assert len(ans) == m
	for (j, a) in enumerate(ans):
		ans2f[j][a] += 1
weights = [max(_.items(), key=lambda kv: kv[1])[1] for _ in ans2f]
marks = list(map(int, input().split()))
assert len(marks) == m
s = 0
for (w, mark) in zip(weights, marks):
	s += w * mark
print(s)


(n, m) = map(int, input().split())
k = []
for i in range(n):
	k.append(input())
k = tuple(zip(*k))
ans = 0
l = list(map(int, input().split()))
for i in range(m):
	ans += max(k[i].count('A'), k[i].count('B'), k[i].count('C'), k[i].count('D'), k[i].count('E')) * l[i]
print(ans)


(n, m) = map(int, input().split())
sp = [list(input()) for _ in range(n)]
a = list(map(int, input().split()))
sp1 = []
s = 0
for j in range(m):
	sp1.append([i[j] for i in sp])
for i in range(m):
	x = list(set(sp1[i]))
	while len(x) != 1:
		if sp1[i].count(x[0]) >= sp1[i].count(x[1]):
			del x[1]
		else:
			del x[0]
	s += sp1[i].count(x[0]) * a[i]
print(s)


q = []
qs = []
n = list(map(int, input().split()))
col = n[0]
colq = n[1]
s = ''
while n[0] != 0:
	n[0] -= 1
	s += str(input())
ss = ''
for i in range(0, colq):
	z = i
	coll = col
	while coll > 0:
		ss = ss + s[z]
		z += colq
		coll -= 1
buf = 0
for i in range(0, len(ss), col):
	p = ss[i:col * (buf + 1)]
	a = p.count('A')
	b = p.count('B')
	c = p.count('C')
	d = p.count('D')
	e = p.count('E')
	buf += 1
	q.append(max(a, b, c, d, e))
rez = list(map(int, input().split()))
viv = 0
for i in range(0, len(rez)):
	viv = viv + q[i] * rez[i]
print(viv)


from collections import defaultdict as dd
import math
import sys
import heapq
for _ in range(1):
	d = dd(int)
	(n, k) = [int(i) for i in input().split()]
	l = [dd(int) for i in range(k)]
	for i in range(n):
		s = input()
		for j in range(len(s)):
			l[j][s[j]] += 1
	ans = 0
	a = [int(i) for i in input().split()]
	for i in range(k):
		temp = []
		for j in l[i]:
			temp.append(l[i][j] * a[i])
		ans += max(temp)
	print(ans)


from collections import Counter
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
cor = [int(el) for el in input().split()]
ans = 0
for i in range(m):
	dic = [0, 0, 0, 0, 0]
	for p in a:
		dic[ord(p[i]) - ord('A')] += 1
	ans += max(dic) * cor[i]
print(ans)


(n, m) = map(int, input().split())
(answer, total) = ([], 0)
for i in range(n):
	answer.append(input())
points = list(map(int, input().split()))
for j in range(m):
	correct = [0] * 5
	for i in range(n):
		correct[ord(answer[i][j]) - 65] += 1
	total += max(correct) * points[j]
print(total)


from collections import defaultdict
(n, m) = map(int, input().split())
a = [defaultdict(int) for i in range(m)]
for i in range(n):
	for (j, x) in enumerate(input()):
		a[j][x] += 1
s = 0
for (i, x) in enumerate(map(int, input().split())):
	s += x * max(a[i].values())
print(s)


import re
from collections import deque
from functools import reduce
from heapq import *
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep

def fmatr(matrix, lnsep: str=linesep, fieldsep: str=' ') -> str:
	return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))

def fbool(boolval: int) -> str:
	return ['No', 'Yes'][boolval]

def solve() -> None:
	(n, m) = map(int, input().strip().split())
	s = [input().strip() for i in range(n)]
	a = list(map(int, input().strip().split()))
	ans = 0
	for i in range(m):
		d = {}
		answers = map(itemgetter(i), s)
		for answer in answers:
			if not answer in d.keys():
				d[answer] = 0
			d[answer] += 1
		ans += max(d.values()) * a[i]
	print(ans)
solve()


(n, m) = map(int, input().split())
x = []
y = []
for i in range(n):
	S_i = input()
	x.append(S_i)
A = list(map(int, input().split()))
for j in range(m):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	for i in range(n):
		if x[i][j] == 'A':
			a = a + 1
		elif x[i][j] == 'B':
			b = b + 1
		elif x[i][j] == 'C':
			c = c + 1
		elif x[i][j] == 'D':
			d = d + 1
		else:
			e = e + 1
	y.append(max(a, b, c, d, e) * A[j])
print(sum(y))


p = input().rstrip().split(' ')
L = []
PP = 0
B = 0
for i in range(0, int(p[0])):
	d = input().rstrip()
	x = list(d)
	L.append(x)
C = input().rstrip().split(' ')
for i in range(0, int(p[1])):
	l = ['A', 'B', 'C', 'D', 'E']
	q = [0] * 5
	for j in range(0, int(p[0])):
		T = l.index(L[j][i])
		q[T] += 1
	V = max(q)
	B += V * int(C[PP])
	PP += 1
print(B)


from sys import *
(n, k) = map(int, stdin.readline().split())
m = []
for i in range(n):
	m.append(input())
b = list(map(int, input().split()))
ans = 0
for i in range(k):
	a = [0] * 5
	for j in range(n):
		if m[j][i] == 'A':
			a[0] += 1
		elif m[j][i] == 'B':
			a[1] += 1
		elif m[j][i] == 'C':
			a[2] += 1
		elif m[j][i] == 'D':
			a[3] += 1
		elif m[j][i] == 'E':
			a[4] += 1
	ans += b[i] * max(a)
print(ans)


(a, b) = map(int, input().split())
arr = [[0, 0, 0, 0, 0] for i in range(b)]
for i in range(a):
	s = input()
	for j in range(b):
		c = s[j]
		arr[j][ord(c) - ord('A')] += 1
q = list(map(int, input().split()))
s = 0
for i in range(b):
	s += max(arr[i]) * q[i]
print(s)


import operator
nm = [int(x) for x in input().strip().split()]
answers = {}
scores = []
total = 0
for i in range(0, nm[0]):
	answers[i] = list(input().strip())
scores = [int(x) for x in input().strip().split()]
for i in range(0, nm[1]):
	ansdic = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in answers.keys():
		ansdic[answers[j][i]] += 1
	total += scores[i] * max(ansdic.values())
print(total)


(n, m) = [int(x) for x in input().split()]
l = []
for i in range(m):
	l.append([0, 0, 0, 0, 0])
while n:
	n = n - 1
	s = input()
	for i in range(0, len(s)):
		l[i][ord(s[i]) - 65] += 1
l1 = []
for i in l:
	l1.append(max(i))
l2 = list(map(int, input().split()))
print(sum((x * y for (x, y) in zip(l1, l2))))


l = input()
l = l.split(' ')
n = int(l[0])
m = int(l[1])
a = []
for i in range(n):
	a.append(input())
f = {}
mx = []
for i in range(m):
	f[i] = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		f[i][a[j][i]] += 1
	mx.append(max([f[i]['A'], f[i]['B'], f[i]['C'], f[i]['D'], f[i]['E']]))
p = input()
pt = p.split(' ')
res = 0
for i in range(m):
	res = res + int(pt[i]) * mx[i]
print(res)


(x, y) = [int(a) for a in input().split()]
ar = []
for i in range(x):
	n = input()
	ar.append(n)
c = list(map(int, input().split()))[:y]
t = 0
for i in range(y):
	b = [0] * 5
	for j in range(x):
		b[ord(ar[j][i]) - 65] += 1
	t = t + max(b) * c[i]
print(t)


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(input())
marks = list(map(int, input().split()))
total = 0
for i in range(m):
	temp = [0] * 5
	for j in range(n):
		temp[ord(arr[j][i]) - 65] += 1
	total += marks[i] * max(temp)
print(total)


(a, b) = map(int, input().split())
v = []
for i in range(a):
	v.append(input())
s = list(map(int, input().split()))
w = 0
for r in range(b):
	(z, c) = ([], 0)
	for j in range(a):
		z.append(v[j][r])
	x = set(z)
	for i in x:
		c = max(c, z.count(i))
	w += c * s[r]
print(w)


(n, m) = map(int, input().split())
resp = []
for _ in range(n):
	resp.append(list(input()))
marks = list(map(int, input().split()))
total = 0
for i in range(m):
	d = {}
	for j in range(n):
		d[resp[j][i]] = 1 if resp[j][i] not in d else d[resp[j][i]] + 1
	max_freq = 0
	for (_, j) in d.items():
		max_freq = max(max_freq, j)
	total += max_freq * marks[i]
print(total)


(n, m) = map(int, input().split())
test = list()
points = 0
pkt = 0
a = 0
b = 0
c = 0
d = 0
e = 0
for _ in range(n):
	test.append(input())
scores = list(map(int, input().split()))
for j in range(m):
	a = 0
	b = 0
	c = 0
	d = 0
	e = 0
	pkt = 0
	for i in range(n):
		if test[i][j] == 'A':
			a += 1
		if test[i][j] == 'B':
			b += 1
		if test[i][j] == 'C':
			c += 1
		if test[i][j] == 'D':
			d += 1
		if test[i][j] == 'E':
			e += 1
	pkt = max([a, b, c, d, e]) * scores[j]
	points += pkt
print(points)


(n, m) = list(map(int, input().split()))
answer = []
for i in range(n):
	answer.append(input())
marks = list(map(int, input().split()))
max_marks = 0
for i in range(m):
	count = {}
	Max = 0
	for j in answer:
		if j[i] in count:
			count[j[i]] += 1
		else:
			count[j[i]] = 1
		if count[j[i]] > Max:
			Max = count[j[i]]
	max_marks += Max * marks[i]
print(max_marks)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, m) = mp()
	x = []
	for i in range(n):
		s = st()
		x.append(s)
	l = li()
	c = 0
	for i in range(m):
		d = {}
		for j in range(n):
			d[x[j][i]] = d.get(x[j][i], 0) + 1
		a = max(d.values())
		c += a * l[i]
	pr(c)
for _ in range(1):
	solve()


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	tmp = list(input())
	for i in range(len(tmp)):
		key = str(i) + '_' + tmp[i]
		d[key] = d.get(key, 0) + 1
score = [x for x in map(int, input().split())]
sum = 0
for i in range(m):
	m1 = max(d.get(str(i) + '_A', 0), d.get(str(i) + '_B', 0))
	m2 = max(d.get(str(i) + '_C', 0), d.get(str(i) + '_D', 0))
	m = max(max(m1, m2), d.get(str(i) + '_E', 0))
	sum += m * score[i]
print(sum)


(n, m) = map(int, input().split())
translate = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4}
have = []
for i in range(m):
	have.append([0, 0, 0, 0, 0])
for i in range(n):
	st = input()
	for j in range(m):
		have[j][translate[st[j]]] += 1
value = list(map(int, input().split()))
total = 0
for i in range(m):
	total += max(have[i]) * value[i]
print(total)


(n, m) = map(int, input().split())
num = [[0] * 5 for i in range(m)]
for i in range(n):
	ans = input()
	for j in range(m):
		num[j][ord(ans[j]) - ord('A')] += 1
sco = list(map(int, input().split()))
opt = 0
for i in range(m):
	MAX = 0
	for j in range(5):
		MAX = max(MAX, num[i][j])
	opt += MAX * sco[i]
print(opt)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(input())
a = list(map(int, input().split()))
score = 0
for j in range(m):
	(cA, cB, cC, cD, cE) = [0] * 5
	for i in range(n):
		if s[i][j] == 'A':
			cA += 1
		if s[i][j] == 'B':
			cB += 1
		if s[i][j] == 'C':
			cC += 1
		if s[i][j] == 'D':
			cD += 1
		if s[i][j] == 'E':
			cE += 1
	score += max(cA, cB, cC, cD, cE) * a[j]
print(score)


a = input('')
n = 0
m = 0
for i in a.split(' '):
	if n == 0:
		n = int(i)
	else:
		m = int(i)
s = []
for i in range(0, n):
	s.append(input(''))
b = input('')
c = []
for i in b.split(' '):
	c.append(int(i))
tot = 0
for i in range(0, m):
	g = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(0, n):
		s1 = s[j]
		g[s1[i]] = g[s1[i]] + 1
	tot = tot + c[i] * max(g.values())
print(tot)


(N, M) = map(int, input().split())
D = [''] * N
for i in range(N):
	D[i] = input()
s = 'ABCDE'
g = {s[i]: i for i in range(5)}
a = list(map(int, input().split()))
num = 0
for j in range(M):
	d = [0] * 5
	for i in range(N):
		d[g[D[i][j]]] += 1
	num += max(d) * a[j]
print(num)


(n, m) = map(int, input().split())
score = 0
Marks0 = []
for i in range(m):
	Marks0.append([0, 0, 0, 0, 0])
for i in range(n):
	x = input()
	for j in range(m):
		answer = x[0]
		x = x[1:]
		if answer == 'A':
			Marks0[j][0] += 1
		if answer == 'B':
			Marks0[j][1] += 1
		if answer == 'C':
			Marks0[j][2] += 1
		if answer == 'D':
			Marks0[j][3] += 1
		if answer == 'E':
			Marks0[j][4] += 1
Points = [int(s) for s in input().split()]
for k in range(m):
	Marks0[k] = max(Marks0[k])
	score += Marks0[k] * Points[k]
	k += 1
print(score)


(n, m) = map(int, input().split())
d = {i: [0, 0, 0, 0, 0] for i in range(m)}
for i in range(n):
	s = input()
	for j in range(m):
		x = ord(s[j]) - 65
		d[j][x] += 1
a = list(map(int, input().split()))
ans = 0
for k in range(m):
	ans += a[k] * max(d[k])
print(ans)


(n, m) = map(int, input().split())
ans = []
for _ in range(n):
	ans.append(input())
mark = [int(x) for x in input().split()]
fcount = [0] * m
for x in range(m):
	cout = [0] * 5
	for i in range(n):
		cout[ord(ans[i][x]) - 65] += 1
	fcount[x] = max(cout)
maxmark = 0
for j in range(m):
	maxmark = maxmark + fcount[j] * mark[j]
print(maxmark)


(n, m) = map(int, input().split())
l = []
for e in range(n):
	s = input()
	l.append(s)
score = list(map(int, input().split()))
s = 0
for i in range(m):
	common = [0] * 5
	for j in range(n):
		common[ord(l[j][i]) - 65] += 1
	s += max(common) * score[i]
print(s)


from math import *
from collections import *
from itertools import *
from functools import *
from random import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
alnum = lambda x: ord(x) - ord('a')

def main():
	(n, m) = getl()
	scores = [defaultdict(int) for _ in range(m)]
	for i in range(n):
		s = input()
		for (j, x) in enumerate(s):
			scores[j][x] += 1
	a = getl()
	ans = 0
	for j in range(m):
		ans += max(scores[j].values()) * a[j]
	print(ans)
main()


(n, m) = map(int, input().split())
l = []
marks = 0
while n:
	s = input()
	l.append(s)
	n = n - 1
a = list(map(int, input().split()))
l1 = []
ASCII_SIZE = 256

def getMaxOccuringChar(str):
	count = [0] * ASCII_SIZE
	max = -1
	c = ''
	for i in str:
		count[ord(i)] += 1
	for i in str:
		if max < count[ord(i)]:
			max = count[ord(i)]
			c = i
	return c
for i in range(m):
	s1 = ''
	for j in range(len(l)):
		s1 += l[j][i]
	l1.append(s1)
for i in range(len(l1)):
	marks += l1[i].count(getMaxOccuringChar(l1[i])) * a[i]
print(marks)


(n, m) = map(int, input().strip().split())
ll = []
for k in range(n):
	ll.append(input().strip())
numbers = tuple(map(int, input().strip().split()))
s = 0
for k in range(m):
	d = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for kk in range(n):
		d[ll[kk][k]] += 1
	s = s + max(d['A'], d['B'], d['C'], d['D'], d['E']) * numbers[k]
print(s)


(n, m) = [int(i) for i in input().split()]
s = [list(input()) for i in range(n)]
a = [int(i) for i in input().split()]
max_score = 0
for j in range(m):
	b = [0] * 5
	for i in range(n):
		b[ord(s[i][j]) - 65] += a[j]
	max_score += max(b)
print(max_score)


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
student_answers = []
for i in range(n):
	student_answers.append(input())
marks = list(map(int, input().split(' ')))
correct_answers = []
for j in range(m):
	frequencies = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for i in range(n):
		frequencies[student_answers[i][j]] += 1
	correct_answers.append(sorted(zip(frequencies.values(), frequencies.keys()))[-1][1])
total_marks = 0
for i in range(n):
	for j in range(m):
		if student_answers[i][j] == correct_answers[j]:
			total_marks += marks[j]
print(total_marks)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
score = list(map(int, input().split()))
ans = 0
for i in range(m):
	d = [0] * 5
	for x in a:
		if x[i] == 'A':
			d[0] += 1
		elif x[i] == 'B':
			d[1] += 1
		elif x[i] == 'C':
			d[2] += 1
		elif x[i] == 'D':
			d[3] += 1
		else:
			d[4] += 1
	ans += max(d) * score[i]
print(ans)


(s, q) = map(int, input().split())
arr = []
for i in range(s):
	arr.append(input())
score = list(map(int, input().split()))
result = 0
A = 0
B = 0
C = 0
D = 0
E = 0
for j in range(q):
	for k in range(s):
		if arr[k][j] == 'A':
			A += 1
		if arr[k][j] == 'B':
			B += 1
		if arr[k][j] == 'C':
			C += 1
		if arr[k][j] == 'D':
			D += 1
		if arr[k][j] == 'E':
			E += 1
	c = max(A, B, C, D, E)
	result += c * score[j]
	A = 0
	B = 0
	C = 0
	D = 0
	E = 0
print(result)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s += [input()]
a = list(map(int, input().split()))
q = []
for i in range(m):
	q += [[r[i] for r in s]]
r = 0
i = 0
for c in q:
	r += a[i] * max(c.count('A'), c.count('B'), c.count('C'), c.count('D'), c.count('E'))
	i += 1
print(r)


t = [0 * i for i in range(5)]
l = list(map(int, input().split()))
w = []
for i in range(l[0]):
	s = list(str(input()))
	w.append(s)
v = list(map(int, input().split()))
f = 0
for j in range(l[1]):
	t = [0, 0, 0, 0, 0]
	for i in range(l[0]):
		if w[i][j] == 'A':
			t[0] += 1
		elif w[i][j] == 'B':
			t[1] += 1
		elif w[i][j] == 'C':
			t[2] += 1
		elif w[i][j] == 'D':
			t[3] += 1
		else:
			t[4] += 1
	f = f + max(t) * v[j]
print(f)


(a, b) = map(int, input().split())
l = []
for i in range(a):
	s = ''
	s = input()
	l.append(s)
l2 = list(map(int, input().split()))
sum = 0
for i in range(b):
	t = 0
	y = 0
	c = 0
	d = 0
	e = 0
	for j in range(a):
		if l[j][i] == 'A':
			t += 1
		elif l[j][i] == 'B':
			y += 1
		elif l[j][i] == 'C':
			c += 1
		elif l[j][i] == 'D':
			d += 1
		else:
			e += 1
	x = max(t, y, c, d, e)
	sum = sum + x * l2[i]
print(sum)


from sys import stdin
(n, m) = list(map(int, stdin.readline().split()))
string = []
for i in range(n):
	string.append(list(stdin.readline().strip()))
marks = list(map(int, stdin.readline().split()))
ans = 0
for j in range(m):
	freq = [0] * 26
	for i in range(n):
		freq[ord(string[i][j]) - ord('A')] += 1
	ans += max(freq) * marks[j]
print(ans)


(n, m) = map(int, input().split())
from collections import defaultdict
mydick = dict()
mydick = defaultdict(lambda : list(), mydick)
for i in range(n):
	s = input()
	for j in range(m):
		mydick[j].append(s[j])
a = list(map(int, input().split()))
fin = 0
for (keys, values) in mydick.items():
	values = values.sort()
	ans = 0
	count = 1
	for i in range(n - 1):
		if mydick[keys][i] == mydick[keys][i + 1]:
			count += 1
		else:
			ans = max(ans, count)
			count = 1
	ans = max(ans, count)
	fin += ans * a[keys]
print(fin)


from collections import Counter
(n, m) = map(int, input().split())
s = []
for i in range(n):
	s.append(list(input()))
scores = [int(x) for x in input().split()]
q = list(map(list, zip(*s)))
(j, score) = (0, 0)
for i in q:
	c = Counter(i)
	score = score + c.most_common()[0][1] * scores[j]
	j += 1
print(score)


(n, m) = map(int, input().split())
l = [list(input()) for i in range(n)]
arr = list(map(int, input().split()))
ans = 0
for i in range(m):
	dic = {}
	for j in range(n):
		dic[l[j][i]] = dic.get(l[j][i], 0) + 1
	ans += max(list(dic.values())) * arr[i]
print(ans)


(n, m) = map(int, input().split())
s = []
ans = []
for i in range(n):
	s.append(input())
z = list(map(int, input().split()))
q = {k: [] for k in range(m)}
for i in s:
	for j in range(m):
		q[j].append(i[j])
for i in q.values():
	a = i.count('A')
	b = i.count('B')
	c = i.count('C')
	d = i.count('D')
	e = i.count('E')
	if max(a, b, c, d, e) == a:
		ans.append('A')
	elif max(a, b, c, d, e) == b:
		ans.append('B')
	elif max(a, b, c, d, e) == c:
		ans.append('C')
	elif max(a, b, c, d, e) == d:
		ans.append('D')
	elif max(a, b, c, d, e) == e:
		ans.append('E')
balov = 0
for i in s:
	for j in range(len(i)):
		if i[j] == ans[j]:
			balov += z[j]
print(balov)


students = int(input().split()[0])
answers = []
for _ in range(students):
	answers.append(input())
answers = list(zip(*answers))
costs = map(int, input().split())
result = 0
for (a, c) in zip(answers, costs):
	q = {}
	for answer in a:
		if answer not in q:
			q[answer] = 0
		q[answer] += 1
	max_cost = max(q.values()) * c
	result += max_cost
print(result)


(n, m) = [int(x) for x in input().split()]
M = []
som = 0
for i in range(n):
	M.append(input())
D = [int(x) for x in input().split()]
for j in range(m):
	som1 = 0
	som2 = 0
	som3 = 0
	som4 = 0
	som5 = 0
	for i in range(n):
		if M[i][j] == 'A':
			som1 += 1
		elif M[i][j] == 'B':
			som2 += 1
		elif M[i][j] == 'C':
			som3 += 1
		elif M[i][j] == 'D':
			som4 += 1
		else:
			som5 += 1
	som += max(som1, som2, som3, som4, som5) * D[j]
print(som)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
z = []
for i in range(m):
	d1 = {}
	for i in range(5):
		d1[chr(65 + i)] = 0
	z.append(d1)
for _ in range(n):
	s = input()
	for i in range(m):
		z[i][s[i]] += 1
marks = list(map(int, input().split()))
sum = 0
for i in range(m):
	sum = sum + max(z[i].values()) * marks[i]
print(sum)


(n, m) = list(map(int, input().split()))
student_answers = []
for i in range(n):
	student_answers.append(input())
marks_for_questions = list(map(int, input().split()))
final_optimum_arr = []
ans_to_Q = []
final_optimum_answer = 0
total_sum_of_students = 0
for i in range(m):
	for j in range(n):
		ans_to_Q.append(student_answers[j][i])
	if len(ans_to_Q) == n:
		final_optimum_answer = max(set(ans_to_Q), key=ans_to_Q.count)
		total_sum_of_students += marks_for_questions[i] * ans_to_Q.count(final_optimum_answer)
		ans_to_Q.clear()
print(total_sum_of_students)


(n, m) = map(int, input().split())
ans = [[0 for i in range(m)] for i in range(5)]
from collections import *
al = defaultdict(list)
for i in range(n):
	s = input()
	for j in range(len(s)):
		al[j].append(s[j])
z = list(map(int, input().split()))
total = 0
for t in range(m):
	total += max(al[t].count('A'), al[t].count('B'), al[t].count('C'), al[t].count('D'), al[t].count('E')) * z[t]
print(total)


(n, m) = map(int, input().split())
w = [[0 for i in range(5)] for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		code = ord(s[j]) - ord('A')
		w[j][code] += 1
for i in range(m):
	w[i] = max(w[i])
a = list(map(int, input().split()))
c = 0
for i in range(m):
	c += a[i] * w[i]
print(c)


from sys import stdin

def solve(a, c, n, m):
	i = 0
	ans = 0
	while i < m:
		j = 0
		t = [0 for _ in range(5)]
		mas = 0
		while j < n:
			x = ord(a[j][i]) - 65
			t[x] += 1
			if t[x] > mas:
				mas = t[x]
			j += 1
		ans += c[i] * mas
		i += 1
	print(ans)

def main():
	(n, m) = map(int, stdin.readline().split())
	ans = list()
	for _ in range(n):
		ans.append(stdin.readline().strip())
	cor = list(map(int, stdin.readline().split()))
	solve(ans, cor, n, m)
main()


l = list(map(int, input().split()))
students = []
for i in range(l[0]):
	w = input()
	w = list(w)
	students.append(w)
ans = list(map(int, input().split()))
total = 0
for j in range(l[1]):
	dic = {}
	for i in range(l[0]):
		if students[i][j] not in dic.keys():
			dic[students[i][j]] = 1
		else:
			dic[students[i][j]] += 1
	max = 0
	for k in dic.keys():
		if dic[k] > max:
			max = dic[k]
	total += max * ans[j]
print(total)


import sys
import math
import bisect

def main():
	(n, m) = map(int, input().split())
	A = []
	for i in range(m):
		A.append([])
	for i in range(n):
		s = input()
		for j in range(m):
			A[j].append(s[j])
	B = list(map(int, input().split()))
	ans = 0
	for i in range(m):
		d = dict()
		for c in A[i]:
			if c not in d:
				d[c] = 0
			d[c] += 1
		ans += max(d.values()) * B[i]
	print(ans)
main()


from sys import stdin
from string import ascii_uppercase as letters
from collections import defaultdict
input = stdin.readline
(n, m) = list(map(int, input().split()))
a = [input().rstrip() for i in range(n)]
p = list(map(int, input().split()))
if n == 1:
	print(sum(p))
else:
	s = [defaultdict(int) for i in range(m)]
	for i in range(n):
		for j in range(m):
			s[j][a[i][j]] += 1
	correct = []
	for answers in s:
		mv = 0
		letter = ''
		for (l, v) in answers.items():
			if v > mv:
				mv = v
				letter = l
		correct.append(letter)
	ans = 0
	for test in a:
		for i in range(m):
			if test[i] == correct[i]:
				ans += p[i]
	print(ans)


(n, m) = map(int, input().split())
score = [[0] * 5 for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		score[j][ord(s[j]) - ord('A')] += 1
scores = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += scores[i] * max(score[i])
print(ans)


(n, m) = list(map(int, input().split()))
cnt = [0] * m
for i in range(m):
	cnt[i] = [0] * 5
for i in range(n):
	a = input()
	for j in range(m):
		cnt[j][ord(a[j]) - 65] += 1
cost = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += max(cnt[i]) * cost[i]
print(ans)


(n, m) = map(int, input().split())
a = [[0, 0, 0, 0, 0] for i in range(m)]
for i in range(n):
	s = input()
	for j in range(len(s)):
		if s[j] == 'A':
			a[j][0] += 1
		if s[j] == 'B':
			a[j][1] += 1
		if s[j] == 'C':
			a[j][2] += 1
		if s[j] == 'D':
			a[j][3] += 1
		if s[j] == 'E':
			a[j][4] += 1
mx = 0
ans = 0
w = list(map(int, input().split()))
for i in range(len(w)):
	mx = 0
	for j in range(len(a[i])):
		if a[i][j] * w[i] > mx:
			mx = a[i][j] * w[i]
	ans += mx
print(ans)


import math
(n, m) = map(int, input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = [0 for i in range(m)]
d = [0 for i in range(m)]
e = [0 for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		if s[j] == 'A':
			a[j] += 1
		if s[j] == 'B':
			b[j] += 1
		if s[j] == 'C':
			c[j] += 1
		if s[j] == 'D':
			d[j] += 1
		if s[j] == 'E':
			e[j] += 1
peso = [int(i) for i in input().split()]
res = 0
for i in range(m):
	res += peso[i] * max(a[i], max(b[i], max(c[i], max(d[i], e[i]))))
print(res)


(n, m) = map(int, input().split())
letters = [[] for z in range(m)]
for i in range(n):
	inp = list(input())
	for j in range(m):
		letters[j].append(inp[j])
values = list(map(int, input().split()))
answer = 0
for i in range(m):
	d = {}
	for el in letters[i]:
		if el not in d:
			d[el] = 1
		else:
			d[el] += 1
	sd = sorted(d.items(), key=lambda x: x[1], reverse=True)
	answer += values[i] * sd[0][1]
print(answer)


(n, m) = [int(i) for i in input().split()]
answers = [{'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0} for i in range(0, m)]
for i in range(0, n):
	ans = input()
	for j in range(0, m):
		answers[j][ans[j]] += 1
weights = [int(i) for i in input().split()]
score = 0
for j in range(0, m):
	val = 0
	for key in answers[j]:
		val = max(val, answers[j][key])
	score += val * weights[j]
print(score)


from sys import stdin
inpt = stdin.readline

def mode(M):
	return M.count(max(set(M), key=M.count))
(n, m) = map(int, inpt().split())
A = [[0 for i in range(n)] for i in range(m)]
for i in range(n):
	temp = str(inpt())
	for k in range(m):
		A[k][i] = temp[k]
Score = list(map(int, inpt().split()))
a = 0
for l in range(m):
	a += mode(A[l]) * Score[l]
print(a)


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

def sin():
	return input().strip()

def listin():
	return list(map(int, input().strip().split()))

def liststr():
	return list(map(str, input().strip().split()))

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	x // d if x % d == 0 else x // d + 1

def LCM(a, b):
	return a * b // gcd(a, b)

def cnt(arr):
	(a, b, c, d, e) = (0, 0, 0, 0, 0)
	for i in arr:
		if i == 'A':
			a += 1
		elif i == 'B':
			b += 1
		elif i == 'C':
			c += 1
		elif i == 'D':
			d += 1
		elif i == 'E':
			e += 1
	return max(a, b, c, d, e)

def solve():
	(n, m) = listin()
	x = []
	y = []
	for i in range(n):
		x.append([i for i in sin()])
	q = listin()
	z = []
	for i in range(m):
		temp = []
		for j in range(n):
			temp.append(x[j][i])
		z.append(temp)
	summ = 0
	for i in range(m):
		summ += cnt(z[i]) * q[i]
	print(summ)
t = 1
for hula in range(t):
	solve()


(n, m) = map(int, input().split())
d = [[0, 0, 0, 0, 0] for t in range(m)]
for i in range(n):
	s = input()
	for t in range(m):
		d[t][ord(s[t]) - 65] += 1
a = list(map(int, input().split()))
ans = 0
for i in range(m):
	ans += max(d[i]) * a[i]
print(ans)


(n, m) = map(int, input().split())
answers = list((str(input()) for _ in range(n)))
a = list(map(int, input().split()))
res = 0
for i in range(m):
	d = [0, 0, 0, 0, 0]
	for j in range(n):
		if answers[j][i] == 'A':
			d[0] += 1
		if answers[j][i] == 'B':
			d[1] += 1
		if answers[j][i] == 'C':
			d[2] += 1
		if answers[j][i] == 'D':
			d[3] += 1
		if answers[j][i] == 'E':
			d[4] += 1
	res += max(d) * a[i]
print(res)


(n, k) = list(map(int, input().split()))
t = []
g = []
for j in range(n):
	t.append(list(input()))
f = list(map(int, input().split()))
for u in range(k):
	s = []
	for w in range(n):
		s.append(t[w][u])
	g.append(s)
vb = 0
for x in range(len(g)):
	vb += max(g[x].count('A'), g[x].count('B'), g[x].count('C'), g[x].count('D'), g[x].count('E')) * f[x]
print(vb)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
(n, m) = mi()
a = [getdict(list('ABCDE')) for i in range(m)]
for i in range(n):
	t = input()
	for j in range(m):
		a[j][t[j]] += 1
p = li()
t = 0
for i in range(m):
	t += (max(a[i].values()) - 1) * p[i]
print(t)


(n, m) = map(int, input().strip().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
c = [0 for i in range(m)]
d = [0 for i in range(m)]
e = [0 for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		if s[j] == 'A':
			a[j] += 1
		if s[j] == 'B':
			b[j] += 1
		if s[j] == 'C':
			c[j] += 1
		if s[j] == 'D':
			d[j] += 1
		if s[j] == 'E':
			e[j] += 1
v = list(map(int, input().strip().split()))
ans = 0
for i in range(m):
	m = max(a[i], b[i])
	m = max(m, c[i])
	m = max(m, d[i])
	m = max(m, e[i])
	ans += v[i] * m
print(ans)


from collections import *
I = input
print(sum((x * max(c.values()) for (c, x) in zip(map(Counter, zip(*(I() for _ in [0] * int(I().split()[0])))), map(int, I().split())))))


(n, m) = map(int, input().split())
k = []
for i in range(n):
	string = input()
	l = list(string)
	k.append(l)
q = list(map(int, input().split()))
su = 0
for i in range(m):
	t1 = t2 = t3 = t4 = t5 = 0
	for j in range(n):
		if k[j][i] == 'A':
			t1 += 1
		elif k[j][i] == 'B':
			t2 += 1
		elif k[j][i] == 'C':
			t3 += 1
		elif k[j][i] == 'D':
			t4 += 1
		else:
			t5 += 1
	a = max(t1, t2, t3, t4, t5)
	su += a * q[i]
print(su)


s = input()
(n, m) = map(int, s.split(' '))
str1 = []
for i in range(n):
	l = input()
	str1.append(l)
arr = list(map(int, input().split(' ')))
ans = 0
for i in range(m):
	d = {}
	temp = 0
	for j in range(n):
		if str1[j][i] in d:
			d[str1[j][i]] = d[str1[j][i]] + 1
		else:
			d[str1[j][i]] = 1
	for k in d.keys():
		if temp < d[k]:
			temp = d[k]
	ans += temp * arr[i]
print(ans)


(n, m) = map(int, input().split())
l = [[0, 0, 0, 0, 0] for _ in range(m)]
st = 'ABCDE'
for i in range(n):
	s = input()
	for (j, v) in enumerate(s):
		l[j][st.index(v)] += 1
ans = list(map(int, input().split()))
res = 0
c = 0
for i in l:
	res += max(i) * ans[c]
	c += 1
print(res)


import operator
(n, m) = map(int, input().split(' '))
h_maps = [{} for _ in range(m)]
responses = [input() for _ in range(n)]
marks = list(map(int, input().split(' ')))
res = 0
for i in range(m):
	for j in range(n):
		char = responses[j][i]
		if char in h_maps[i]:
			h_maps[i][char] += 1
		else:
			h_maps[i][char] = 1
	res += h_maps[i][max(h_maps[i].items(), key=operator.itemgetter(1))[0]] * marks[i]
print(res)


(n, m) = [int(x) for x in input().split()]
op = []
for N in range(n):
	op.append(list(input()))
a = [int(x) for x in input().split()]
(s, ans) = ('', 0)
for i in range(m):
	val = 0
	s = ''
	for j in range(n):
		s += op[j][i]
	val = max(val, a[i] * max(s.count('A'), s.count('B'), s.count('C'), s.count('D'), s.count('E')))
	ans += val
print(ans)


data = input().split()
n = int(data[0])
m = int(data[1])
ball = 0
arr = []
for i in range(n):
	arr.append(input()[:m])
data1 = list(map(lambda x: int(x), input().split()[:m]))
for i in range(m):
	marks = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0}
	for j in range(n):
		marks[arr[j][i]] += 1
	ball += int(marks[max(marks, key=marks.get)]) * data1[i]
print(ball)


l = input().split()
n = int(l[0])
m = int(l[1])
count = [[0 for i in range(5)] for i in range(m)]
for i in range(n):
	s = input()
	for j in range(m):
		count[j][ord(s[j]) - 65] += 1
li = [0 for i in range(m)]
for i in range(m):
	li[i] = max(count[i])
l = input().split()
arr = [int(i) for i in l]
sumi = 0
for i in range(m):
	sumi += arr[i] * li[i]
print(sumi)