malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<long long> v[10001];   long long n, ass1, ass2;   int main() {     v[1].push_back(1);     v[1].push_back(2);     v[2].push_back(1);     v[2].push_back(3);     v[3].push_back(2);     v[3].push_back(3);     cin >> n;     ass1 = ass2 = 3;     while (ass1 + ass2 <= n) {       v[1].push_back(ass2 + 1);       v[ass1 + 1].push_back(ass2 + 1);       for (int i = 2; i <= ass1; i++) {         v[i].push_back(ass2 + i);         v[ass1 + 1].push_back(ass2 + i);       }       ass2 += ass1;       ass1++;     }     cout << ass1 << endl;     for (int i = 1; i <= ass1; i++) {       for (int j = 0; j < v[i].size(); j++) {         if (j != 0) cout <<    ;         cout << v[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt = -1;   struct node {     bool op;     string val;     int op1, op2;     int type;     node() {       op = 0;       val =   ;       type = 0;     }   } m[5020];   map<string, int> ind;   inline int cti(char i) { return (int)(i -  0 ); }   vector<string> vct;   bool ansx[2020], ansm[2020];   int tb[5020];   int main() {     int n, mm;     string t, p;     cin >> n >> mm;     for (int i = 0; i < n; i++) {       cin >> t;       if (ind.find(t) == ind.end()) {         ind[t] = ++cnt;       }       cin >> p;       cin >> p;       if (p[0] ==  1  or p[0] ==  0 ) {         m[cnt].val = p;         continue;       }       m[cnt].op = 1;       if (p ==  ? )         m[cnt].op1 = -1;       else         m[cnt].op1 = ind[p];       cin >> p;       if (p[0] ==  O ) m[cnt].type = 1;       if (p[0] ==  A ) m[cnt].type = 2;       if (p[0] ==  X ) m[cnt].type = 3;       cin >> p;       if (p ==  ? )         m[cnt].op2 = -1;       else         m[cnt].op2 = ind[p];     }     int x0, x1, pic1, pic2;     for (int i = 0; i < mm; i++) {       x0 = x1 = 0;       for (int k = 0; k < n; k++) {         auto j = m[k];         if (j.op == 0) {           x0 += cti(j.val[i]);           tb[k] = cti(j.val[i]);         } else {           if (j.op1 == -1)             pic1 = 0;           else             pic1 = tb[j.op1];           if (j.op2 == -1)             pic2 = 0;           else             pic2 = tb[j.op2];           if (j.type == 1) {             x0 += pic1 | pic2;             tb[k] = pic1 | pic2;           } else if (j.type == 2) {             x0 += pic1 & pic2;             tb[k] = pic1 & pic2;           } else {             x0 += pic1 ^ pic2;             tb[k] = pic1 ^ pic2;           }         }       }       for (int k = 0; k < n; k++) {         auto j = m[k];         if (j.op == 0) {           x1 += cti(j.val[i]);           tb[k] = cti(j.val[i]);         } else {           if (j.op1 == -1)             pic1 = 1;           else             pic1 = tb[j.op1];           if (j.op2 == -1)             pic2 = 1;           else             pic2 = tb[j.op2];           if (j.type == 1) {             x1 += pic1 | pic2;             tb[k] = pic1 | pic2;           } else if (j.type == 2) {             x1 += pic1 & pic2;             tb[k] = pic1 & pic2;           } else {             x1 += pic1 ^ pic2;             tb[k] = pic1 ^ pic2;           }         }       }       if (x0 > x1) {         ansx[i] = 0;         ansm[i] = 1;       }       if (x0 == x1) {         ansx[i] = 0;         ansm[i] = 0;       }       if (x0 < x1) {         ansx[i] = 1;         ansm[i] = 0;       }     }     for (int i = 0; i < mm; i++) cout << ansm[i];     cout << endl;     for (int i = 0; i < mm; i++) cout << ansx[i];     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct T {     int ind;     int st;     int ds;     bool operator<(const T &one) const {       if (st != one.st) return st < one.st;       return ds < one.ds;     }   } gr;   gr grps[10000];   int n;   vector<int> mv;   int valid(int nt) {     int en = 0;     for (int i = 0; i < n; i++) {       if (i == nt) continue;       if (grps[i].st < en) return 0;       en = max(en, grps[i].ds);     }     return 1;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> grps[i].st;       cin >> grps[i].ds;       grps[i].ind = i + 1;     }     sort(grps, grps + n);     for (int i = 0; i < n; i++) {       if (valid(i) == 1) mv.push_back(grps[i].ind);     }     cout << mv.size() << endl;     sort(mv.begin(), mv.end());     for (int i = 0; i < mv.size(); i++) cout << mv[i] <<    ;     return 0;   }
#include<iostream>   #include<cstdlib>   #include<cstdio>   #include<cmath>   #include<iomanip>   #include<cstring>   #include<algorithm>   #include<ctime>   using namespace std;   const int MAXN=2010;   int read()   {    int kkk=0,x=1;    char c=getchar();    while((c< 0  || c> 9 ) && c!= - ) c=getchar();    if(c== - ) c=getchar(),x=-1;    while(c>= 0  && c<= 9 ) kkk=kkk*10+(c- 0 ),c=getchar();    return kkk*x;   }   int n,X[MAXN],Y[MAXN],tag[MAXN],father[MAXN],id[MAXN],cur,ans[MAXN*MAXN][2],ANS,dl[MAXN],h,t,pd[MAXN];   double Theta[MAXN];   int find(int k){return father[k]==k?k:father[k]=find(father[k]);}   void solve(int S)   {    h=t=0;    dl[++t]=S;    while(h!=t)    {     int u=dl[++h];     father[u]=S;     if(tag[u]==S) break;     dl[++t]=tag[u];    }    if(t==1) pd[S]=1;   }   bool cmp(int x,int y){return Theta[x]<Theta[y];}   int main()   {    n=read();    for(int i=1;i<=n;++i) X[i]=read(),Y[i]=read(),tag[i]=read();    for(int i=1;i<=n;++i) if(!father[i]) solve(i);    for(int i=1;i<=n;++i) if(!pd[i])    {     if(!cur) cur=i;     else if(X[i]<X[cur] || (X[i]==X[cur] && Y[i]<Y[cur])) cur=i;    }    for(int i=1;i<=n;++i) Theta[i]=atan2(Y[i]-Y[cur],X[i]-X[cur]);    for(int i=1;i<=n;++i) id[i]=i;    sort(id+1,id+n+1,cmp);    pd[cur]=1;    for(int i=1,las=0;i<=n;++i) if(!pd[id[i]])    {     if(las)     {      int alas=find(las),aid=find(id[i]);      if(alas!=aid)      {       father[alas]=aid;       ans[++ANS][0]=las;       ans[ANS][1]=id[i];       swap(tag[las],tag[id[i]]);      }     }     las=id[i];    }    while(tag[cur]!=cur)    {     ans[++ANS][0]=cur;     ans[ANS][1]=tag[cur];     swap(tag[cur],tag[tag[cur]]);    }    printf( %d n ,ANS);    for(int i=1;i<=ANS;++i) printf( %d %d n ,ans[i][0],ans[i][1]);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, fl = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch -  0 );     return x * fl;   }   const int NN = 500000 + 17;   void open() {     freopen( a.in ,  r , stdin);     freopen( a.out ,  w , stdout);   }   void OK() { printf( OK n ); }   int n, q;   int c[NN];   int ans[NN];   vector<pair<int, int> > e[NN];   pair<int, int> ep[NN];   struct Tree {     int fa[NN], dep[NN], d[NN], ll[NN], rr[NN], rev[NN];     int tim;     struct node {       int w[2];     } t[NN << 2];     int tag[NN << 2];     node merge(node a, node b) {       node c;       c.w[0] = max(a.w[0], b.w[0]);       c.w[1] = max(a.w[1], b.w[1]);       return c;     }     void set_tag(int rt) {       tag[rt] ^= 1;       swap(t[rt].w[0], t[rt].w[1]);     }     void psd(int rt) {       if (tag[rt]) {         set_tag(rt << 1);         set_tag(rt << 1 | 1);         tag[rt] = 0;       }     }     void build(int rt, int l, int r) {       if (l == r) {         t[rt].w[d[rev[l]]] = dep[rev[l]];         return;       }       int mid = (l + r) >> 1;       build(rt << 1, l, mid);       build(rt << 1 | 1, mid + 1, r);       t[rt] = merge(t[rt << 1], t[rt << 1 | 1]);     }     void flip(int rt, int l, int r, int ll, int rr) {       if (ll <= l && r <= rr) {         set_tag(rt);         return;       }       psd(rt);       int mid = (l + r) >> 1;       if (ll <= mid) flip(rt << 1, l, mid, ll, rr);       if (rr > mid) flip(rt << 1 | 1, mid + 1, r, ll, rr);       t[rt] = merge(t[rt << 1], t[rt << 1 | 1]);     }     void dfs(int x, int ff) {       fa[x] = ff;       dep[x] = dep[ff] + 1;       ll[x] = ++tim;       rev[tim] = x;       for (int i = 0, top = e[x].size(); i < top; i++) {         int y = e[x][i].first, z = e[x][i].second;         if (y != ff) {           d[y] = (d[x] + z) & 1;           dfs(y, x);         }       }       rr[x] = tim;     }     void work(int root) {       dfs(root, 0);       build(1, 1, n);       for (int i = 1; i <= q; i++) {         int x = ep[c[i]].first, y = ep[c[i]].second;         if (fa[x] == y) swap(x, y);         flip(1, 1, n, ll[y], rr[y]);         ans[i] = max(ans[i], t[1].w[0]);       }     }   } tx, ty;   int mx, pos, px, py;   void dfs(int x, int dep, int ff) {     if (dep > mx) mx = dep, pos = x;     for (int i = 0, top = e[x].size(); i < top; i++) {       int y = e[x][i].first;       if (y != ff) dfs(y, dep + 1, x);     }   }   void get_path() {     dfs(1, 0, 0);     px = pos;     mx = -1;     dfs(px, 0, 0);     py = pos;     tx.work(px);     ty.work(py);   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       int x = read(), y = read(), z = read();       e[x].push_back(make_pair(y, z));       e[y].push_back(make_pair(x, z));       ep[i] = make_pair(x, y);     }     q = read();     for (int i = 1; i <= q; i++) c[i] = read();     get_path();     for (int i = 1; i <= q; i++) {       ans[i]--;       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getDiff(int n, string s1, string s2) {     int cnt = 0;     for (int i = 0; i < n; i++) {       if (s1[i] != s2[i]) {         cnt++;       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     string temp = s;     for (int i = 0; i < n - 1; i++) {       if (i < n - 2) {         if (s[i] == s[i + 1] && s[i + 1] == s[i + 2] && s[i + 2] == s[i]) {           if (s[i] ==  R ) {             s[i + 1] =  G ;           } else if (s[i] ==  G ) {             s[i + 1] =  R ;           } else {             s[i + 1] =  R ;           }           continue;         }       }       if (s[i] == s[i + 1]) {         if (i == 0) {           if (s[i] ==  R ) {             s[i] =  G ;           } else if (s[i] ==  G ) {             s[i] =  R ;           } else {             s[i] =  R ;           }         } else {           if (s[i - 1] ==  R ) {             if (s[i] ==  B ) {               s[i] =  G ;             } else {               s[i] =  B ;             }           } else if (s[i - 1] ==  B ) {             if (s[i] ==  R ) {               s[i] =  G ;             } else {               s[i] =  R ;             }           } else {             if (s[i] ==  B ) {               s[i] =  R ;             } else {               s[i] =  B ;             }           }         }       }     }     int ans = getDiff(n, s, temp);     cout << ans <<   n ;     cout << s <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, l[1010], r[1010];   char a[1010];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     l[1] = 0;     for (int i = 1; i < n; i++) {       if (a[i] ==  R ) l[i + 1] = l[i] + 1;       if (a[i] ==  = ) l[i + 1] = l[i];       if (a[i] ==  L ) l[i + 1] = 0;     }     r[n] = 0;     for (int i = n - 1; i >= 1; i--) {       if (a[i] ==  L ) r[i] = r[i + 1] + 1;       if (a[i] ==  = ) r[i] = r[i + 1];       if (a[i] ==  R ) r[i] = 0;     }     for (int i = 1; i <= n; i++) cout << max(l[i], r[i]) + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 99;   complex<int> read() {     int x, y;     cin >> x >> y;     return complex<int>(x, y);   }   long double dist(complex<int> a, complex<int> b) {     return hypot(abs(a.real() - b.real()), abs(a.imag() - b.imag()));   }   complex<long double> conv(complex<int> a) {     return complex<long double>(a.real(), a.imag());   }   bool _90_deg(complex<int> a, complex<int> b, complex<int> c) {     return fabs(((conj(((conv(b)) - (conv(a)))) * (((conv(c)) - (conv(b)))))                      .real())) < 1e-9;   }   bool isSquare(vector<complex<int>> vec) {     sort(vec.begin(), vec.end(), [](complex<int> a, complex<int> b) {       if (a.real() == b.real()) return a.imag() < b.imag();       return a.real() < b.real();     });     long double len = dist(vec[0], vec[1]);     if (fabs(len) < 1e-9) return false;     vector<pair<int, int>> _ = {{0, 2}, {1, 3}, {2, 3}};     for (auto cur : _) {       auto __ = dist(vec[cur.first], vec[cur.second]);       if (fabs(len - dist(vec[cur.first], vec[cur.second])) > 1e-9) return false;     }     long double diag1 = dist(vec[1], vec[2]);     long double diag2 = dist(vec[0], vec[3]);     if (fabs(diag1 - diag2) > 1e-9) return false;     swap(vec[2], vec[3]);     for (int i = 0; i < 4; ++i) vec.push_back(vec[i]);     for (int i = 2; i < vec.size(); ++i) {       if (!_90_deg(vec[i - 2], vec[i - 1], vec[i])) {         return false;       }     }     return true;   }   vector<complex<int>> home;   int go(int i, vector<complex<int>> vec) {     if (i >= 4) {       return isSquare(vec) ? 0 : 1e9;     }     int ret = 1e9;     for (int j = 0; j < 4; ++j) {       ret = min(ret, go(i + 1, vec) + j);       vec[i] -= home[i];       complex<int> r(-vec[i].imag(), vec[i].real());       vec[i] = r + home[i];     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     home.resize(4);     int t;     cin >> t;     while (t--) {       vector<complex<int>> v(4);       for (int i = 0; i < 4; ++i) {         v[i] = read();         home[i] = read();       }       int ret = go(0, v);       cout << (ret > 1e8 ? -1 : ret) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   const int N = 5e3 + 10;   int n;   int t[N];   int cnt[N];   int res[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t[i];     }     for (int r = 1; r <= n; r++) {       memset(cnt, 0, sizeof(cnt));       int mxCnt = 0, val = -1;       for (int l = r; l >= 1; l--) {         cnt[t[l]]++;         if (cnt[t[l]] > mxCnt || (cnt[t[l]] == mxCnt && t[l] < val)) {           mxCnt = cnt[t[l]];           val = t[l];         }         res[val]++;       }     }     for (int i = 1; i <= n; i++) {       cout << res[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long freq[100005];   int32_t main() {     long long n;     cin >> n;     string s;     cin >> s;     sort(s.begin(), s.end());     reverse(s.begin(), s.end());     cout << s[0];     for (long long i = 1; i < n; i++) {       if (s[i] ==  0 ) cout << s[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int NMAX = 1e6;   struct eq {     int x, c;     bool operator<(const eq &aux) const { return x < aux.x; }   };   eq a[200005], b[200005];   stack<pair<int, int> > st;   void prec(int &n, eq a[]) {     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].x, &a[i].c);     sort(a + 1, a + n + 1);     st.push({a[1].x, a[1].c});     for (int i = 2; i <= n; ++i) {       while (!st.empty() && st.top().second >= a[i].c) st.pop();       st.push({a[i].x, a[i].c});     }     int sz = st.size();     n = sz;     while (!st.empty()) {       a[sz].x = st.top().first;       a[sz].c = st.top().second;       st.pop();       --sz;     }   }   struct monster {     int x, y, c;     bool operator<(const monster &aux) const { return x < aux.x; }   };   monster A[200005];   long long Arb[NMAX * 4 + 5], pref[NMAX * 4 + 5];   void update(int x, long long val, int st = 0, int dr = NMAX, int nod = 1) {     if (st == dr) {       Arb[nod] += val;       pref[nod] = Arb[nod];       return;     }     int mij = (st + dr) / 2;     if (x <= mij)       update(x, val, st, mij, nod * 2);     else       update(x, val, mij + 1, dr, nod * 2 + 1);     Arb[nod] = Arb[nod * 2] + Arb[nod * 2 + 1];     pref[nod] =         max(Arb[nod], max(pref[nod * 2], Arb[nod * 2] + pref[nod * 2 + 1]));   }   int n, m, p;   int main() {     scanf( %d%d%d , &n, &m, &p);     prec(n, a);     prec(m, b);     for (int i = 1; i <= m; ++i) update(b[i - 1].x, -b[i].c + b[i - 1].c);     update(b[m].x, -INF);     for (int i = 1; i <= p; ++i) scanf( %d%d%d , &A[i].x, &A[i].y, &A[i].c);     sort(A + 1, A + p + 1);     int j = 1;     long long Sol = -a[1].c - b[1].c;     for (int i = 1; i <= n; ++i) {       while (j <= p && A[j].x < a[i].x) {         update(A[j].y, A[j].c);         ++j;       }       Sol = max(Sol, pref[1] - a[i].c);     }     printf( %lld , Sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       ;       int a[n];       int b[n];       for (int i = 0; i < n; i++) {         cin >> a[i];         cin >> b[i];       }       reverse(b, b + n);       bool ans = 1;       for (int i = 0; i < n; i++) {         if (a[i] + b[i] > x) {           ans = 0;           break;         }       }       if (ans)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, a, s = 0, c = 0;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> a;       s += a;     }     for (long long int i = 1; i <= 5; i++) {       s += i;       if (s % (n + 1) != 1) c++;       s -= i;     }     cout << c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = mod * mod;   const long long d2 = (mod + 1) / 2;   const long double EPS = 1e-9;   const long double PI = acos(-1.0);   int ABS(int a) { return max(a, -a); }   long long ABS(long long a) { return max(a, -a); }   long double ABS(long double a) { return max(a, -a); }   int p[110000];   int main() {     int a;     scanf( %d , &a);     for (int i = 0; i < a; i++) scanf( %d , p + i);     std::sort(p, p + a);     long long sum = 0;     set<int> S;     for (int i = 0; i < a; i++) S.insert(p[i]);     for (int i = 0; i < a; i++) sum += p[i];     if (a == 1 || sum == 0) {       if (sum % 2 == 0)         printf( cslnb n );       else         printf( sjfnb n );       return 0;     }     bool dame = false;     int cnt = 0;     for (int i = 0; i < a - 1; i++) {       if (p[i] == p[i + 1]) {         cnt++;         if (p[i] == 0 || S.count(p[i] - 1)) dame = true;       }     }     if (cnt > 1) dame = true;     if (dame) {       printf( cslnb n );       return 0;     }     long long val = 0;     for (int i = 0; i < a; i++) {       val += p[i] - i;     }     if (val % 2 == 0)       printf( cslnb n );     else       printf( sjfnb n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(), cout.tie();     long long n, k;     cin >> n >> k;     long long a[n];     map<long long, long long> mp;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     sort(a, a + n);     int i = 0, j = n - 1;     long long mini = a[0], maxi = a[n - 1];     while (k && i < j) {       while (i + 1 < n && a[i] == a[i + 1]) i++;       while (j - 1 >= 0 && a[j] == a[j - 1]) j--;       if (i < j) {         long long x = mp[a[i]], y = mp[a[j]];         if (x < y) {           long long d = a[i + 1] - a[i];           long long mn = min(k / x, d);           if ((a[i] + mn) == a[i + 1]) {             mp[a[i + 1]] += mp[a[i]];             k -= (mn * mp[a[i]]);             mini = a[i + 1];             i++;           } else {             mini = a[i] + mn;             break;           }         } else {           long long d = a[j] - a[j - 1];           long long mn = min(k / y, d);           if ((a[j] - mn) == a[j - 1]) {             mp[a[j - 1]] += mp[a[j]];             k -= (mn * mp[a[j]]);             maxi = a[j - 1];             j--;           } else {             maxi = a[j] - mn;             break;           }         }       } else {         mini = a[i], maxi = a[i];       }     }     cout << maxi - mini << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   string s;   int pows[4] = {0, 0, 0, 0};   void Desc(int q) {     if (q <= 1) return;     switch (q) {       case 2:         pows[0]--;         break;       case 3:         pows[1]--;         break;       case 4:         pows[0] -= 2;         break;       case 5:         pows[2]--;         break;       case 6:         pows[0]--;         pows[1]--;         break;       case 7:         pows[3]--;         break;       case 8:         pows[0] -= 3;         break;       case 9:         pows[1] -= 2;         break;     }     Desc(q - 1);   }   void Proc(int q) {     if (q <= 1) return;     switch (q) {       case 2:         pows[0]++;         break;       case 3:         pows[1]++;         break;       case 4:         pows[0] += 2;         break;       case 5:         pows[2]++;         break;       case 6:         pows[0]++;         pows[1]++;         break;       case 7:         pows[3]++;         break;       case 8:         pows[0] += 3;         break;       case 9:         pows[1] += 2;         break;     }     Proc(q - 1);   }   int conv(int q) {     switch (q) {       case 0:         return 2;       case 1:         return 3;       case 2:         return 5;       case 3:         return 7;     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(20);     cin >> N;     cin >> s;     for (int i = 0; i < N; ++i) Proc(s[i] -  0 );     for (int i = 3; i >= 0; --i) {       while (pows[i] != 0) {         cout << conv(i);         Desc(conv(i));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> status(26);   vector<vector<int> > adjList(200000);   vector<string> names(100);   vector<int> ts;   vector<int> processing(26);   void dfs(int u, bool &valid) {     status[u] = 1;     processing[u] = true;     for (int j = 0; j < adjList[u].size(); j++) {       int v = adjList[u][j];       if (processing[v] == true) {         valid = false;         return;       }       if (status[v] == 0) {         dfs(v, valid);       }     }     processing[u] = false;     ts.push_back(u);   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> names[i];     }     for (int i = 0; i < 26; i++) {       status[i] = 0;       processing[i] = false;     }     for (int i = 0; i < n - 1; i++) {       int c1 = -1;       int c2 = -1;       for (int j = 0; j < names[i].size() && j < names[i + 1].size(); j++) {         if (names[i][j] != names[i + 1][j]) {           c1 = names[i][j];           c2 = names[i + 1][j];           adjList[(c1 -  a )].push_back(c2 -  a );           break;         }       }       if (c1 == -1 && c2 == -1 && names[i].size() > names[i + 1].size()) {         cout <<  Impossible  << endl;         return 0;       }     }     for (int i = 0; i < 26; i++) {       if (status[i] == 0) {         bool valid = true;         dfs(i, valid);         if (!valid) {           cout <<  Impossible  << endl;           return 0;         }       }     }     for (int i = ts.size() - 1; i >= 0; i--) {       cout << (char)( a  + ts[i]);     }     cout << endl;     return 0;   }