1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < b;i ++) 3 typedef long long ll; 4 using namespace std; 5 inline ll read() 6 { 7 ll ans = 0; 8 char ch = getchar(), last = ' '; 9 while(!isdigit(ch)) last = ch, ch = getchar(); 10 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 11 if(last == '-') ans = -ans; 12 return ans; 13 } 14 inline void write(ll x) 15 { 16 if(x < 0) x = -x, putchar('-'); 17 if(x >= 10) write(x / 10); 18 putchar(x % 10 + '0'); 19 } 20 int n,m; 21 char lst[1002][1002]; 22 int gd[1002]; 23 int main() 24 { 25 n = read(),m = read(); 26 memset(lst,0,sizeof(lst)); 27 memset(gd,0,sizeof(gd)); 28 _for(i,0,n) 29 scanf("%s",lst[i]); 30 _for(i,0,m) 31 gd[i] = read(); 32 33 int hash[6]; 34 int rnt = 0; 35 _for(i,0,m) 36 { 37 memset(hash,0,sizeof(hash)); 38 _for(j,0,n) 39 hash[lst[j][i]-'A'] ++; 40 int tmax = 0; 41 _for(j,0,6) 42 tmax = max(tmax,hash[j]); 43 rnt += tmax*gd[i]; 44 } 45 write(rnt); 46 return 0; 47 }