func_code_string: #include <bits/stdc++.h>   using namespace std;   char a[1100], b[1100][1100];   const int inf = 2000000000;   int c[1100], len[1100], f[1100][1100], sum[1100], ran[2][1100], to[1100],       d[1100], n, m, fr[1100];   int cal(int i) {     int j, res = 0;     for (j = len[i]; j > m; j--) res += c[b[i][j] -  0 ];     return res;   }   void add(int i) {     if (len[i] <= m)       len[i] = m + 1, b[i][m + 1] =  1 ;     else {       int pos = m + 1;       b[i][pos]++;       while (b[i][pos] >  9 ) {         if (len[i] == pos)           len[i]++, b[i][len[i]] =  1 ;         else           b[i][pos + 1]++;         b[i][pos] =  0 ;         pos++;       }     }   }   int main() {     int i, j, k, nw, pre, l, r, co, p, q, ans;     scanf( %s , a + 1);     m = strlen(a + 1);     reverse(a + 1, a + m + 1);     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %s , b[i] + 1);       len[i] = strlen(b[i] + 1);       reverse(b[i] + 1, b[i] + len[i] + 1);       for (j = len[i] + 1; j <= m; j++) b[i][++len[i]] =  0 ;     }     for (i = 0; i <= 9; i++) scanf( %d , &c[i]);     for (i = 1; i <= n; i++) ran[0][i] = i;     nw = 0;     pre = 1;     for (i = 0; i <= m; i++)       for (j = 1; j <= n + 1; j++) f[i][j] = -inf;     f[0][n + 1] = 0;     for (i = 1; i <= m; i++) {       nw ^= 1;       pre ^= 1;       for (j = 0; j <= 9; j++) sum[j] = 0;       for (j = 1; j <= n; j++) sum[b[j][i] -  0 ]++;       for (j = 1; j <= 9; j++) sum[j] += sum[j - 1];       for (j = n; j; j--) {         ran[nw][sum[b[ran[pre][j]][i] -  0 ]] = ran[pre][j];         to[sum[b[ran[pre][j]][i] -  0 ]] = j;         fr[j] = sum[b[ran[pre][j]][i] -  0 ]--;       }       l = 0;       r = 9;       if (i == m) l = 1;       if (a[i] !=  ? ) l = a[i] -  0 , r = a[i] -  0 ;       for (j = l; j <= r; j++) {         co = 0;         for (k = 1; k <= n; k++) co += c[(b[k][i] -  0  + j) % 10];         for (k = n; ((k) && (b[ran[nw][k]][i] -  0  + j > 9)); k--)           ;         for (p = n + 1;              (((!k) || (p > to[k]) || (b[ran[nw][k]][i] -  0  + j < 9)) && (p));              p--) {           if (p != n + 1) {             co -= c[(b[ran[nw][fr[p]]][i] -  0  + j) % 10];             co += c[(b[ran[nw][fr[p]]][i] -  0  + j + 1) % 10];           }           f[i][k + 1] = max(f[i][k + 1], f[i - 1][p] + co);         }         for (; ((k) && (b[ran[nw][k]][i] -  0  + j == 9)); k--) {           if ((k == 1) || (b[ran[nw][k - 1]][i] -  0  + j != 9))             q = 1;           else             q = to[k - 1] + 1;           for (; p >= q; p--) {             co -= c[(b[ran[nw][fr[p]]][i] -  0  + j) % 10];             co += c[(b[ran[nw][fr[p]]][i] -  0  + j + 1) % 10];             f[i][k] = max(f[i][k], f[i - 1][p] + co);           }         }       }     }     for (i = 1; i <= n; i++) d[i] = ran[nw][i];     co = 0;     ans = 0;     for (i = 1; i <= n; i++) co += cal(i);     ans = max(ans, co + f[m][n + 1]);     for (i = n; i; i--) {       co -= cal(d[i]);       add(d[i]);       co += cal(d[i]);       ans = max(ans, co + f[m][i]);     }     printf( %d n , ans);     return 0;   }   