#include using namespace std; int main() { int N, M; cin >> N >> M; vector V(N); for (int &v : V) cin >> v; vector S(N); for (int i = 0; i < N; i++) { string s; cin >> s; for (int j = 0; j < M; j++) S[i] += (s[j] == 'o') << j; } vector Z(1 << M); for (int i = 0; i < N; i++) Z[S[i]] += V[i]; for (int i = 0; i < M; i++) for (int j = 0; j < (1 << M); ++j) if (j & (1 << i)) Z[j] += Z[j - (1 << i)]; vector DP(1 << M); for (int i = 1; i < (1 << M); i++) { for (int j = 0; j < M; j++) if (i & (1 << j)) { long v = Z[i - (1 << j)] - Z[i]; DP[i] = max(DP[i], DP[i - (1 << j)] + v * v); } } cout << DP.back() << endl; }