malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void add(int& a, int b) {     a += b;     a = min(a, 100000000);   }   const int MX = 300005;   int root[MX];   bool is_left[MX];   vector<int> nodes[MX];   int left_size[MX], right_size[MX];   int ans = 0;   char s[MX];   vector<int> comps[MX];   int main() {     int n, k;     ignore = scanf( %d %d , &n, &k);     ignore = scanf(  %s , s + 1);     for (int i = 1; i <= k; i++) {       int c;       ignore = scanf(  %d , &c);       while (c--) {         int x;         ignore = scanf( %d , &x);         comps[x].push_back(i);       }     }     for (int i = 1; i <= k; i++) {       root[i] = i;       is_left[i] = false;       nodes[i].push_back(i);       right_size[i] = 1;     }     for (int i = 1; i <= n; i++) {       if (comps[i].size() == 1) {         int x = comps[i][0];         ans -= min(left_size[root[x]], right_size[root[x]]);         if (s[i] ==  0 ) {           if (is_left[x]) {             add(right_size[root[x]], MX);           } else {             add(left_size[root[x]], MX);           }         } else {           if (is_left[x]) {             add(left_size[root[x]], MX);           } else {             add(right_size[root[x]], MX);           }         }         ans += min(left_size[root[x]], right_size[root[x]]);       } else if (comps[i].size() == 2) {         int x = comps[i][0], y = comps[i][1];         if (root[x] != root[y]) {           ans -= min(left_size[root[x]], right_size[root[x]]);           ans -= min(left_size[root[y]], right_size[root[y]]);           if (nodes[root[x]].size() > nodes[root[y]].size()) {             swap(x, y);           }           if ((is_left[x] == is_left[y]) != (s[i] ==  1 )) {             for (int v : nodes[root[x]]) is_left[v] = !is_left[v];             swap(left_size[root[x]], right_size[root[x]]);           }           add(left_size[root[y]], left_size[root[x]]);           add(right_size[root[y]], right_size[root[x]]);           for (int v : nodes[root[x]]) {             nodes[root[y]].push_back(v);             root[v] = root[y];           }           ans += min(left_size[root[x]], right_size[root[x]]);         }       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   template <typename T>   T sqr(T x) {     return x * x;   }   double sind(double x) { return sin(x * PI / 180); }   double cosd(double x) { return cos(x * PI / 180); }   double tand(double x) { return tan(x * PI / 180); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int r, c, i, j, x = 0, y = 0;     cin >> r >> c;     vector<string> v;     bool mark[c + 1];     memset(mark, 0, sizeof(mark));     for (i = 0; i < r; i++) {       string s;       cin >> s;       v.push_back(s);     }     for (auto i : v) {       string s;       bool f = 1;       s = i;       for (j = 0; j < c; j++) {         if (s[j] ==  S ) {           f = 0;           mark[j] = 1;         }       }       if (f) x++;     }     for (i = 0; i < c; i++) {       if (mark[i] == 0) y++;     }     int ans = 0;     ans += x * c;     ans += y * (r - x);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Graph {     long long int v;     list<pair<long long int, long long int>> *adj;       public:     Graph(long long int v) : v(v) {       adj = new list<pair<long long int, long long int>>[v];     }     void addEdge(long long int u, long long int v, long long int w,                  bool bidir = true) {       adj[u].push_back(make_pair(v, w));       if (bidir) adj[v].push_back(make_pair(u, w));     }     void dijkstra() {       vector<long long int> distance(v, LONG_MAX);       priority_queue<pair<long long int, long long int>,                      vector<pair<long long int, long long int>>,                      greater<pair<long long int, long long int>>>           pq;       pq.push(make_pair(0, 0));       distance[0] = 0;       while (!pq.empty()) {         auto ele = pq.top();         pq.pop();         for (auto itr = adj[ele.second].begin(); itr != adj[ele.second].end();              itr++) {           long long int v = itr->first;           long long int weight = itr->second;           if (distance[ele.second] != LONG_MAX &&               distance[ele.second] + weight < distance[v]) {             distance[v] = distance[ele.second] + weight;             pq.push(make_pair(distance[v], v));           }         }       }       for (auto ele : distance) cout << ele <<    ;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long int n;     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     Graph g(n);     for (long long int i = 0; i < n - 1; i++) g.addEdge(i, i + 1, 1);     for (long long int i = 0; i < n; i++)       if (i != v[i] - 1) g.addEdge(i, v[i] - 1, 1, false);     g.dijkstra();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using Long = int64_t;   constexpr Long Z = 0;   bool fire(Long N, Long M, int K, const vector<Long>& X, const vector<Long>& Y,             Long t) {     map<Long, int> xs;     map<Long, int> ys;     xs[0] = 0;     xs[N] = 0;     ys[0] = 0;     ys[M] = 0;     for (int i = 0; i < K; ++i) {       Long x = X[i];       Long y = Y[i];       xs[max(x - t, Z)] = 0;       xs[min(x + 1 + t, N)] = 0;       ys[max(y - t, Z)] = 0;       ys[min(y + 1 + t, M)] = 0;     }     int i = 0;     for (auto& p : xs) {       p.second = i++;     }     i = 0;     for (auto& p : ys) {       p.second = i++;     }     int nx = (int)xs.size();     int ny = (int)ys.size();     vector<vector<bool>> mat(ny + 1, vector<bool>(nx + 1));     for (int i = 0; i < K; ++i) {       Long x = X[i];       Long y = Y[i];       int bx = xs[max(x - t, Z)];       int ex = xs[min(x + 1 + t, N)];       int by = ys[max(y - t, Z)];       int ey = ys[min(y + 1 + t, M)];       for (int y = by; y < ey; ++y)         for (int x = bx; x < ex; ++x) mat[y][x] = 1;     }     int bx = -1;     int ex = -1;     int by = -1;     int ey = -1;     for (int y = 0; y < ny - 1; ++y) {       for (int x = 0; x < nx - 1; ++x) {         if (mat[y][x]) continue;         if (bx == -1) {           bx = x;           ex = x + 1;           by = y;           ey = y + 1;         } else {           bx = min(bx, x);           ex = max(ex, x + 1);           by = min(by, y);           ey = max(ey, y + 1);         }       }     }     if (bx == -1) return true;     Long bxx = 0, exx = N, byy = 0, eyy = M;     for (const auto& p : xs) {       if (p.second == bx) bxx = p.first;       if (p.second == ex) exx = p.first;     }     for (const auto& p : ys) {       if (p.second == by) byy = p.first;       if (p.second == ey) eyy = p.first;     }     if (exx - bxx > 2 * t + 1 || eyy - byy > 2 * t + 1) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long N, M;     int K;     cin >> N >> M >> K;     vector<Long> X(K), Y(K);     for (int i = 0; i < K; ++i) {       cin >> X[i] >> Y[i];       --X[i];       --Y[i];     }     Long lb = -1;     Long ub = max(N, M);     while (ub - lb >= 2) {       Long mid = (ub + lb) / 2;       if (fire(N, M, K, X, Y, mid)) {         ub = mid;       } else {         lb = mid;       }     }     cout << ub <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long INF = 2e18;   constexpr long long MOD = 1e9 + 7;   constexpr long long MAXN = 2e5 + 3;   void solve() {     long long n;     cin >> n;     long long k;     cin >> k;     vector<long long> arr(n);     for (long long i = 0; i < n; ++i) {       long long &x = arr[i];       cin >> x;     }     vector<long long> ans(n);     set<long long> s;     set<long long> c;     for (long long i = 0; i < 256; ++i) s.emplace(i);     long long last = -INF;     long long maxx = -1;     for (long long i = 0; i < n; ++i) {       pair<long long, long long> x = pair<long long, long long>(arr[i], i);       long long v = -1;       for (long long j = arr[i]; j >= max(0ll, arr[i] - k + 1); --j) {         if (s.count(j)) {           v = j;         }         if (c.count(j)) {           v = j;           break;         }       }       for (long long i = v; i <= x.first; ++i) {         if (s.count(i)) s.erase(i);       }       c.emplace(v);       ans[i] = v;     }     for (long long x : ans) {       cout << x <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100010], s[100010], sp, cnt;   long long tot, sum, pj;   int main() {     cin >> n >> m;     for (register int i = 1; i <= n; i++) cin >> a[i], tot += a[i];     if (tot % m != 0) {       cout <<  No  << endl;       return 0;     }     pj = tot / m;     for (register int i = 1; i <= n; i++) {       sum += a[i];       if (sum == pj) {         sum = 0;         s[++cnt] = i - sp;         sp = i;       }       if (sum > pj) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     for (register int i = 1; i <= cnt; i++) cout << s[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int fre[26] = {0};     for (int i = 0; i < n; i++) {       fre[s[i] -  a ] = fre[s[i] -  a ] + 1;     }     string ans =   ;     for (int i = 0; i < 26; i++) {       for (int j = 0; j < fre[i]; j++) {         ans = ans + char(97 + i);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   struct arc {     int f, s, prev;   } arr[300000];   int q[100005];   int beg[100005];   int kol = 0;   void add_arc(int f, int s) {     f--;     s--;     arr[kol].f = f;     arr[kol].s = s;     arr[kol].prev = beg[f];     beg[f] = kol++;     arr[kol].f = s;     arr[kol].s = f;     arr[kol].prev = beg[s];     beg[s] = kol++;   }   long long tmp[100005];   long long DFS(int pos, int fr = 0, int p = -1) {     long long child = 0, ret = 0;     int nfr = 0;     for (int i = beg[pos]; i != -1; i = arr[i].prev) {       if (arr[i].s == p) {         continue;       }       if (q[arr[i].s] > 1) {         q[arr[i].s]--;         tmp[fr + nfr] = DFS(arr[i].s, fr + nfr, pos) + 1;         child += q[arr[i].s];         nfr++;       } else {         child += q[arr[i].s];       }     }     sort(tmp + fr, tmp + fr + nfr, greater<long long>());     if (nfr >= q[pos]) {       for (int i = 0; i < q[pos]; i++) {         ret += tmp[fr + i] + 1;       }       q[pos] = 0;     } else {       for (int i = 0; i < nfr; i++) {         ret += tmp[fr + i] + 1;       }       q[pos] -= nfr;       ret += 2 * min((long long)q[pos], child);       q[pos] -= min((long long)q[pos], child);     }     return ret;   }   int main() {     memset(beg, -1, sizeof beg);     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &q[i]);     }     for (int i = 0; i < n - 1; i++) {       int f, s;       scanf( %d%d , &f, &s);       add_arc(f, s);     }     int s;     scanf( %d , &s);     s--;     if (q[s] != 0) {       cout << DFS(s) << endl;     } else {       cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100100;   const long long oo = 1e18;   int N;   long long P[MAX], D[MAX];   int L[MAX], R[MAX];   void init_L() {     stack<int> S;     for (int i = 0; i <= N + 1; ++i) {       while (S.size() >= 2) {         int x = S.top();         S.pop();         if (D[x] >= P[i] - P[S.top()]) {           S.push(x);           break;         }       }       if (!S.empty()) L[i] = S.top();       S.push(i);     }   }   void init_R() {     stack<int> S;     for (int i = N + 1; i >= 0; --i) {       while (S.size() >= 2) {         int x = S.top();         S.pop();         if (D[x] >= P[S.top()] - P[i]) {           S.push(x);           break;         }       }       if (!S.empty()) R[i] = S.top();       S.push(i);     }   }   template <class T>   struct MinQ {     deque<T> D, Q;     T top() { return D.front(); }     void push(T x) {       while (!D.empty() && x < D.back()) D.pop_back();       D.push_back(x);       Q.push_back(x);     }     void pop() {       if (D.front() == Q.front()) D.pop_front();       Q.pop_front();     }     T front() { return Q.front(); }     T empty() { return Q.empty(); }     T size() { return Q.size(); }   };   long long low(int x) {     if (x == N + 1) return -1e10;     long long ret = P[R[x]] - D[x];     return ret < P[x] ? ret : +oo;   }   long long high(int x) {     if (x == 0) return +1e10;     long long ret = P[L[x]] + D[x];     return ret > P[x] ? ret : -oo;   }   bool check(long long W) {     MinQ<long long> Q;     for (int a = 0, b = 0; a <= N; ++a) {       for (; b <= N + 1 && P[b] - P[a] <= W; ++b) Q.push(low(b));       Q.pop();       if (!Q.empty() && high(a) >= Q.top()) return true;     }     return false;   }   int main() {     scanf( %d , &N);     for (int i = 0; i <= N + 1; ++i) scanf( %lld , P + i);     for (int i = 1; i <= N; ++i) scanf( %lld , D + i), D[i] *= 2;     D[0] = D[N + 1] = oo;     init_L();     init_R();     if (R[0] != N + 1) {       puts( 0 );       return 0;     }     long long lo = 1, hi = 1e10;     while (lo < hi) {       long long mid = (lo + hi) / 2;       check(mid) ? hi = mid : lo = mid + 1;     }     printf( %.1lf n , lo / 2.0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int t, sp[N];   map<int, int> n, m, s;   vector<pair<int, int> > _n, _m, _s;   long long n_val, m_val, s_val;   void sieve(void) {     for (int i = 2; i * i < N; ++i) {       if (sp[i]) continue;       sp[i] = i;       for (int j = i * i; j < N; j += i) {         if (sp[j]) continue;         sp[j] = i;       }     }     for (int i = 2; i < N; ++i) {       if (sp[i]) continue;       sp[i] = i;     }   }   int size;   long long Less;   void backtrack(int at, long long val) {     if (at == size) {       if (val <= n_val) ++Less;       return;     }     for (int i = 0; i <= _s[at].second; ++i) {       backtrack(at + 1, val);       val *= 1LL * _s[at].first;     }     return;   }   int main() {     sieve();     scanf( %d , &t);     while (t--) {       n.clear(), m.clear(), s.clear();       _n.clear(), _m.clear(), _s.clear();       for (int i = 0; i < 3; ++i) {         int x;         scanf( %d , &x);         while (x > 1) {           int p = sp[x];           while (x % p == 0) {             ++n[p], x /= p;           }         }       }       for (int i = 0; i < 3; ++i) {         int x;         scanf( %d , &x);         while (x > 1) {           int p = sp[x];           while (x % p == 0) {             ++m[p], x /= p;           }         }       }       for (int i = 0; i < 3; ++i) {         int x;         scanf( %d , &x);         while (x > 1) {           int p = sp[x];           while (x % p == 0) {             ++s[p], x /= p;           }         }       }       ++s[2];       n_val = m_val = s_val = 1LL;       for (auto it : n) {         _n.emplace_back(it.first, it.second);         for (int i = 0; i < it.second; ++i) {           n_val *= 1LL * it.first;         }       }       for (auto it : m) {         _m.emplace_back(it.first, it.second);         for (int i = 0; i < it.second; ++i) {           m_val *= 1LL * it.first;         }       }       for (auto it : s) {         _s.emplace_back(it.first, it.second);         for (int i = 0; i < it.second; ++i) {           s_val *= 1LL * it.first;         }       }       int sz = _n.size();       long long tot = m_val;       for (int mask = 1; mask < 1 << sz; ++mask) {         int nope = 0, on = 0;         long long num = 1LL;         for (int i = 0; i < sz; ++i) {           if (!(mask & 1 << i)) continue;           ++on;           int p = _n[i].first, e = _n[i].second;           if (s[p] + 1 > e) {             nope = 1;             break;           }           for (int j = 0; j <= s[p]; ++j) {             num *= 1LL * p;           }         }         if (nope) continue;         long long cur = m_val / num;         if (on & 1) cur = -cur;         tot += cur;       }       Less = 0;       size = _s.size();       backtrack(0, 1LL);       tot += Less;       printf( %lld n , tot);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 25;   int main(int argc, char *argv[]) {     int n, k;     cin >> n >> k;     string a[n];     for (int i = (0), _b = (n); i < (_b); ++i) cin >> a[i];     uint8_t g[4];     uint32_t b[n];     for (int i = (0), _b = (n); i < (_b); ++i) {       uint8_t x = 0;       int idx = 0;       for (int j = (0), _b = (a[i].length()); j < (_b); ++j) {         if (a[i][j] ==  . ) {           g[idx] = x;           x = 0;           ++idx;         } else           x = x * 10 + a[i][j] -  0 ;       }       g[idx] = x;       b[i] = (g[0] << 24) | (g[1] << 16) | (g[2] << 8) | g[3];     }     uint32_t mask = 0xffffffff;     uint32_t ans = 0;     while (mask) {       set<uint32_t> s;       for (int i = (0), _b = (n); i < (_b); ++i) s.insert(b[i] & mask);       if (s.size() == k) ans = mask;       mask <<= 1;     }     if (!ans)       cout << -1 << endl;     else {       uint8_t a0 = (ans >> 24) & 0xff;       uint8_t a1 = (ans >> 16) & 0xff;       uint8_t a2 = (ans >> 8) & 0xff;       uint8_t a3 = ans & 0xff;       printf( %d.%d.%d.%d n , a0, a1, a2, a3);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, vector<string> > mp;   string s;   int n, pos = 0;   ;   void dfs(int lvl) {     int j = pos;     while (s[j] !=  , ) j++;     mp[lvl].push_back(s.substr(pos, j - pos));     pos = j + 1;     j++;     while (s[j] !=  , ) j++;     int ct = stoi(s.substr(pos, j - pos));     pos = j + 1;     for (int i = 1; i <= ct; i++) dfs(lvl + 1);   }   int main() {     cin >> s;     s +=  , ;     n = s.length();     while (pos < n) dfs(1);     cout << mp.size() <<   n ;     for (auto it = mp.begin(); it != mp.end(); it++) {       vector<string> vec = (*it).second;       for (string str : vec) cout << str <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   long long x[3], y[3];   int main() {     for (int i = 0; i < 3; i++) cin >> x[i] >> y[i];     if (x[0] == x[1] && x[0] == x[2] || y[0] == y[1] && y[0] == y[2]) {       printf( 1 n );       return 0;     }     int perm[3] = {0, 1, 2};     long long minx = min(x[0], min(x[1], x[2]));     long long maxx = max(x[0], max(x[1], x[2]));     long long miny = min(y[0], min(y[1], y[2]));     long long maxy = max(y[0], max(y[1], y[2]));     do {       long long x1 = x[perm[0]], y1 = y[perm[0]];       long long x2 = x[perm[1]], y2 = y[perm[1]];       long long x3 = x[perm[2]], y3 = y[perm[2]];       bool gr1 = false;       bool gr2 = false;       bool gr3 = false;       if ((x1 == minx || x1 == maxx) && (y1 == miny || y1 == maxy)) gr1 = true;       if ((x2 == minx || x2 == maxx) && (y2 == miny || y2 == maxy)) gr2 = true;       if ((x3 == minx || x3 == maxx) && (y3 == miny || y3 == maxy)) gr3 = true;       if (gr1 && gr2 && gr3) {         printf( 2 );         return 0;       }       if ((x1 == x2 || y1 == y2) && gr1 && gr3 && !gr2) {         printf( 2 );         return 0;       }     } while (next_permutation(perm, perm + 3));     printf( 3 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9 + 7);   const double PI = acos(-1.0);   const int N = 200000;   long long n, a;   long long p[N], b[N];   bool check(int x) {     long long i, m;     m = a;     for (i = 0; i < x; i++)       if (b[n - x + i] < p[i]) m -= p[i] - b[n - x + i];     return (m >= 0);   }   int main() {     long long m, l, r, i;     cin >> n >> m >> a;     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < m; i++) cin >> p[i];     sort(b, b + n);     sort(p, p + m);     l = 0;     r = min(n, m);     while (l < r) {       m = (l + r + 1) / 2;       if (check(m))         l = m;       else         r = m - 1;     }     m = 0;     for (i = 0; i < l; i++) m += p[i];     cout << l <<     << max(0ll, m - a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a[2005];   char s[2005];   int f[2005 * 2][2005], h[2005], n, m, k;   void dp(int l, int r, int x) {     if (l >= r) return;     int L = ++m, R = ++m, mid = l;     for (int i = l; i < r; i++)       if (h[i] < h[mid]) mid = i;     dp(l, mid, L), dp(mid + 1, r, R);     for (int i = 0; i < mid - l + 2; i++)       for (int j = 0; j < r - mid + 1; j++)         if (i + j <= k)           f[x][i + j] = max(f[x][i + j], h[mid] * i * j + f[L][i] + f[R][j]);   }   int main() {     scanf( %d%d  , &n, &k);     for (int i = 0; i < n; i++) gets(s), a[i] = s;     sort(a, a + n);     for (int i = 0; i < n - 1; i++) {       h[i] = min(a[i].size(), a[i + 1].size());       for (int j = 0; j < h[i]; j++)         if (a[i][j] != a[i + 1][j]) h[i] = j;     }     dp(0, n - 1, 0);     printf( %d n , f[0][k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<pair<int, int> > arr(n);       for (int i = 0; i < n; i++) cin >> arr[i].first;       for (int i = 0; i < n; i++) cin >> arr[i].second;       sort(arr.begin(), arr.end());       long long int cost = 1e18;       long long int prev = 0;       for (int i = n - 1; i >= 0; i--) {         cost = min(cost, max((long long int)arr[i].first, prev));         prev += arr[i].second;       }       cost = min(cost, prev);       cout << cost << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   map<string, string> a;   map<string, int> b;   string s, g, p;   int main() {     int n, q;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       int l = s.length();       for (int j = 0; j < l; j++) {         for (int k = 1; j + k <= l; k++) {           string c = s.substr(j, k);           if (a[c] != s) {             b[c]++;             a[c] = s;           }         }       }     }     cin >> q;     for (int h = 0; h < q; h++) {       cin >> p;       if (b[p] == 0) {         cout << b[p] <<                  <<  -  << endl;       } else {         cout << b[p] <<     << a[p] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s = 19, i, sum, j, l;   int main() {     cin >> n;     for (i = 1; i < n; i++) {       s += 9;       l = s;       while (l) {         sum += (l % 10);         l /= 10;       }       if (sum != 10) i--;       sum = 0;     }     cout << s;   }