#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f *= -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = getchar();     }     return x * f;   }   int n = read(), w[5], dp[1005][630], s[15],       c[15] = {0, 125, 25, 5, 1, 300, 60, 12, 465, 93, 624};   bool p[6][1005];   int main() {     for (int i = 1; i < 5; i++) w[i] = read();     char ss = getchar();     for (int i = 1; i < 5; i++)       for (int j = 1; j <= n; j++) {         while (ss !=  .  && ss !=  * ) ss = getchar();         p[i][j] = (ss ==  * );         ss = getchar();       }     memset(dp, 0x3f3f3f3f, sizeof(dp));     dp[1][0] = 0;     int b[5] = {0, 125, 25, 5, 1};     for (int i = 1; i < 11; i++) {       if (i < 5)         s[i] = w[1];       else if (i > 4 && i < 8)         s[i] = w[2];       else if (i > 7 && i < 10)         s[i] = w[3];       else         s[i] = w[4];     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 625; j++) {         int a[5] = {0, j / 125, j / 25 % 5, j / 5 % 5, j % 5};         if (max(max(a[1], a[2]), max(a[3], a[4])) > n - i + 1) continue;         for (int o = 1; o < 5; o++)           if (a[o] > 0 && !p[o][i + a[o] - 1])             dp[i][j] = min(dp[i][j], dp[i][j - b[o]]);         if (min(min(a[1], a[2]), min(a[3], a[4])) > 0)           dp[i + 1][j - 156] = min(dp[i + 1][j - 156], dp[i][j]);         for (int k = 1; k < 11; k++) {           int b[5] = {0, c[k] / 125, c[k] / 25 % 5, c[k] / 5 % 5, c[k] % 5},               l = 0;           for (int o = 1; o < 5; o++) l = l * 5 + max(a[o], b[o]);           dp[i][l] = min(dp[i][l], dp[i][j] + s[k]);         }       }     }     printf( %d n , dp[n + 1][0]);     return 0;   }   