import sys from itertools import product def chmin(a, b): return b if a > b else a def main(): input = sys.stdin.read data = input().split() index = 0 N, M, K = map(int, data[index:index+3]) index += 3 A = list(map(int, data[index:index+N])) index += N linf = 4 * 10**18 dp = [[linf] * (1 << N) for _ in range(M + 1)] for i in range(1 << N): dp[0][i] = sum(A[j] for j in range(N) if not (i & (1 << j))) for p in range(M): B = int(data[index]) - 1 index += 1 for i in range(1 << N): c = i while c: now, temp = i, dp[p][i] temp += (bin(i).count('1') - bin(c).count('1')) * K now |= ((c << 1) & ((1 << N) - 1)) now |= (c >> 1) now &= ~(1 << B) dp[p + 1][now] = chmin(dp[p + 1][now], temp) c = (c - 1) & i now, temp = i, dp[p][i] temp += bin(i).count('1') * K now &= ~(1 << B) dp[p + 1][now] = chmin(dp[p + 1][now], temp) for i in range(M): print(dp[i + 1][0]) if __name__ == "__main__": main()