malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void next_int(T &x) {     x = 0;     char c;     bool neg = false;     while (!isdigit(c = getchar()))       if (c ==  - ) neg = true;     do x = x * 10 + c - 48;     while (isdigit(c = getchar()));     if (neg) x = -x;   }   template <typename T>   inline void write_int(T x, char last = 0) {     if (x < 0) putchar( - ), x = abs(x);     char tmp[20];     int cnt = 0;     while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;     tmp[cnt] = x + 48;     for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);     if (last) putchar(last);   }   struct Line {     long long a, b;     Line(long long _a, long long _b) : a(_a), b(_b) {}   };   const int N = (int)2e5 + 5;   vector<Line> hull;   int n;   long long a[N], sum[N], sum2[N];   bool bad(Line l1, Line l2, Line l3) {     return (l1.b - l3.b) * (l2.a - l1.a) <= (l3.a - l1.a) * (l1.b - l2.b);   }   void add(Line x) {     while (((int)hull.size()) >= 2 &&            bad(hull[((int)hull.size()) - 2], hull[((int)hull.size()) - 1], x))       hull.pop_back();     hull.push_back(x);   }   long long getval(int pos, long long x) {     if (pos >= ((int)hull.size())) return (long long)1e18 + 7;     return hull[pos].a * x + hull[pos].b;   }   long long read(long long x) {     int lo = 0, hi = ((int)hull.size()) - 1, mid;     while (lo != hi) {       mid = (lo + hi) >> 1;       if (getval(mid, x) <= getval(mid + 1, x))         hi = mid;       else         lo = mid + 1;     }     return getval(lo, x);   }   int main() {     next_int(n);     for (int i = (1); i <= (n); ++i) {       next_int(a[i]);       sum[i] = sum[i - 1] + a[i];       sum2[i] = sum2[i - 1] + (long long)i * a[i];     }     add(Line(0, 0));     long long res = 0;     for (int i = (1); i <= (n); ++i) {       res = max(res, -read(-sum[i]) + sum2[i]);       add(Line(-i, sum2[i] - (long long)i * sum[i]));     }     write_int(res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     string s;     cin >> s;     vector<int> freq(27, 0);     for (i = 0; i < s.length(); ++i) {       if (s[i] ==  B )         freq[26]++;       else if (s[i] >=  a  && s[i] <=  z )         freq[s[i] -  a ]++;     }     cout << (min(freq[26],                  min(freq[ u  -  a ],                      min(freq[ l  -  a ],                          min(freq[1],                              min(freq[ s  -  a ],                                  min(freq[0] >> 1, min(freq[ u  -  a ] >> 1,                                                        freq[ r  -  a ]))))))))          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[4], b[4];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     if (!n)       puts( YES n1 n1 n3 n3 );     else if (n == 1)       printf( YES n%d n%d n%d n , a[0] << 1, a[0] << 1, a[0] + (a[0] << 1));     else if (n == 2) {       if (a[0] * 3 == a[1])         printf( YES n%d n%d n , a[0] << 1, a[0] << 1);       else if (a[1] < a[0] * 3)         printf( YES n%d n%d n , a[0] * 3, a[0] * 4 - a[1]);       else         puts( NO );     } else if (n == 4) {       if (a[0] + a[3] == a[1] + a[2] && (a[3] - a[0]) << 1 == a[1] + a[2])         puts( YES );       else         puts( NO );     } else {       int i;       for (i = 1; i <= 1000000; ++i) {         for (int j = 0; j < 3; ++j) b[j] = a[j];         b[3] = i;         sort(b, b + 4);         if (b[0] + b[3] == b[1] + b[2] && (b[3] - b[0]) << 1 == b[1] + b[2])           break;       }       if (i <= 1000000)         printf( YES n%d n , i);       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   int edge[110][110];   int main() {     memset(edge, 0, sizeof(edge));     int n, u, v, w;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &w);       edge[i % n][(i + 1) % n] = edge[(i + 1) % n][i % n] = w;     }     scanf( %d%d , &u, &v);     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         if (i == j)           edge[i][j] = 0;         else if (edge[i][j] == 0)           edge[i][j] = 1000000;       }     for (int k = 0; k < n; ++k)       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j) {           if (i == k || j == k) continue;           if (edge[i][j] > edge[i][k] + edge[k][j])             edge[i][j] = edge[i][k] + edge[k][j];         }     printf( %d n , edge[u - 1][v - 1]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int m, n;       scanf( %d %d , &n, &m);       char s[n][m];       for (int i = 0; i < n; i++) {         scanf( %s , s[i]);       }       int ans = 0;       for (int i = 0; i < n; i++)         if (s[i][m - 1] ==  R ) ans++;       for (int i = 0; i < m; i++)         if (s[n - 1][i] ==  D ) ans++;       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mx = 105;   const long long mx1 = 1000001;   const long long mod = 1000000007;   vector<vector<long long> > edges;   void adds(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   long long mul(long long a, long long b) { return (long long)a * b % mod; }   void max_self(long long &a, long long b) { a = max(a, b); }   int main() {     int n, i, res = 0, inc1 = -1, lp = 0, rp = 0;     cin >> n;     string s;     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ( ) {         lp++;       } else {         rp++;       }       if (rp > lp && inc1 == -1) {         inc1 = i;       } else if (lp == rp && inc1 != -1) {         res += i - inc1 + 1;         inc1 = -1;       }     }     if (lp != rp)       cout <<  -1 n ;     else {       cout << res <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s1;     vector<string> vc;     cin >> s;     for (int i = 0; i < s.size(); i++) {       s1 = s[i];       vc.push_back(s1);       for (int j = i + 1; j < s.size(); j++) {         s1 = s[i];         s1 += s[j];         vc.push_back(s1);         for (int l = j + 1; l < s.size(); l++) {           s1 = s[i];           s1 += s[j];           s1 += s[l];           vc.push_back(s1);           for (int k = l + 1; k < s.size(); k++) {             s1 = s[i];             s1 += s[j];             s1 += s[l];             s1 += s[k];             vc.push_back(s1);             for (int a = k + 1; a < s.size(); a++) {               s1 = s[i];               s1 += s[j];               s1 += s[l];               s1 += s[k];               s1 += s[a];               vc.push_back(s1);               for (int b = a + 1; b < s.size(); b++) {                 s1 = s[i];                 s1 += s[j];                 s1 += s[l];                 s1 += s[k];                 s1 += s[a];                 s1 += s[b];                 vc.push_back(s1);                 for (int c = b + 1; c < s.size(); c++) {                   s1 = s[i];                   s1 += s[j];                   s1 += s[l];                   s1 += s[k];                   s1 += s[a];                   s1 += s[b];                   s1 += s[c];                   vc.push_back(s1);                   for (int d = c + 1; d < s.size(); d++) {                     s1 = s[i];                     s1 += s[j];                     s1 += s[l];                     s1 += s[k];                     s1 += s[a];                     s1 += s[b];                     s1 += s[c];                     s1 += s[d];                     vc.push_back(s1);                     for (int e = d + 1; e < s.size(); e++) {                       s1 = s[i];                       s1 += s[j];                       s1 += s[l];                       s1 += s[k];                       s1 += s[a];                       s1 += s[b];                       s1 += s[c];                       s1 += s[d];                       s1 += s[e];                       vc.push_back(s1);                       for (int f = e + 1; f < s.size(); f++) {                         s1 = s[i];                         s1 += s[j];                         s1 += s[l];                         s1 += s[k];                         s1 += s[a];                         s1 += s[b];                         s1 += s[c];                         s1 += s[d];                         s1 += s[e];                         s1 += s[f];                         vc.push_back(s1);                       }                     }                   }                 }               }             }           }         }       }     }     long long i;     s1 = s[0];     string ans = s1;     for (i = 0; i < vc.size(); i++) {       string p = vc[i];       reverse(p.begin(), p.end());       if (vc[i] == p) {         ans = max(ans, p);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   double f(double z, double first) {     int k = 0;     double w;     while (first > 2 * z) {       w = z;       while (2 * w < first) w *= 2, k += 2;       first -= w;     }     if (first <= z)       return first;     else       return 2 * z - first;   }   int main() {     int b, c;     double a, lo, hi, mid, w;     int k;     while (scanf( %d %d , &c, &b) == 2) {       a = c;       if (c < b) {         printf( -1 n );       } else if (c == b) {         printf( %d n , b);       } else {         k = ((int)(floor(a / b + 1e-9) + 1e-9 - 1)) / 2;         hi = a / (2 * k + 1);         lo = a / (2 * k + 2);         k = 60;         while (k--) {           mid = (lo + hi) / 2.0;           w = f(mid, a);           if (w <= b)             lo = mid;           else             hi = mid;         }         printf( %.10lf n , mid);       }     }     return 0;   }
#include<bits/stdc++.h>   //#include<ext/pb_ds/assoc_container.hpp>   //#include<ext/pb_ds/tree_policy.hpp>   //#include <ext/pb_ds/trie_policy.hpp>   //using namespace __gnu_pbds;   using namespace std;   #define ll     long long int   #define ld    long double   #define mod             1000000007   #define inf             1e18   #define endl     n    #define pb     push_back   #define vi              vector<ll>   #define vs    vector<string>   #define pii             pair<ll,ll>   #define ump    unordered_map   #define mp     make_pair   #define pq_max          priority_queue<ll>   #define pq_min          priority_queue<ll,vi,greater<ll> >   #define all(n)    n.begin(),n.end()   #define ff     first   #define ss     second   #define mid(l,r)        (l+(r-l)/2)   #define bitc(n)   __builtin_popcount(n)   #define loop(i,a,b)  for(int i=(a);i<=(b);i++)   #define looprev(i,a,b)  for(int i=(a);i>=(b);i--)   #define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)   #define log(args...)  { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }   #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<   ;cout<<endl;    template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;}   template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}   vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}   void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {       cout << *it <<   =   << a << endl;       err(++it, args...);   }   //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;   //typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;   void file_i_o()   {       ios_base::sync_with_stdio(0);        cin.tie(0);        cout.tie(0);       #ifndef ONLINE_JUDGE           freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);       #endif   }   int main(int argc, char const *argv[]) {       clock_t begin = clock();       file_i_o();       // Write your code here....       int t;       cin>>t;       while(t--){           int n;           cin>>n;           set<char> ts;           string s;           cin>>s;           int fl=0;           ts.insert(s[0]);           for(int i=1;i<n;i++){               if(s[i]==s[i-1]){                   continue;               }else{                   if(ts.find(s[i])==ts.end()){                       ts.insert(s[i]);                   }else{                       cout<< NO n ;                       fl=1;                       break;                   }               }           }           if(fl!=1){               cout<< YES n ;           }       }                          #ifndef ONLINE_JUDGE                  clock_t end = clock();         cout<<  n nExecuted In:  <<double(end - begin) / CLOCKS_PER_SEC*1000<<  ms ;       #endif        return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long double pii = 3.14159265359;   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 200001;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T-- != 0) {       int N;       cin >> N;       vector<int> v(2);       for (int x = 0; x < (N); x++) {         int nb;         cin >> nb;         v[nb]++;       }       if (v[0] >= v[1]) {         cout << v[0] << nl;         for (int x = 0; x < (v[0]); x++) cout << 0 <<    ;       } else {         cout << v[1] - v[1] % 2 << nl;         for (int x = 0; x < (v[1] - v[1] % 2); x++) {           cout << 1 <<    ;         }       }       cout << nl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   char s[2010][1010];   int a[1010][1010];   int main() {     scanf( %d%d%d n , &n, &m, &k);     if (k == 1) {       int cnt = 0;       int tot = 0;       for (int i = 0; i < 2 * n - 1; ++i) {         gets(s[0]);         for (int j = 0; j < m - ((i + 1) & 1); ++j, ++tot)           if (s[0][j] ==  E ) cnt++;       }       if (cnt * 4 >= tot * 3) {         puts( YES );         for (int i = 0; i < n; ++i) {           for (int j = 0; j < m; ++j) {             if (j != 0) printf(   );             printf( 1 );           }           printf(  n );         }       } else         puts( NO );       return 0;     }     puts( YES );     for (int i = 0; i < 2 * n - 1; ++i) gets(s[i]);     if (n < m) {       for (int i = 0; i < n; ++i) {         int ii = 2 * i;         a[i][0] = 0;         for (int j = 1; j < m; ++j)           if (s[ii][j - 1] ==  E )             a[i][j] = a[i][j - 1];           else             a[i][j] = 1 - a[i][j - 1];       }       for (int i = 1; i < n; ++i) {         int cnt = 0;         for (int j = 0; j < m; ++j)           if (s[2 * i - 1][j] ==  E )             cnt += a[i][j] == a[i - 1][j];           else             cnt += a[i][j] != a[i - 1][j];         if (cnt < m - cnt)           for (int j = 0; j < m; ++j) a[i][j] = 1 - a[i][j];       }     } else {       for (int i = 0; i < m; ++i) {         a[0][i] = 0;         for (int j = 1; j < n; ++j)           if (s[2 * j - 1][i] ==  E )             a[j][i] = a[j - 1][i];           else             a[j][i] = 1 - a[j - 1][i];       }       for (int i = 1; i < m; ++i) {         int cnt = 0;         for (int j = 0; j < n; ++j)           if (s[2 * j][i - 1] ==  E )             cnt += a[j][i] == a[j][i - 1];           else             cnt += a[j][i] != a[j][i - 1];         if (cnt < n - cnt)           for (int j = 0; j < n; ++j) a[j][i] = 1 - a[j][i];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (j != 0) printf(   );         printf( %d , a[i][j] + 1);       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y, z;   };   double len[10000];   double sum[10000];   int n;   Point point[10001], potter;   double vp, vs;   double getDist(Point &a, Point &b) {     double x = a.x - b.x;     double y = a.y - b.y;     double z = a.z - b.z;     return sqrt(x * x + y * y + z * z);   }   double getGapConst(Point &tar, Point &vec) {     if (!(abs(vec.x - 0.0) < 1e-10)) return tar.x / vec.x;     if (!(abs(vec.y - 0.0) < 1e-10)) return tar.y / vec.y;     return tar.z / vec.z;   }   int main(void) {     scanf( %d , &n);     for (int i = 0; i <= n; i++)       scanf( %lf %lf %lf , &point[i].x, &point[i].y, &point[i].z);     scanf( %lf %lf , &vp, &vs);     scanf( %lf %lf %lf , &potter.x, &potter.y, &potter.z);     if ((abs(point[0].x - potter.x) < 1e-10) &&         (abs(point[0].y - potter.y) < 1e-10) &&         (abs(point[0].z - potter.z) < 1e-10)) {       printf( YES n );       printf( 0 n );       printf( %lf %lf %lf n , potter.x, potter.y, potter.z);       return 0;     }     for (int i = 0; i < n; i++) {       len[i] = getDist(point[i], point[i + 1]);       if (i == 0)         sum[i] = 0;       else         sum[i] = sum[i - 1] + len[i - 1];     }     bool isFound = false;     for (int i = 0; i < n; i++) {       Point vec;       vec.x = point[i + 1].x - point[i].x;       vec.y = point[i + 1].y - point[i].y;       vec.z = point[i + 1].z - point[i].z;       double startRatio = sum[i] / len[i];       Point start;       start.x = point[i].x - startRatio * vec.x;       start.y = point[i].y - startRatio * vec.y;       start.z = point[i].z - startRatio * vec.z;       Point unit;       unit.x = vec.x / len[i];       unit.y = vec.y / len[i];       unit.z = vec.z / len[i];       double s = 0, e = 1, mid;       for (int q = 0; q < 40; q++) {         mid = (s + e) / 2;         Point tar;         tar.x = point[i].x + vec.x * mid;         tar.y = point[i].y + vec.y * mid;         tar.z = point[i].z + vec.z * mid;         double dist = getDist(tar, potter);         double reqTime = dist / vp;         Point snitch;         snitch.x = start.x + unit.x * vs * reqTime;         snitch.y = start.y + unit.y * vs * reqTime;         snitch.z = start.z + unit.z * vs * reqTime;         Point gap;         gap.x = snitch.x - point[i].x;         gap.y = snitch.y - point[i].y;         gap.z = snitch.z - point[i].z;         double gapConst = getGapConst(gap, vec);         if ((abs(mid - gapConst) < 1e-10)) {           isFound = true;           printf( YES n );           printf( %.10lf n , reqTime);           printf( %.10lf %.10lf %.10lf n , tar.x, tar.y, tar.z);           break;         } else if (mid > gapConst)           e = mid;         else           s = mid;       }       if (isFound) break;     }     if (!isFound) printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     unsigned long long ans = 0;     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  0 ;       if (x % 4 == 0) ans++;       if (i > 0) {         x += 10 * (s[i - 1] -  0 );         if (x % 4 == 0) ans += i;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k;     cin >> n >> k;     string s, s1;     cin >> s;     if (k == 0) {       cout << s;     } else if (n == 1) {       cout << 0 <<   n ;     } else {       if (s[0] !=  1 ) {         k--;       }       s1.push_back( 1 );       int i = 1;       while (k && i < n) {         if (s[i] !=  0 ) k--;         s1.push_back( 0 );         i++;       }       for (; i < n; i++) {         s1.push_back(s[i]);       }       cout << s1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define f(i,n) for(int i=0;i<n;i++)   #define endl (  n )   #define pb push_back   #define mp make_pair   #define pl pair<ll, ll>   #define vl vector<ll>   #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);      #define M 1000000007    const int N=2e5+2;    ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}   ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}   ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}   vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}   ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}   ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}   ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}   ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m      int fact[N];              void precalc(){               fact[0]=1;               for(int i=1;i<N;i++){                   fact[i]=mod_mul(fact[i-1],i,M);               }           }    long long mod(long long x){               return ((x%M + M)%M);           }           ll inv(ll x){               return expo(x,M-2,M);           }              ll divide(ll a, ll b){               return mod_mul(a,inv(b),M);           }              ll nCr(ll n, ll r){               return divide(fact[n],mod_mul(fact[r],fact[n-r],M));           }          int main()   {       fastIO     ll t;     cin>>t;     while(t--){    ll n; cin >> n;           ll arr[n], sum = 0;           for(auto &i : arr) cin >> i, sum += i;               ll cnt = sum - (sum / n * n);           cout << cnt * (n - cnt) << endl;                   }               }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 3;   const double EPS = (1e-7);   int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, v;     cin >> n >> m >> v;     int maxcon = ((n - 1) * (n - 2)) / 2 + 1;     if (m > maxcon or m < n - 1) {       cout << -1 << endl;     } else {       for (int i = 1; i <= n; i++) {         if (i != v) {           cout << i <<     << v <<    n ;           m--;         }       }       int pr = 1;       if (pr == v) {         pr++;       }       for (int i = 1; i <= n and m; i++) {         if (i != v and i != pr) {           for (int j = i + 1; j <= n and m; j++) {             if (j != v and j != pr) {               cout << i <<     << j << endl;               m--;             }           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 3e5;   int n;   int a[maxN];   int diff[maxN];   int ans[maxN];   vector<int> pos[maxN];   int main() {     int t;     while (scanf( %d , &t) != EOF)       for (int tt = 1; tt <= t; tt++) {         scanf( %d , &n);         for (int i = 0; i < n; i++) pos[i].clear();         for (int i = 0; i < n; i++) {           scanf( %d , &a[i]);           a[i]--;           pos[a[i]].push_back(i);         }         for (int i = 0; i < n; i++) diff[i] = -1;         for (int i = 0; i < n; i++)           if (!pos[i].empty()) {             diff[i] = max(*pos[i].begin(), n - 1 - *pos[i].rbegin());             for (int j = 0; j < pos[i].size() - 1; j++)               diff[i] = max(diff[i], pos[i][j + 1] - pos[i][j] - 1);           }         for (int i = 0; i < n; i++) ans[i] = -1;         for (int i = n - 1; i >= 0; i--)           if (diff[i] != -1) ans[diff[i]] = i + 1;         for (int i = 0; i < n; i++)           if (ans[i] != -1) {             int j = i;             while (j + 1 < n && (ans[j + 1] >= ans[i] || ans[j + 1] == -1))               ans[++j] = ans[i];             i = j;           }         for (int i = 0; i < n; i++)           printf( %d%c , ans[i], i < n - 1 ?     :   n );       }     return 0;   }