#include <bits/stdc++.h>
using namespace std;

template <class CapType = int>
struct Dinic {
    struct Edge {
        size_t to, rev;
        CapType cap, flow;
        Edge(size_t to, CapType cap, size_t rev) : 
            to(to), cap(cap), rev(rev), flow(0) {}
    };
    vector<vector<Edge>> g;
    vector<size_t> iter;
    vector<int> lev;
    size_t num_node;

    Dinic() = default;
    Dinic(size_t n) : num_node(n), g(n), lev(n, 0), iter(n, 0) {}

    void AddEdge(size_t u, size_t v, CapType cap) {
        g[u].emplace_back(v, cap, g[v].size() - 0);
        g[v].emplace_back(u, 0, g[u].size() - 1);
    }

    bool Bfs(size_t src, size_t snk) {
        fill(lev.begin(), lev.end(), -1);
        lev[src] = 0;
        vector<size_t> que(1, src);
        for (size_t it = 0; it < que.size(); ++it) {
            size_t x = que[it];
            for (const Edge &e : g[x]) {
                if (e.cap == 0) continue;
                if (lev[e.to] == -1) {
                    lev[e.to] = lev[x] + 1;
                    que.push_back(e.to);
                }
            }
        }
        return lev[snk] != -1;
    }

    CapType Flow(size_t x, size_t snk, CapType flow) {
        if (x == snk) return flow;
        CapType res = 0;
        for (size_t &it = iter[x]; it < g[x].size(); it++) {
            Edge &e = g[x][it];
            if (e.cap == 0) continue;
            if (lev[e.to] != lev[x] + 1) continue;
            CapType f = Flow(e.to, snk, min(e.cap, flow));
            res += f;
            flow -= f;
            e.cap -= f;
            e.flow += f;
            g[e.to][e.rev].cap += f;
            g[e.to][e.rev].flow -= f;
            if (!flow) break;
        }
        if (!res) lev[x] = -1;
        return res;
    }

    CapType operator()(size_t src, size_t snk) {
        constexpr CapType kInf = numeric_limits<CapType>::max();
        CapType res = 0;
        while (Bfs(src, snk)) {
            fill(iter.begin(), iter.end(), 0);
            res += Flow(src, snk, kInf);
        }
        return res;
    }

    CapType GetResidual(size_t from, size_t to) const {
        for (const Edge &e : g[from]) {
            if (e.to == to) return e.cap;
        }
        return -1;
    }

    CapType GetFlow(size_t from, size_t to) const {
        for (const Edge &e : g[from]) {
            if (e.to == to) return e.flow;
        }
        return -1;
    }
};


int main() {
    int n, m, a, b, c;
    cin >> n >> m >> a >> b >> c;
    vector<string> gr(n);
    for (int i = 0; i < n; ++i) cin >> gr[i];
    vector<vector<int>> bh(n, vector<int>(m));
    vector<vector<int>> bv(n, vector<int>(m));
    vector<vector<int>> wh(n, vector<int>(m));
    vector<vector<int>> wv(n, vector<int>(m));
    int nid = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            bh[i][j] = nid++;
            bv[i][j] = nid++;
            wh[i][j] = nid++;
            wv[i][j] = nid++;
        }
    }
    int src = nid++, snk = nid++;
    Dinic<int> flow(nid);
    constexpr int kInf = 1'000'000'000;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            flow.AddEdge(bh[i][j], snk, a);
            if (j + 1 < m) flow.AddEdge(bh[i][j], bh[i][j + 1], b);
            else flow.AddEdge(bh[i][j], snk, b);
            flow.AddEdge(src, bv[i][j], a);
            if (i + 1 < n) flow.AddEdge(bv[i + 1][j], bv[i][j], b);
            else flow.AddEdge(src, bv[i][j], b);
            flow.AddEdge(src, wh[i][j], a);
            if (j + 1 < m) flow.AddEdge(wh[i][j + 1], wh[i][j], b);
            else flow.AddEdge(src, wh[i][j], b);
            flow.AddEdge(wv[i][j], snk, a);
            if (i + 1 < n) flow.AddEdge(wv[i][j], wv[i + 1][j], b);
            else flow.AddEdge(wv[i][j], snk, b);
            if (gr[i][j] == '#') {
                flow.AddEdge(bv[i][j], bh[i][j], c);
                flow.AddEdge(src, wh[i][j], kInf);
                flow.AddEdge(wv[i][j], snk, kInf);
            } else {
                flow.AddEdge(bh[i][j], bv[i][j], kInf);
                flow.AddEdge(bh[i][j], wv[i][j], c);
                flow.AddEdge(wh[i][j], bv[i][j], c);
            }
        }
    }
    printf("%d\n", flow(src, snk));
}



Measured memory_bytes: 4712