func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 0xffffff;   int LEN;   class Mcmf {    public:     struct T {       int from, to, val;       int next, cost;     } edge[200001];     int len;     int visit[200001], pre[200001], dist[200001], que[200001], vis[200001],         pos[200001];     void init() {       memset(vis, -1, sizeof(vis));       len = 0;     }     void add(int from, int to, int val, int cost) {       edge[len].from = from, edge[len].to = to, edge[len].val = val,       edge[len].cost = cost;       edge[len].next = vis[from], vis[from] = len++;       edge[len].from = to, edge[len].to = from, edge[len].val = 0,       edge[len].cost = -cost;       edge[len].next = vis[to], vis[to] = len++;     }     int SPFA(int s, int t, int n) {       int i, to, k;       for (i = 0; i <= n; i++) {         pre[i] = -1, visit[i] = 0;       }       int head, tail;       head = tail = 0;       for (i = 0; i <= n; i++) dist[i] = inf;       que[tail++] = s, pre[s] = s, dist[s] = 0, visit[s] = 1;       while (head != tail) {         int from = que[head++];         visit[from] = 0;         for (k = vis[from]; k != -1; k = edge[k].next) {           to = edge[k].to;           if (edge[k].val > 0 && dist[from] + edge[k].cost < dist[to]) {             dist[to] = dist[from] + edge[k].cost;             pre[to] = from;             pos[to] = k;             if (!visit[to]) {               visit[to] = 1;               que[tail++] = to;             }           }         }       }       if (pre[t] != -1 && dist[t] < inf) return 1;       return 0;     }     int mnCostFlow(int s, int t, int n) {       if (s == t) {       }       int flow = 0, cost = 0;       while (SPFA(s, t, n)) {         int from, mn = inf;         for (from = t; from != s; from = pre[from])           mn = min(mn, edge[pos[from]].val);         flow += mn;         cost += dist[t] * mn;         for (from = t; from != s; from = pre[from]) {           edge[pos[from]].val -= mn;           edge[pos[from] ^ 1].val += mn;         }       }       if (flow != LEN) return -1;       return cost;     }   };   int n, q;   char s[10010];   int cnt[27];   int tmp[27];   Mcmf mcf;   int main() {     mcf.init();     scanf( %s , s);     LEN = strlen(s);     for (int i = 0; i < LEN; ++i) {       cnt[s[i] -  a ]++;     }     int len;     scanf( %d , &q);     int st = q + 26, en = st + 1, num;     for (int i = 0; i < q; ++i) {       scanf( %s , s);       len = strlen(s);       memset(tmp, 0, sizeof(tmp));       for (int k = 0; k < len; ++k) ++tmp[s[k] -  a ];       for (int k = 0; k < 26; ++k) mcf.add(i, q + k, tmp[k], 0);       scanf( %d , &num);       mcf.add(st, i, num, i + 1);     }     for (int i = 0; i < 26; ++i) mcf.add(q + i, en, cnt[i], 0);     int ans = mcf.mnCostFlow(st, en, en + 1);     printf( %d n , ans);   }   