#include<bits/stdc++.h>
using namespace std;
int n, m, a[100], k, num[100];
long long ans;
bool vis[100] = {0};
int check() {
long long sum = 0;
for(int i = 1; i <= n; i ++) {
for(int j = i; j <= n; j ++) {
if(min(j - i, i + n - j) == k) {
sum += a[num[i]] * a[num[j]];
}
}
}
ans = max(ans, sum);
return 0;
}
int dfs(int x) {
if(x == n + 1) {
check();
return 0;
}
for(int i = 1; i <= n; i ++) {
if(vis[i] == 0) {
vis[i] = 1;
num[x] = i;
dfs(x + 1);
vis[i] = 0;
}
}
}
int main() {
freopen("noi_online2020_ring.in", "r", stdin);
freopen("noi_online2020_ring.out", "w", stdout);
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
for(int i = 1; i <= m; i ++) {
cin >> k;
ans = 0;
dfs(1);
cout << ans << endl;
}
return 0;
}