func_code_string: #include <bits/stdc++.h>   using namespace std;   struct Edge {     int from, to;     long long capacity, cost;     Edge(int from, int to, long long capacity, long long cost) {       this->from = from;       this->to = to;       this->capacity = capacity;       this->cost = cost;     }   };   vector<vector<int>> adj;   vector<vector<long long>> cost, capacity;   const long long INF = 1e9;   void shortest_paths(int n, int v0, vector<long long>& d, vector<int>& p) {     d.assign(n, INF);     d[v0] = 0;     vector<int> m(n, 2);     deque<int> q;     q.push_back(v0);     p.assign(n, -1);     while (!q.empty()) {       int u = q.front();       q.pop_front();       m[u] = 0;       for (int v : adj[u]) {         if (capacity[u][v] > 0 && d[v] > d[u] + cost[u][v]) {           d[v] = d[u] + cost[u][v];           p[v] = u;           if (m[v] == 2) {             m[v] = 1;             q.push_back(v);           } else if (m[v] == 0) {             m[v] = 1;             q.push_front(v);           }         }       }     }   }   long long min_cost_flow(int N, vector<Edge> edges, long long K, int s, int t) {     adj.assign(N, vector<int>());     cost.assign(N, vector<long long>(N, 0));     capacity.assign(N, vector<long long>(N, 0));     for (Edge e : edges) {       adj[e.from].push_back(e.to);       adj[e.to].push_back(e.from);       cost[e.from][e.to] = e.cost;       cost[e.to][e.from] = -e.cost;       capacity[e.from][e.to] = e.capacity;     }     long long flow = 0;     long long cost = 0;     vector<int> p;     vector<long long> d;     while (flow < K) {       shortest_paths(N, s, d, p);       if (d[t] == INF) break;       long long f = K - flow;       int cur = t;       while (cur != s) {         f = min(f, capacity[p[cur]][cur]);         cur = p[cur];       }       flow += f;       cost += f * d[t];       cur = t;       while (cur != s) {         capacity[p[cur]][cur] -= f;         capacity[cur][p[cur]] += f;         cur = p[cur];       }     }     if (flow < K)       return -1;     else       return cost;   }   string s, x[105];   int y, val[256], n, temp[256];   vector<Edge> v;   int main() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       val[s[i] -  a ]++;     }     scanf( %d , &n);     for (int i = 0; i < 26; i++) {       v.push_back(Edge(n + 1 + i, n + 1 + 26, val[i], 0));     }     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y;       v.push_back(Edge(0, i, y, i));       for (int j = 0; j < x[i].size(); j++) {         temp[x[i][j] -  a ]++;       }       for (int j = 0; j < 26; j++) {         v.push_back(Edge(i, n + 1 + j, temp[j], 0));         temp[j] = 0;       }     }     printf( %lld n , min_cost_flow(n + 26 + 2, v, s.size(), 0, n + 26 + 1));   }   