malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   int main() {     string s;     cin >> s;     string ans;     bool found{false};     for (int i = 0; i < (int)s.size(); i++) {       if ((i == (int)s.size() - 1) && !found) continue;       if (s[i] ==  1  || found)         ans += s[i];       else         found = true;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> st;   int arr[1000005];   bool taken[1000005];   map<int, int> mp;   int main() {     int n;     (scanf( %d , &n));     for (int i = 1; i <= n; i++) {       (scanf( %d , &arr[i]));       mp[arr[i]]++;       st.insert(i);     }     for (int i = 1; i <= n; i++) st.erase(arr[i]);     memset(taken, false, sizeof(taken));     cout << st.size() <<   n ;     for (int i = 1; i <= n; i++) {       if (mp[arr[i]] > 1) {         if (*st.begin() > arr[i] && taken[arr[i]] == false)           taken[arr[i]] = true;         else {           mp[arr[i]]--;           arr[i] = *st.begin();           st.erase(st.begin());         }       }     }     for (int i = 1; i <= n; i++) cout << arr[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int neginf = 0xc0c0c0c0;   const int mod = 1000000007;   bool cmp(const double& a, const double& b, const double TOL = 1e-9) {     return (a + TOL > b) ? (b + TOL > a) ? 0 : 1 : -1;   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;     }     return res;   }   int n, A, B, C, T;   int main() {     cin >> n >> A >> B >> C >> T;     vector<int> msg(n);     for (int(i) = (0); (i) < (n); ++(i)) cin >> msg[i];     sort((msg).begin(), (msg).end());     int last = msg.back();     long long best = 0;     for (int v : msg) {       int gain;       if (C > B) {         gain = A + (T - v) * (C - B);       } else         gain = A;       best += gain;     }     cout << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool done[123][123];   char s[123][123];   vector<pair<pair<long long, long long>, long long int> > v;   int main() {     long long int n, m;     scanf( %lld%lld , &n, &m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         done[i][j] = false;         scanf(  %c , &s[i][j]);       }     for (int i = 1; i < n - 1; ++i)       for (int j = 1; j < m - 1; ++j)         if (s[i][j] !=  . ) {           if (s[i - 1][j] ==  *  && s[i + 1][j] ==  *  && s[i][j - 1] ==  *  &&               s[i][j + 1] ==  * ) {             long long int up = 0, dn = 0, lt = 0, rt = 0;             for (int k = i - 1; k >= 0; k--)               if (s[k][j] ==  . )                 break;               else                 up++;             for (int k = i + 1; k < n; k++)               if (s[k][j] ==  . )                 break;               else                 dn++;             for (int k = j - 1; k >= 0; k--)               if (s[i][k] ==  . )                 break;               else                 lt++;             for (int k = j + 1; k < m; k++)               if (s[i][k] ==  . )                 break;               else                 rt++;             long long int mn = min(up, min(dn, min(lt, rt)));             if (mn) {               v.push_back(                   make_pair(pair<long long, long long>(i + 1, j + 1), mn));               int k, cnt;               cnt = mn;               done[i][j] = true;               for (k = i - 1; cnt; k--, cnt--) done[k][j] = true;               cnt = mn;               for (k = i + 1; cnt; k++, cnt--) done[k][j] = true;               cnt = mn;               for (k = j - 1; cnt; k--, cnt--) done[i][k] = true;               cnt = mn;               for (k = j + 1; cnt; k++, cnt--) done[i][k] = true;             }           }         }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (s[i][j] ==  *  && done[i][j] == false) {           printf( -1 n );           return 0;         }     printf( %lld n , (long long int)v.size());     for (int i = 0; i != (long long int)v.size(); ++i)       printf( %lld %lld %lld n , v[i].first.first, v[i].first.second,              v[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, len[400], cnt, Block, pos[100010];   long long c[100010], sum[400], v[100010], cov[400], dlt[400];   bool mak[400];   void BuildBlocks() {     int tail;     for (int i = 1; i <= n; i = tail + 1) {       tail = min(i + Block - 1, n);       ++cnt;       len[cnt] = tail;       for (int j = i; j <= tail; j++) pos[j] = cnt;     }   }   long long Abs(long long x) { return (x < 0) ? -x : x; }   void work(int x, int y, long long k) {     int now = pos[x];     long long delta;     for (int i = x; i <= y; i++) {       delta = Abs(v[i] - k);       v[i] = k;       c[i] += delta;       sum[now] += delta;     }   }   void pushdown(int now) {     if (cov[now] != 0) {       for (int i = len[now - 1] + 1; i <= len[now]; i++) v[i] = cov[now];       cov[now] = 0;     }   }   void Change(int x, int y, long long k) {     int px, py, H, T;     px = pos[x];     py = pos[y];     H = px + 1;     T = py - 1;     if (px == py) {       pushdown(px);       work(x, y, k);       mak[px] = false;       return;     }     if (x == len[px - 1] + 1)       --H;     else {       pushdown(px);       mak[px] = false;       work(x, len[px], k);     }     if (y == len[py])       ++T;     else {       pushdown(py);       mak[py] = false;       work(len[py - 1] + 1, y, k);     }     if (H > T) return;     for (int i = H; i <= T; i++)       if (mak[i] == false) {         work(len[i - 1] + 1, len[i], k);         mak[i] = true;       } else {         if (cov[i] == 0) cov[i] = v[len[i]];         sum[i] += (long long)(len[i] - len[i - 1]) * Abs(k - cov[i]);         dlt[i] += Abs(k - cov[i]);         cov[i] = k;       }   }   long long count(int x, int y) {     long long ans = 0;     int now = pos[x];     for (int i = x; i <= y; i++) ans += c[i] + dlt[now];     return ans;   }   long long Query(int x, int y) {     int px, py, H, T;     long long ans = 0;     px = pos[x];     py = pos[y];     H = px + 1;     T = py - 1;     if (px == py) return count(x, y);     if (x == len[px - 1] + 1)       --H;     else       ans += count(x, len[px]);     if (y == len[py])       ++T;     else       ans += count(len[py - 1] + 1, y);     for (int i = H; i <= T; i++) ans += sum[i];     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) v[i] = i;     Block = ceil(sqrt(n));     BuildBlocks();     for (int i = 1; i <= m; i++) {       int opt, x, y, k;       scanf( %d%d%d , &opt, &x, &y);       if (opt == 1) {         scanf( %d , &k);         Change(x, y, k);       } else         printf( %I64d n , Query(x, y));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, k;     cin >> t;     while (t > 0) {       cin >> n >> k;       if (n < k) {         cout << k - n << endl;       } else if (n % 2 == k % 2) {         cout << 0 << endl;       } else {         cout << 1 << endl;       }       t--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N], b[N], x[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, t;     cin >> n >> t;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) cin >> x[i];     for (int i = 1; i <= n; ++i)       if (x[i] < i || x[i] < x[i - 1]) return puts( No ), 0;     for (int i = 1; i < n; ++i)       if (x[i] != x[i + 1] && x[i] != i) return puts( No ), 0;     a[n + 1] = a[n] + 5;     for (int i = 1; i <= n; ++i) {       if (x[i] == i)         b[i] = a[i + 1] + t - 1;       else         b[i] = a[i + 1] + t;       if (b[i] == b[i - 1]) return puts( No ), 0;     }     cout <<  Yes  << endl;     for (int i = 1; i <= n; ++i) cout << b[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using li = long long;   using ld = long double;   void solve(bool);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(20);     solve(true);     return 0;   }   const int maxn = (int)1e5 + 5;   int n, a[maxn];   map<int, int> m;   void solve(bool __attribute__((unused)) read) {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] > 0 && !m.count(a[i] - 1)) {         cout << i + 1 <<   n ;         return;       }       m[a[i]] = 1;     }     cout << -1 <<   n ;     return;   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   string m =  abacaba ;   long long int bal(string s) {     long long int bl = 0;     for (long long int i = 0; i < n - 6; i++) {       bool b = true;       for (long long int j = 0; j < m.size(); j++) {         if (s[i + j] != m[j]) {           b = false;           break;         }       }       if (b) bl++;     }     return bl;   }   int main() {     long long int tc;     scanf( %lld , &tc);     while (tc--) {       scanf( %lld , &n);       string s;       cin >> s;       long long int koto = bal(s);       if (koto == 1) {         for (long long int i = 0; i < n; i++) {           if (s[i] ==  ? ) s[i] =  d ;         }         cout <<  YES  << endl << s << endl;         continue;       }       if (koto >= 2) {         cout <<  NO  << endl;         continue;       }       long long int oh = 0;       for (long long int i = 0; i < n - 6; i++) {         string ans = s;         for (long long int j = 0; j < m.size(); j++) {           if (ans[i + j] ==  ? ) ans[i + j] = m[j];         }         koto = bal(ans);         if (koto > 1 || koto == 0) continue;         for (long long int j = 0; j < n; j++) {           if (ans[j] ==  ? ) ans[j] =  d ;         }         oh = 1;         s = ans;         break;       }       if (oh) {         cout <<  YES  << endl << s << endl;       } else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int n = (int)s.size();       vector<int> nxt(n);       int pos = -1;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) pos = i;         nxt[i] = pos;       }       int ans = 0;       for (int r = 0; r < n; r++) {         int val = 0;         for (int l = r; r - l < 20 && l >= 0; l--) {           if (s[l] ==  0 ) continue;           val += 1 << (r - l);           if (val <= r - ((l != 0) ? nxt[l - 1] : -1)) ans++;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p[200001], bl, cnt, cntbl, visited[200001], flag;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) {         int j = i, tmp = j;         while (!visited[j]) {           visited[j] = 1;           j = p[j];         }         if (j != tmp) flag = 1;         cnt++;       }     }     for (int i = 0; i < n; i++) {       cin >> bl;       if (bl) cntbl++;     }     cout << ((cnt == 1 && !flag ? 0 : cnt) + (cntbl % 2 == 0 ? 1 : 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 110000;   int N;   long long A[NMax], B[NMax], dp[NMax];   int Q[NMax], L, R;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %I64d , A + i);     for (int i = 1; i <= N; i++) scanf( %I64d , B + i);     L = 0;     R = 0;     Q[L] = 1;     for (int i = 2; i <= N; i++) {       while (R > L &&              (double)(dp[Q[L + 1]] - dp[Q[L]]) / (B[Q[L]] - B[Q[L + 1]]) <                  (double)A[i])         L++;       dp[i] = dp[Q[L]] + B[Q[L]] * A[i];       Q[++R] = i;       while (R > L + 1) {         int c = R, b = R - 1, a = R - 2;         if ((double)(dp[Q[c]] - dp[Q[b]]) / (B[Q[b]] - B[Q[c]]) <             (double)(dp[Q[b]] - dp[Q[a]]) / (B[Q[a]] - B[Q[b]])) {           Q[b] = Q[c];           R--;         } else           break;       }     }     printf( %I64d n , dp[N]);     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     string p(s.size(),  0 );     int dif = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) dif++;     }     if (dif % 2 != 0) return cout <<  impossible , 0;     int a(0), b(0);     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) {         if (a <= b) {           p[i] = t[i];           a++;         } else {           p[i] = s[i];           b++;         }       }     }     cout << p;   }
#include <bits/stdc++.h>   using namespace std;   long long aa[258], bb[258];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0), cerr <<   ;     string a, b;     long long n;     cin >> n;     cin >> a >> b;     long double s = 0;     for (int i = 1; i <= n; ++i)       aa[b[i - 1]] += i,           s += (n - i + 1) * (aa[a[i - 1]] + bb[b[i - 1]]) * 1.0 / n,           bb[a[i - 1]] += i;     long double l = s * 1.0 / (n + 1) / (2 * n + 1);     l *= 6.0;     cout.precision(9);     cout << fixed << l;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int tt = 0; tt < t; tt++) {       int n, flag = 0;       cin >> n;       vector<int> q(n + 1);       vector<int> p(n + 1, -1);       vector<int> use(n + 1, 0);       for (int i = 1; i <= n; i++) cin >> q[i];       p[1] = q[1];       use[q[1]] = 1;       for (int i = 2; i <= n; i++)         if (q[i] > q[i - 1]) {           p[i] = q[i];           use[q[i]] = 1;         }       vector<int> w;       for (int i = 1; i <= n; i++)         if (use[i] == 0) w.push_back(i);       int u = 0;       for (int i = 1; i <= n; i++)         if (p[i] == -1) {           p[i] = w[u];           u++;         }       int ma = p[1];       for (int i = 1; i <= n; i++) {         ma = max(ma, p[i]);         if (ma != q[i]) flag = 1;       }       if (flag == 0) {         for (int i = 1; i <= n; i++) cout << p[i] <<    ;       } else         cout << -1;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace ioput {   template <typename T>   T read() {     T x = 0, f = 1;     char c = getchar_unlocked();     while ((c <  0 ) || (c >  9 )) {       if (c ==  - ) f = -1;       c = getchar_unlocked();     }     while ((c >=  0 ) && (c <=  9 ))       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar_unlocked();     return x * f;   }   template <typename T>   void write(T x, char c) {     static char t[20];     static int tlen;     t[tlen = 1] = c;     if (x < 0) putchar_unlocked( - ), x = -x;     do t[++tlen] = x % 10 +  0 , x /= 10;     while (x);     while (tlen) putchar_unlocked(t[tlen--]);   }   }  // namespace ioput   using namespace ioput;   const int maxn = 100005;   struct seg {     int id, pos, t;     bool operator<(const seg &A) const {       return pos - t == A.pos - A.t ? pos < A.pos : pos - t < A.pos - A.t;     }   } a[maxn], b[maxn], tmp[maxn];   int a_cnt, b_cnt;   int p[maxn], n, W, H;   pair<int, int> ans[maxn];   int main() {     n = read<int>(), W = read<int>(), H = read<int>();     int type, pos, t;     for (int i = 1, iend = n; i <= iend; ++i) {       type = read<int>(), pos = read<int>(), t = read<int>();       if (type == 1)         a[++a_cnt] = (seg){i, pos, t};       else         b[++b_cnt] = (seg){i, pos, t};     }     sort(a + 1, a + 1 + a_cnt);     sort(b + 1, b + 1 + b_cnt);     int cur = 1;     for (int i = 1, iend = a_cnt; i <= iend; ++i) {       static stack<int> stk;       int j = i;       while ((j < a_cnt) && (a[j + 1].pos - a[j + 1].t == a[i].pos - a[i].t)) ++j;       int pos = j, tmpcur;       while ((cur <= b_cnt) && (b[cur].pos - b[cur].t < a[i].pos - a[i].t)) ++cur;       tmpcur = cur;       for (int k = j, kend = i; k >= kend; --k) stk.push(a[k].id);       while ((cur <= b_cnt) && (b[cur].pos - b[cur].t == a[i].pos - a[i].t))         stk.push(b[cur].id), ++cur;       for (int k = i, kend = j; k <= kend; ++k) a[k].id = stk.top(), stk.pop();       for (int k = cur - 1, kend = tmpcur; k >= kend; --k)         b[k].id = stk.top(), stk.pop();       i = j;     }     for (int i = 1, iend = a_cnt; i <= iend; ++i)       ans[a[i].id] = make_pair(a[i].pos, H);     for (int i = 1, iend = b_cnt; i <= iend; ++i)       ans[b[i].id] = make_pair(W, b[i].pos);     for (int i = 1, iend = n; i <= iend; ++i)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ipow(int base, int exp) {     int result = 1;     for (;;) {       if (exp & 1) result *= base;       exp >>= 1;       if (!exp) break;       base *= base;     }     return result;   }   void show(int a[], int array_size) {     for (int i = 0; i < array_size; ++i) cout << a[i] <<    ;     cout <<   n ;   }   int cc(int target, int q, int current) {     if (q == 0) {       if (target == current)         return 1;       else         return 0;     } else       return (cc(target, q - 1, current + 1) + cc(target, q - 1, current - 1));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int x, y;     cin >> x >> y;     int v, i;     cin >> v;     long long o = 0;     for (i = 0; i < v; i++) {       int x1, y1, X, Y;       cin >> x1 >> y1;       if (x1 == 0)         X = 1000000005;       else         X = max((1 - x) / x1, (n - x) / x1);       if (y1 == 0)         Y = 1000000005;       else         Y = max((1 - y) / y1, (m - y) / y1);       int d = min(X, Y);       o = o + (long long)d;       x += d * x1;       y += d * y1;     }     cout << o <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tt = 1;     while (tt--) {       int n, a, b, c;       cin >> n >> a >> b >> c;       int mv = min(min(a, b), c);       int q = n / mv, ans = 0;       for (int x = 0; x <= q; x++) {         for (int y = 0; y <= q - x; y++) {           float z = ((n - x * a - y * b) * 1.0) / c;           if (z == (int)z && z >= 0) ans = max(ans, x + y + (int)z);         }       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a, b, t, points[100000];   int n;   double d[100000];   pair<double, int> s1[100000], s2[100000];   double dist(pair<int, int> first, pair<int, int> second) {     long long x = first.first - second.first;     long long y = first.second - second.second;     return sqrt(x * x + y * y);   }   int main() {     cin >> a.first >> a.second >> b.first >> b.second >> t.first >> t.second >> n;     double ans = 0;     for (int i = 0; i < n; i++) {       cin >> points[i].first >> points[i].second;       d[i] = dist(points[i], t);       ans += 2 * d[i];       s1[i] = pair<double, int>(dist(a, points[i]) - d[i], i);       s2[i] = pair<double, int>(dist(b, points[i]) - d[i], i);     }     sort(s1, s1 + n);     sort(s2, s2 + n);     double ans1;     double ans2;     double ans3;     ans1 = ans + s1[0].first;     ans2 = ans + s2[0].first;     if (s1[0].second != s2[0].second) {       ans3 = ans + s1[0].first + s2[0].first;     } else       ans3 = ans + min(s1[0].first + s2[1].first, s1[1].first + s2[0].first);     cout << setprecision(9);     cout << min(ans1, min(ans2, ans3));   }
#include <bits/stdc++.h>   using namespace std;   int a[102];   int b[102];   int main() {     int n, m;     cin >> n >> m;     int num = 0;     for (int i = 1; i <= m; i++) {       int q = 0;       for (int j = 1; j <= n; j++) {         cin >> a[j];         q = max(q, a[j]);       }       for (int l = 1; l <= n; l++) {         if (a[l] == q) {           b[l]++;           break;         }       }     }     int t = 0;     for (int j = 1; j <= 100; j++) {       t = max(t, b[j]);     }     for (int l = 1; l <= 100; l++) {       if (t == b[l]) {         cout << l;         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 300005;   int n, m;   int p[max_n];   int rk[max_n];   bool vis[max_n];   vector<int> G[max_n];   set<int> s;   void dfs(int u) {     for (auto v : G[u]) s.erase(rk[v]);     vector<int> can;     for (auto v : s) {       if (v < rk[u]) {         v = p[v];         can.push_back(v);         vis[rk[v]] = true;       } else         break;     }     for (auto v : G[u])       if (!vis[rk[v]]) s.insert(rk[v]);     for (auto v : can) s.erase(rk[v]);     for (auto v : can) dfs(v);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , p + i), rk[p[i]] = i;     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[v].push_back(u);     }     for (int i = 1; i <= n - 1; i++) s.insert(i);     vis[n] = true;     dfs(p[n]);     printf( %d n , s.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, a, b;     cin >> n >> a >> b;     if (abs(a - b) > 1 || (a + b) > n - 2) {       cout <<  -1  << endl;       return;     }     int l = 1, r = n;     int arr[n + 5];     for (int i = 1; i <= n; i++) arr[i] = i;     if (a > b)       for (int i = 1; i <= a; i++) swap(arr[r], arr[r - 1]), r -= 2;     else if (b > a)       for (int i = 1; i <= b; i++) swap(arr[l], arr[l + 1]), l += 2;     else {       if (b > 0)         swap(arr[l], arr[l + 1]), l += 2, swap(arr[r], arr[r - 1]), r -= 2, b--;       for (int i = 1; i <= b; i++) swap(arr[l], arr[l + 1]), l += 2;     }     for (int i = 1; i <= n; i++) cout << arr[i] <<    ;     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[m], b[m];     for (int i = 0; i < m; i++) {       cin >> a[i];       b[i] = a[i];     }     int min = 0;     for (int i = 0; i < n; i++) {       int t1 = INT_MAX;       int loc = -1;       for (int j = 0; j < m; j++) {         if (a[j] < t1 && a[j] > 0) {           t1 = a[j];           loc = j;         }       }       a[loc] -= 1;       min += t1;     }     int max = 0;     for (int i = 0; i < n; i++) {       int t = INT_MIN;       int loc = -1;       for (int j = 0; j < m; j++) {         if (b[j] > t && b[j] > 0) {           t = b[j];           loc = j;         }       }       max += t;       b[loc] -= 1;     }     cout << max <<     << min << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int inf(1010101010);   const long long P(29);   long long pp[100005];   long long ch[100005];   inline bool eq(int start1, int start2, int le) {     long long h1(ch[start1 + le] - ch[start1]);     long long h2(ch[start2 + le] - ch[start2]);     return h1 * pp[start2] == h2 * pp[start1];   }   int n, a[100005];   map<int, vector<int> > startpos;   int shortest[100005];   int cmin[100005];   int main() {     cin >> n;     for (int i(0); i < (n); i++) cin >> a[i], startpos[a[i]].push_back(i);     ch[0] = 0;     pp[0] = 1;     int i(1);     for (; i <= (n); i++) {       ch[i] = ch[i - 1] + pp[i - 1] * a[i - 1];       pp[i] = pp[i - 1] * P;     }     for (int i(0); i < (n); i++) {       shortest[i] = inf;       int startnum(a[i]);       vector<int> const& v(startpos[startnum]);       for (__typeof((v).end()) it((v).begin()); it != ((v).end()); ++it) {         int j(*it);         if (j <= i) continue;         int le(j - i);         if (j + le <= n && eq(i, j, le)) shortest[i] = min(shortest[i], le);       }     }     cmin[n] = inf;     for (int i(n - 1); i >= (0); i--) {       cmin[i] = min(cmin[i + 1], shortest[i]);     }     int pt(0);     for (; pt < (n);) {       int le(cmin[pt]);       if (le == inf) break;       int loc(find(shortest + pt, shortest + n, le) - shortest);       pt = loc + le;     }     cout << (n - pt) << endl;     for (int i(pt); i < (n); i++) cout << a[i] <<    ;     cout << endl;   }