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

Starter code:

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

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")


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)))


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)

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)


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

n, m = list(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)


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(j + 1, cnt, ans)

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)


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)
    


import sys 
import itertools
input = lambda: sys.stdin.readline().rstrip()

n, m = list(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)


#577_A

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)


n, m = map(int, input().split())
d = [{'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(len(s)):
        d[j][s[j]] += 1
array = list(map(int, input().split()))
s = 0
for i in range(m):
    ma = 0
    for el in d[i]:
        if d[i][el] > ma:
            ma = d[i][el]
    s += ma*array[i]
print(s)

def main():
    import sys
    # input = sys.stdin.readline
    
    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 = 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)


from collections import defaultdict
X = list(map(int, input().split()))
Answers = []
for i in range(X[0]):
    Answers.append(input())
points = list(map(int, input().split()))
Sum = 0
for i in range(X[1]):
    Temp = defaultdict(int)
    for j in range(X[0]):
        Temp[Answers[j][i]]+=1
    Sum+=points[i]*max(Temp.values())
print(Sum)

# UB_CodeForces
# Advice: Gain your experience with participating in CodeForces contests
# Location: Behind my desk
# Caption: Contest time
# CodeNumber: 556


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)
    


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=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)




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)


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)

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(cnts)
print(sum(i[0] * i[1] for i in zip(points, cnts)))

#    ~####~~~#####~~~~####~~~######~~#####~~~#####~~~##~~##
#    ##~~##~~##~~##~~##~~##~~~~~##~~~##~~##~~##~~~~~~##~##
#    ##~~##~~#####~~~######~~~~##~~~~#####~~~####~~~~####
#    ##~~##~~##~~##~~##~~##~~~##~~~~~##~~##~~##~~~~~~##~##
#    ~####~~~##~~##~~##~~##~~######~~#####~~~#####~~~##~~##


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 list(f.values()):
            if k > max_f:
                max_f = k
        result += max_f * b[i]
    print(result)


query_count = 1
# query_count = Read.int()
for j in range(query_count):
    solve()