malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int p[n];     for (int i = 0; i < n; i++) cin >> p[i];     sort(p, p + n);     map<string, int> mm;     string x;     for (int i = 0; i < m; ++i) {       cin >> x;       if (mm.find(x) == mm.end())         mm.insert(make_pair(x, 1));       else         mm[x]++;     }     vector<int> v;     for (auto i = mm.begin(); i != mm.end(); i++) {       v.push_back(i->second);     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long int sum = 0;     for (int i = 0; i < v.size(); i++) {       sum += v[i] * p[i];     }     cout << sum <<    ;     sum = 0;     for (int i = 0; i < v.size(); i++) {       sum += v[i] * p[n - 1 - i];     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   vector<vector<int> > adj(maxn), adj2(maxn);   vector<pair<int, int> > vs;   bool vis[maxn];   void dfs(int pv, int v) {     vis[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (vis[u]) continue;       vs.push_back(make_pair(v, u));       adj2[pv].push_back(vs.size() - 1);       dfs(vs.size() - 1, u);     }   }   int main() {     int n, a, b;     cin >> n;     for (int i = 1; i <= n - 1; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     memset(vis, 0, maxn);     vs.push_back(make_pair(-1, -1));     int s;     for (int i = 1; i <= n; i++)       if (adj[i].size() == 1) {         s = i;         break;       }     vis[s] = 1;     for (int i = 0; i < adj[s].size(); i++) {       int u = adj[s][i];       vs.push_back(make_pair(s, u));       dfs(vs.size() - 1, u);     }     cout << n - 1 << endl;     for (int i = 1; i <= n - 1; i++) {       cout <<  2   << vs[i].first <<     << vs[i].second << endl;     }     for (int i = 1; i <= n - 1; i++) {       for (int j = 0; j < adj2[i].size(); j++)         cout << i <<     << adj2[i][j] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long z[3000019], arr[3000019], pre[3000019];   void fnc(string s) {     memset(z, 0, sizeof(z));     long long l = 0, r = 0;     long long n = s.size();     for (long long i = 1; i <= n; i++) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] <= n && s[z[i]] == s[i + z[i]]) z[i]++;       if (i + z[i] - 1 > r) {         l = i;         r = i + z[i] - 1;       }     }     z[0] = n;     return;   }   signed main() {     std::ios::sync_with_stdio(false);     long long n, m, q, i, l, r;     string s, t, str;     cin >> n >> m >> q;     cin >> s >> t;     str = t +  $  + s;     fnc(str);     for (i = m + 1; i <= n + m; i++) arr[i - m] = (z[i] == m);     for (i = 1; i <= n; i++) pre[i] = arr[i] + pre[i - 1];     while (q--) {       cin >> l >> r;       if (r - l + 1 < m) {         cout << 0 << endl;         continue;       }       cout << pre[r - m + 1] - pre[l - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tc, cs = 1, n, k, a, b, c, d;     while (cin >> n >> k) {       cin >> a >> b >> c >> d;       if (k < n + 1 || n == 4) {         printf( %d n , -1);       } else {         printf( %d %d  , a, c);         for (int i = 1; i < n + 1; i++) {           if (i != a && i != b && i != c && i != d) {             printf( %d  , i);           }         }         printf( %d %d n , d, b);         printf( %d %d  , c, a);         for (int i = 1; i < n + 1; i++) {           if (i != a && i != b && i != c && i != d) {             printf( %d  , i);           }         }         printf( %d %d n , b, d);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void File() {     freopen( output.txt ,  w , stdout);     freopen( input.txt ,  r , stdin);   }   void fast() {     ios::sync_with_stdio(NULL);     cout.tie(NULL);     cin.tie(NULL);   }   const double pi = 2 * acos(0.0);   const int nn = 5e2 + 5;   const int oo = 0x3f3f3f3f;   int main() {     fast();     int n, ans = 0;     pair<int, int> arr[nn];     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;     for (int i = 0; i < n; i++) {       int cnt[4] = {};       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (arr[i].first > arr[j].first && arr[i].second == arr[j].second)           cnt[0]++;         else if (arr[i].first < arr[j].first && arr[i].second == arr[j].second)           cnt[1]++;         else if (arr[i].first == arr[j].first && arr[i].second > arr[j].second)           cnt[2]++;         else if (arr[i].first == arr[j].first && arr[i].second < arr[j].second)           cnt[3]++;         if (cnt[0] && cnt[1] && cnt[2] && cnt[3]) {           ans++;           break;         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>       using namespace std;   using ll=long long;   using pii=pair<int,int>;      int np[17][200000];   int pre[(1<<17)+1];      int main() {    int n,k;    cin >> n >> k;       string s;       cin >> s;    int l=0,r=n/k;       while (l<r) {           int m=(l+r+1)/2;           for (int j=0;j<k;j++) {               int cnt=0, nextpos=n+1;               for (int i=n-1;i>=0;i--) {                   if (s[i]== ?  || s[i]== a +j) cnt++;                   else cnt=0;                   if (cnt>=m) nextpos=i;                   np[j][i]=nextpos;               }           }           /*cerr << m << endl;           for (int j=0;j<k;j++) {               cerr << (char)( a +j) <<  :  ;               for (int i=0;i<n;i++) cerr << np[j][i] <<    ;               cerr << endl;           }*/           pre[0]=0;           for (int i=1;i<(1<<k);i++) {               pre[i]=n+1;               /*for (int j=0;j<k;j++) if (i&(1<<j)) {                   cerr << (char)( a +j) <<  , ;               }               cerr <<   t  << i << endl;*/               for (int j=0;j<k;j++) if (i&(1<<j)) {                   int x=(i&(~(1<<j)));                   //cerr << (char)( a +j) <<    << x <<     << pre[x] <<     << np[j][pre[x]] << endl;                   if (pre[x]<n) pre[i]=min(pre[i],np[j][pre[x]]+m);                   //cerr << (char)( a +j) <<     << pre[i] << endl;               }           }           /*for (int i=0;i<(1<<k);i++) {               for (int j=0;j<k;j++) if (i&(1<<j)) {                   cerr << (char)( a +j) <<  , ;               }               cerr <<   t  << pre[i] << endl;           }*/           if (pre[(1<<k)-1]<=n) l=m;           else r=m-1;       }       printf( %d n ,l);       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   char ch[MAX];   int ans[MAX];   int main() {     int n;     scanf( %d%s , &n, ch);     ans[0] = 1;     for (int i = 1; i < n; i++) {       if (ch[i - 1] ==  = )         ans[i] = ans[i - 1];       else if (ch[i - 1] ==  L ) {         ans[i] = 1;         for (int j = i - 1; j >= 0; j--) {           if (ch[j] ==  L  && ans[j] <= ans[j + 1])             ans[j] = ans[j + 1] + 1;           else if (ch[j] ==  =  && ans[j] != ans[j + 1])             ans[j] = ans[j + 1];           else             break;         }       } else         ans[i] = ans[i - 1] + 1;     }     for (int i = 0; i < n; i++) {       if (i == 0)         printf( %d , ans[i]);       else         printf(  %d , ans[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   void printAll(int n, ...) {     if (1) {       va_list ap;       va_start(ap, n);       for (int i = 1; i <= n; i++) cout << va_arg(ap, long long int) <<    ;       cout << endl;       va_end(ap);     }   }   template <typename T>   string toString(T n) {     stringstream ss;     ss << n;     string s;     ss >> s;     return s;   }   void init() {     cout << fixed << setprecision(0);     ios_base::sync_with_stdio(false);     cin.tie(0);   }   bool isInteger(double n) {     if (n - (long long int)n == 0)       return true;     else       return false;   }   int main() {     init();     long long int i, j, k;     int n, w;     cin >> n >> w;     int x;     int low = 0;     int high = w;     int lowsum = 0;     int highsum = w;     for (int i = 0; i < n; i++) {       cin >> x;       if (lowsum + x < 0) {         low -= (lowsum + x);         lowsum = 0;       } else         lowsum += x;       if (highsum + x > w) {         high = high + (w - highsum - x);         highsum = w;       } else         highsum += x;     }     high < low ? cout << 0 << endl : cout << high - low + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[100000];   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     dp[a] = dp[b] = dp[c] = 1;     int x = min(a, min(b, c));     for (int i = x; i <= n; i++) {       if (i - a >= 0 && dp[i - a] > 0) dp[i] = max(dp[i], dp[i - a] + 1);       if (i - b >= 0 && dp[i - b] > 0) dp[i] = max(dp[i], dp[i - b] + 1);       if (i - c >= 0 && dp[i - c] > 0) dp[i] = max(dp[i], dp[i - c] + 1);     }     cout << dp[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int L[100007], R[100007];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , L + i, R + i);     }     sort(L + 1, L + n + 1);     sort(R + 1, R + n + 1);     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans += max(L[i], R[i]);     }     printf( %I64d n , ans + n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ball[100005];   int main() {     int n, m;     cin >> n >> m;     if (m % 2) {       int basket = m / 2;       while (n--) {         cout << basket + 1 <<   n ;         basket = m - basket - 1;         if (basket <= m / 2) basket--;         if (basket < 0) basket = m / 2;       }     } else {       int basket = m / 2 - 1;       while (n--) {         cout << basket + 1 <<   n ;         basket = m - basket - 1;         if (basket < m / 2) basket--;         if (basket < 0) basket = m / 2 - 1;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int N = 1000 + 10;   int n, l, k;   double dp[202][202][404];   double pro[300];   int a[N];   double solve(int i, int sofar, int cap) {     if (i == n + 1) {       return sofar >= l && cap >= 0;     }     double &ret = dp[i][sofar][cap + 200];     if (ret == ret) return ret;     int toref = min(200, cap + a[i]);     toref = max(toref, -200);     double c1 = solve(i + 1, sofar + 1, toref) * pro[i];     double c2 = solve(i + 1, sofar, cap) * (1 - pro[i]);     return ret = c1 + c2;   }   int main() {     cin >> n >> l >> k;     for (int i = 1; i <= n; ++i) {       cin >> pro[i];       pro[i] /= 100.0;     }     for (int i = 1; i <= n; ++i) cin >> a[i];     memset(dp, -1, sizeof(dp));     cout << fixed << setprecision(10) << solve(1, 0, k) << endl;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int N = 3030;   const int INF = (int)2e9;   int n, m;   int len[N];   int f[N][N];   vector<int> g[N];   vector<int> gr[N];   vector<pair<int, int> > have[N];   vector<pair<int, int> > gave[N];   queue<int> q;   void bfs(int v) {     for (int i = 1; i <= n; i++) len[i] = INF;     len[v] = 0;     q.push(v);     while (!q.empty()) {       int ver = q.front();       q.pop();       for (int i = 0; i < (int)g[ver].size(); i++) {         int to = g[ver][i];         if (len[to] > len[ver] + 1) {           len[to] = len[ver] + 1;           q.push(to);         }       }     }     for (int i = 1; i <= n; i++) {       f[v][i] = len[i];       if (len[i] != INF && i != v) {         gave[i].push_back(make_pair(len[i], v));       }     }     for (int i = 1; i <= n; i++) len[i] = INF;     len[v] = 0;     q.push(v);     while (!q.empty()) {       int ver = q.front();       q.pop();       for (int i = 0; i < (int)gr[ver].size(); i++) {         int to = gr[ver][i];         if (len[to] > len[ver] + 1) {           len[to] = len[ver] + 1;           q.push(to);         }       }     }     for (int i = 1; i <= n; i++) {       if (len[i] != INF && i != v) {         have[i].push_back(make_pair(len[i], v));       }     }   }   int main() {     scanf( %d%d , &n, &m);     int u, v;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       gr[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       bfs(i);     }     for (int i = 1; i <= n; i++) {       sort(have[i].begin(), have[i].end());       reverse(have[i].begin(), have[i].end());       sort(gave[i].begin(), gave[i].end());       reverse(gave[i].begin(), gave[i].end());     }     int res = 0;     int a, b, c, d, sz, ptr, cost;     for (int i = 1; i <= n; i++) {       sz = min(3, (int)gave[i].size());       for (int idx = 0; idx < sz; idx++) {         for (int j = 1; j <= n; j++) {           if (j == i) continue;           if (f[i][j] == INF) continue;           ptr = 0;           while (true) {             if (ptr >= (int)have[j].size()) break;             if (have[j][ptr].second == i ||                 have[j][ptr].second == gave[i][idx].second ||                 j == gave[i][idx].second) {               ++ptr;               continue;             } else {               cost = gave[i][idx].first + f[i][j] + have[j][ptr].first;               if (cost > res) {                 res = cost;                 a = gave[i][idx].second;                 b = i;                 c = j;                 d = have[j][ptr].second;               }               break;             }           }         }       }     }     printf( %d %d %d %d n , a, b, c, d);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[100009];   map<double, bool> mb;   int main() {     long long n, k, i, j, l, cnt = 0;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> v[i];     }     sort(v, v + n);     for (i = 0; i < n; i++) {       double val = (double)(v[i] / (double)k);       if (!mb[val]) {         cnt++;         mb[v[i]] = true;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const siz = 1e9, bound = 7e5, mod = siz + 9;   long long const oo = 1e18;   int aa[bound];   int main() {     int n, k;     scanf( %d , &n), scanf( %d , &k);     for (int(i) = 0; (i) < (n); (i)++) scanf( %d , &aa[i]);     int l = 0, r = n, mid, rob;     while (l <= r) {       mid = (l + r) >> 1;       if ((long long)mid * (mid + 1) / 2 >= k) {         rob = mid;         r = mid - 1;       } else         l = mid + 1;     }     long long cur = (long long)(rob - 1) * rob / 2 + 1;     int idn = 0;     while (cur < k) {       cur++;       idn++;     }     printf( %d n , aa[idn]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MOD = 1e9 + 7;   long long INF = 1e18;   int n, q, a[200005];   int d[200005] = {};   int solve() {     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     while (q--) {       int l, r;       cin >> l >> r, l--, r--;       d[l]++;       d[r + 1]--;     }     for (int i = 1; i < n; i++) d[i] += d[i - 1];     sort(a, a + n);     sort(d, d + n);     long long sum = 0;     for (int i = 0; i < n; i++) sum += 1LL * a[i] * d[i];     cout << sum << endl;     return 0;   }   int main() {     ios::sync_with_stdio(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 1e3 + 10;   long long dis[N][N][4];   int dx[] = {0, 0, -1, 1};   int dy[] = {1, -1, 0, 0};   char c[N][N];   queue<pair<int, int>> q[4];   int n, m;   long long check(int o) {     long long d[4] = {0, INF * INF, INF * INF, INF * INF};     while (!q[o].empty()) {       int x, y;       tie(x, y) = q[o].front();       q[o].pop();       if (isdigit(c[x][y])) {         long long &oo = d[c[x][y] -  0 ];         oo = min(oo, dis[x][y][o]);       }       for (int i = 0; i < 4; i++) {         int tx = x + dx[i];         int ty = y + dy[i];         if (tx < 0 || tx >= n) continue;         if (ty < 0 || ty >= m) continue;         if (c[tx][ty] ==  # ) continue;         if (dis[tx][ty][o] > dis[x][y][o] + 1) {           dis[tx][ty][o] = dis[x][y][o] + 1;           q[o].push({tx, ty});         }       }     }     return min(INF, d[1] + d[2] + d[3] - 2);   }   int main() {     cin >> n >> m;     memset((dis), (0x1f), sizeof(dis));     for (int i = 0; i < n; i++) {       cin >> c[i];       for (int j = 0; j < m; j++) {         if (isdigit(c[i][j])) {           q[c[i][j] -  0 ].push({i, j});           dis[i][j][c[i][j] -  0 ] = 0;         }       }     }     long long ans = min(check(1), min(check(2), check(3)));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (c[i][j] !=  . ) continue;         ans = min(ans, dis[i][j][1] + dis[i][j][2] + dis[i][j][3] - 2);       }     }     if (ans >= INF) ans = -1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline int read() {     int ret = 0, t = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) t = -1, c = getchar();     while (c >=  0  && c <=  9 ) ret = ret * 10 + c -  0 , c = getchar();     return ret * t;   }   const int MAXN = 262145;   int n, a[MAXN], fa[MAXN];   int v[MAXN];   int gf(int x) {     if (fa[x] == x) return x;     return fa[x] = gf(fa[x]);   }   int main() {     n = read();     int i, j;     ++v[0];     long long ans = 0;     for (i = 1; i <= n; i++) a[i] = read(), ++v[a[i]], ans -= a[i];     for (i = 0; i <= 262144; i++) fa[i] = i;     for (i = 262144; i >= 1; i--) {       for (j = i; 1; j = i & (j - 1)) {         int x = j, y = i ^ j;         if (v[x] && v[y] && gf(x) != gf(y))           fa[gf(x)] = gf(y), ans += 1ll * i * (v[x] + v[y] - 1), v[x] = v[y] = 1;         if (!j) break;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, arr[1005], ro[1005], co[1005];   char s[2000000];   int main() {     int a, b;     cin >> s + 1;     a = count(s + 1, s + strlen(s + 1) + 1,  x );     b = count(s + 1, s + strlen(s + 1) + 1,  y );     for (int i = 1; i <= a - b; i++) cout <<  x ;     for (int i = 1; i <= b - a; i++) cout <<  y ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10;   long long n, m, nn, cnt, tot, k, k_, x, y, ww, rt, ans;   long long to[N], nextn[N], h[N];   long long mxsize[N], size[N];   long long w[N];   struct dis {     long long d, d_;     bool operator<(const dis &x) const { return x.d > d; }   } tmp[N], q[N], q0[N];   long long t[N];   bool b[N];   long long lowbit(long long x) { return x & (-x); }   void update(long long x, long long v) {     for (long long i = x; i <= n; i += lowbit(i)) t[i] += v;   }   long long inquiry(long long x) {     long long res = 0;     for (long long i = x; i; i -= lowbit(i)) res += t[i];     return res;   }   void add(long long x, long long y, long long ww) {     cnt++;     to[cnt] = y;     nextn[cnt] = h[x];     h[x] = cnt;     w[cnt] = ww;   }   void findrt(long long x, long long anc) {     mxsize[x] = 0;     size[x] = 1;     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (y == anc || b[y]) continue;       findrt(y, x);       size[x] += size[y];       mxsize[x] = max(mxsize[x], size[y]);     }     mxsize[x] = max(mxsize[x], nn - size[x]);     if (mxsize[x] < mxsize[rt]) rt = x;   }   void dfs(long long x, long long anc, long long dis1, long long dis_) {     tmp[++tot] = (dis){dis1, dis_};     if (dis1 <= k && dis_ <= k_) ans++;     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (y == anc || b[y]) continue;       dfs(y, x, dis1 + w[i], dis_ + 1);     }   }   void work(long long x) {     cnt = 0;     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (b[y]) continue;       tot = 0;       dfs(y, x, w[i], 1);       sort(tmp + 1, tmp + tot + 1);       long long last = 0;       for (long long j = tot; j >= 1; j--)         if (tmp[j].d < k && tmp[j].d_ < k_) {           long long pos =               lower_bound(q + 1, q + cnt + 1, dis{k - tmp[j].d + 1, 0}) - q;           while (q[pos].d > k - tmp[j].d) pos--;           for (long long l = last + 1; l <= pos && l <= cnt; l++)             update(q[l].d_, 1);           ans += inquiry(k_ - tmp[j].d_);           last = pos;         }       for (long long l = 1; l <= last && l <= cnt; l++) update(q[l].d_, -1);       merge(tmp + 1, tmp + tot + 1, q + 1, q + cnt + 1, q0 + 1);       cnt += tot;       for (long long i = 1; i <= cnt; i++) q[i] = q0[i];     }   }   void solve(long long x) {     b[x] = 1;     work(x);     for (long long i = h[x]; i; i = nextn[i]) {       long long y = to[i];       if (b[y]) continue;       rt = 0, mxsize[0] = n;       nn = size[y];       findrt(y, x);       solve(rt);     }   }   signed main() {     scanf( %lld%lld%lld , &n, &k_, &k);     for (long long i = 1; i < n; i++) {       scanf( %lld%lld , &y, &ww);       add(i + 1, y, ww), add(y, i + 1, ww);     }     rt = 0, nn = n;     mxsize[0] = n;     findrt(1, 0);     solve(rt);     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, d[1001], y[100001], dp[1001][1001];   int main() {     scanf( %lld%lld , &a, &b);     for (int i = 1; i <= a; i++) {       scanf( %lld , &d[i]);     }     sort(d + 1, d + a + 1);     long long pp = 1;     for (int i = d[1]; i <= 100000; i++) {       while (pp < a && i >= d[pp + 1]) {         pp++;       }       y[i] = pp;     }     long long ans = 0;     for (int i = 0; i <= a; i++) {       dp[i][0] = 1;     }     for (int ii = 1; ii * (b - 1) <= d[a]; ii++) {       for (int i = 1; i <= a; i++) {         for (int j = 1; j <= b; j++) {           dp[i][j] = dp[i - 1][j] + dp[d[i] - ii >= 0 ? y[d[i] - ii] : 0][j - 1];           dp[i][j] %= 998244353;         }       }       ans += dp[a][b];       ans %= 998244353;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int n, m, x, cnt[N], ne[N][10], g[15], f[15], dp[N][N][15], sd[N], tot;   char s[N];   void dfs(int x) {     for (int i = 0; i < 10; i++)       if (ne[x][i]) dfs(ne[x][i]);     for (int i = 0; i <= sd[x]; i++) {       memset(f, 0, sizeof f);       for (int j = 0; j < 10; j++)         if (ne[x][j]) {           memset(g, 0x3f, sizeof g);           int to = ne[x][j];           for (int x = 0; x <= m; x++)             for (int y = 0; y <= m - x; y++)               g[x + y] = min(g[x + y], f[x] + dp[to][i][y]);           for (int x = 0; x <= m; x++) f[x] = g[x];         }       if (i != sd[x]) {         for (int j = 0; j <= m; j++) dp[x][i][j] = f[j] + cnt[x] * (sd[x] - i);       } else {         if (i == 0)           printf( %d n , f[m]);         else           for (int j = 0; j < sd[x]; j++)             for (int k = 0; k < m; k++)               dp[x][j][k + 1] = min(dp[x][j][k + 1], f[k]);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s%d , s + 1, &x);       int p = 0;       for (int j = 1; s[j]; j++) {         int t = s[j] -  0 ;         if (!ne[p][t]) ne[p][t] = ++tot, sd[tot] = j;         p = ne[p][t];       }       cnt[p] += x;     }     dfs(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int ans = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  -  && ans > 0) ans--;       if (s[i] ==  + ) ans++;     }     cout << ans << endl;   }