malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int M = 100;   int cal(int t) { return (t >= 0 ? t : -t); }   int n, d, a[M + 5], x[M + 5], y[M + 5], dist[M + 5][M + 5];   int main() {     scanf( %d %d , &n, &d);     for (int i = 2; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         dist[i][j] =             (i == j ? 0 : cal(x[i] - x[j]) * d + cal(y[i] - y[j]) * d - a[j]);     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);     printf( %d , dist[1][n]);   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<string> s(n);     for (long long i = 0; i < n; i++) cin >> s[i];     vector<long long> g[n * n];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         if (i + 1 < n) g[i * n + j].push_back((i + 1) * n + j);         if (j + 1 < n) g[i * n + j].push_back(i * n + (j + 1));       }     vector<long long> kval(n * n);     vector<char> cval(n * n);     vector<char> cval2(n * n);     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         cval[i * n + j] = s[i][j];         cval2[i * n + j] = s[i][j];       }     kval[0] = k;     if (cval[0] !=  a  && kval[0]) {       cval[0] =  a ;       kval[0] -= 1;     }     string ans;     queue<long long> q;     ans += cval[0];     q.push(0);     while (q.size()) {       set<long long> tq;       long long maxkval = 0;       char mincval =  z ;       while (q.size()) {         long long x = q.front();         q.pop();         for (auto y : g[x]) {           tq.insert(y);           if (kval[x]) {             kval[y] = max(kval[y], kval[x] - (cval[y] !=  a ));             cval2[y] =  a ;           }           maxkval = max(maxkval, kval[y]);           mincval = min(mincval, cval2[y]);         }       }       ans += mincval;       for (auto v : tq)         if (cval2[v] == mincval) q.push(v);     }     cout << ans.substr(0, 2 * n - 1) <<   n ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using std::abs;   using std::cerr;   using std::cin;   using std::cout;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::string;   using std::swap;   using std::vector;   using ll = long long;   using uint = unsigned int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   void err(vector<string>::iterator it, T a) {     cerr << it->substr((*it)[0] ==    ) <<   =   << a <<   n ;   }   template <typename T, typename... Ts>   void err(vector<string>::iterator it, T a, Ts... as) {     cerr << it->substr((*it)[0] ==    ) <<   =   << a <<  ,  ;     err(++it, as...);   }   struct init {     init() {       cin.tie(0);       std::iostream::sync_with_stdio(0);       cout << std::fixed << std::setprecision(10);       cerr << std::fixed << std::setprecision(10);       srand(228);     }     ~init() {       cerr <<  Time elapsed:   << 1.0 * (double)clock() / CLOCKS_PER_SEC            <<  s. n ;     }   } init;   const int MAXN = 1e5 + 15;   const ll INF = 1e16;   ll a[MAXN][3];   ll dp[MAXN][3][2];   int main() {     int n;     cin >> n;     for (int i = 0; i <= n; ++i)       for (int j = 0; j < 3; ++j)         for (int k = 0; k < 2; ++k) dp[i][j][k] = -INF;     for (int i = 0; i < 3; ++i)       for (int j = 1; j <= n; ++j) cin >> a[j][i];     a[0][1] = a[0][2] = -INF;     dp[0][0][0] = 0;     for (int i = 1; i <= n; ++i) {       dp[i][0][0] =           max({dp[i - 1][0][0] + a[i][0], dp[i - 1][1][0] + a[i - 1][0] + a[i][0],                dp[i - 1][2][0] + a[i - 1][1] + a[i - 1][0] + a[i][0],                i > 1 ? dp[i - 1][2][1] + a[i - 1][1] + a[i - 2][1] + a[i - 2][0] +                            a[i - 1][0] + a[i][0]                      : -INF});       dp[i][0][1] = dp[i - 1][0][0] + a[i][0];       dp[i][1][0] =           max({dp[i - 1][0][0] + a[i - 1][1] + a[i][1], dp[i - 1][1][0] + a[i][1],                dp[i - 1][2][0] + a[i - 1][1] + a[i][1]});       dp[i][1][1] = -INF;       dp[i][2][0] =           max({dp[i - 1][0][0] + a[i - 1][1] + a[i - 1][2] + a[i][2],                dp[i - 1][1][0] + a[i - 1][2] + a[i][2], dp[i - 1][2][0] + a[i][2],                i > 1 ? dp[i - 1][0][1] + a[i - 1][1] + a[i - 2][1] + a[i - 2][2] +                            a[i - 1][2] + a[i][2]                      : -INF});       dp[i][2][1] = dp[i - 1][2][0] + a[i][2];       for (int j = 0; j < 3; ++j)         ;     }     ll ans =         max({dp[n][0][0] + a[n][1] + a[n][2], dp[n][1][0] + a[n][2], dp[n][2][0],              dp[n][0][1] + a[n][1] + a[n - 1][1] + a[n - 1][2] + a[n][2]});     cout << ans <<   n ;     return 0;   }
// Codeforces Round #720 (Div. 2)   // Problem link: https://codeforces.com/problemset/problem/1521/B   // Problem tags:         constructive algorithms    math    *1300              // CODE      #include <iostream>   #include <vector>   #include <limits.h>      using namespace std;      int main()    {      int t;      cin >> t;      while(t--)      {           int n;           cin >> n;                     vector<int> arr(n+1);           int min = INT_MAX, pos = -1;            for(int i = 1; i <= n; i++)           {               cin >> arr[i];               if(arr[i] < min)               {                  min = arr[i];                  pos = i;               }           }                     cout << n-1 <<   n ;                     int next = min+1;           for(int i = pos-1; i > 0; i--)           {               arr[i] = next;               cout << pos <<     << i <<     << min <<     << next <<   n ;                next++;           }           next = min+1;           for(int i = pos+1; i <= n; i++)           {               arr[i] = next;               cout << pos <<     << i <<     << min <<     << next <<   n ;                next++;           }                     // cout <<  array:  ;           // for(int i=1; i<=n; i++)           //     cout << arr[i] <<    ;           // cout <<   n ;      }            return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, i, s, a1, b1, m;     cin >> t;     while (t--) {       cin >> n >> m;       if (n < m) {         cout <<  0 n ;         continue;       }       if (n == m)         cout << n % 10 <<   n ;       else {         long long int a[10] = {}, b[11] = {};         for (i = 1; i <= 10; i++) {           a[i - 1] = (m * i) % 10;           b[i] += a[i - 1] + b[i - 1];         }         a1 = n / m;         b1 = a1 % 10;         a1 = a1 / 10;         s = a1 * b[10] + b[b1];         cout << s <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getInt();   int getNegInt();   int T, N;   int get_nearest(int p, int a, vector<vector<int> >& path,                   unordered_set<int>& me) {     if (me.find(a) != me.end()) return a;     for (auto b : path[a]) {       if (b == p) continue;       int tar = get_nearest(a, b, path, me);       if (tar != -1) return tar;     }     return -1;   }   int main(int argc, char** argv) {     int a, b, k1, k2;     T = getInt();     while (T--) {       unordered_set<int> me, he;       N = getInt();       vector<vector<int> > path(N + 1, vector<int>());       for (int i = 1; i < N; i++) {         scanf( %d%d , &a, &b);         path[a].push_back(b);         path[b].push_back(a);       }       k1 = getInt();       int start;       for (int i = 1; i <= k1; i++) {         a = getInt();         me.insert(a);       }       k2 = getInt();       for (int i = 1; i <= k2; i++) {         b = getInt();         start = b;         he.insert(b);       }       int ans = -1;       for (int i = 1; i <= 1; i++) {         cout <<  B   << start << endl;         fflush(stdout);         int index = getInt();         if (me.find(index) != me.end()) {           ans = index;           break;         }         int nearest = get_nearest(index, index, path, me);         cout <<  A   << nearest << endl;         fflush(stdout);         index = getInt();         if (he.find(index) != he.end()) {           ans = nearest;           break;         }       }       cout <<  C   << ans << endl;       fflush(stdout);     }     return 0;   }   int getInt() {     int ret = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) ret *= 10, ret += c -  0 , c = getchar();     return ret;   }   int getNegInt() {     int ret = 0, sign = 1;     char c = getchar();     while ((c <  0  && c !=  - ) || c >  9 ) c = getchar();     if (c ==  - ) sign = -1, c = getchar();     while (c >=  0  && c <=  9 ) ret *= 10, ret += c -  0 , c = getchar();     return ret * sign;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   bool valido;   vector<vector<long long>> adj;   long long d;   void dfs(long long u, long long p = 0) {     if (!valido) return;     for (long long v : adj[u])       if (v != p) dfs(v, u);     if (a[u] % d == 0) {       a[p]++;     } else {       a[u]++;       if (p == 0 || a[u] % d != 0) valido = 0;     }   }   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       a.resize(n + 1);       adj = vector<vector<long long>>(n + 1);       for (long long i = 0; i < n - 1; i++) {         long long a, b;         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       vector<long long> freq(n + 1);       freq[1] = 2;       for (long long i = 1; i < n - 1; i++) freq[1] = 2 * freq[1] % 998244353;       for (d = 2; d <= n - 1; d++) {         if ((n - 1) % d == 0) {           valido = 1;           fill(a.begin(), a.end(), 0);           dfs(1);           freq[d] = valido;         }       }       vector<long long> res(n + 1);       for (long long d = n; d >= 1; d--) {         res[d] = freq[d];         for (long long mult = 2 * d; mult <= n; mult += d) {           res[d] = res[d] - res[mult] + 998244353;           res[d] %= 998244353;         }       }       for (long long d = 1; d <= n; d++) {         cout << res[d] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> nums;       for (long long i = 0; i < n; i++) {         int num;         cin >> num;         nums.push_back(num);       }       sort(nums.begin(), nums.end());       long long c = 0;       for (int i = 0; i < n; i++) {         if (nums[i] == 0) {           nums[i] += 1;           c++;         }       }       long long sum = 0;       for (int i = 0; i < n; i++) {         sum += nums[i];       }       if (sum == 0) {         c++;       }       cout << c << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;     node() { l = r = -1; }   } p[30];   int vis[30], sum[1000005];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       int id = s[i] -  A ;       if (!vis[id]) {         p[id].l = p[id].r = i;         vis[id] = 1;       } else         p[id].r = i;     }     for (int i = 0; i < 26; i++) {       if (vis[i]) {         sum[p[i].l]++;         sum[p[i].r + 1]--;       }     }     int ans = sum[0];     if (ans > k) {       cout <<  YES ;       return 0;     }     for (int i = 1; i < n; i++) {       sum[i] = sum[i - 1] + sum[i];       if (sum[i] > k) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int arr[1000010], lazy[1000010 << 2];   string str;   struct data {     int n4, n7, n47, n74;     data() { n4 = n7 = n47 = n74 = 0; }   } tree[1000010 << 2];   void build(int node, int l, int r) {     if (l == r) {       tree[node].n4 = (arr[l] == 4);       tree[node].n7 = (arr[l] == 7);       tree[node].n47 = 1;       tree[node].n74 = 1;       return;     }     int mid = (l + r) >> 1;     build(node << 1, l, mid);     build(node << 1 | 1, mid + 1, r);     tree[node].n4 = tree[node << 1].n4 + tree[node << 1 | 1].n4;     tree[node].n7 = tree[node << 1].n7 + tree[node << 1 | 1].n7;     tree[node].n47 = max(max(tree[node << 1].n47 + tree[node << 1 | 1].n7,                              tree[node << 1].n4 + tree[node << 1 | 1].n47),                          tree[node << 1].n4 + tree[node << 1 | 1].n7);     tree[node].n74 = max(max(tree[node << 1].n7 + tree[node << 1 | 1].n74,                              tree[node << 1].n74 + tree[node << 1 | 1].n4),                          tree[node << 1].n7 + tree[node << 1 | 1].n4);   }   void propagate(int node) {     if (lazy[node]) {       lazy[node << 1] ^= 1, lazy[node << 1 | 1] ^= 1;       swap(tree[node << 1].n4, tree[node << 1].n7);       swap(tree[node << 1 | 1].n4, tree[node << 1 | 1].n7);       swap(tree[node << 1].n47, tree[node << 1].n74);       swap(tree[node << 1 | 1].n47, tree[node << 1 | 1].n74);     }     lazy[node] = 0;   }   void update(int node, int l, int r, int i, int j) {     if (r < i || l > j) return;     if (i <= l && r <= j) {       lazy[node] ^= 1;       swap(tree[node].n4, tree[node].n7);       swap(tree[node].n47, tree[node].n74);       return;     }     int mid = (l + r) >> 1;     propagate(node);     update(node << 1, l, mid, i, j);     update(node << 1 | 1, mid + 1, r, i, j);     tree[node].n4 = tree[node << 1].n4 + tree[node << 1 | 1].n4;     tree[node].n7 = tree[node << 1].n7 + tree[node << 1 | 1].n7;     tree[node].n47 = max(max(tree[node << 1].n47 + tree[node << 1 | 1].n7,                              tree[node << 1].n4 + tree[node << 1 | 1].n47),                          tree[node << 1].n4 + tree[node << 1 | 1].n7);     tree[node].n74 = max(max(tree[node << 1].n7 + tree[node << 1 | 1].n74,                              tree[node << 1].n74 + tree[node << 1 | 1].n4),                          tree[node << 1].n7 + tree[node << 1 | 1].n4);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; ++i) {       char c;       cin >> c;       arr[i + 1] = c -  0 ;     }     build(1, 1, n);     while (q--) {       cin >> str;       if (str ==  count ) {         cout << tree[1].n47 <<   n ;       } else {         int l, r;         cin >> l >> r;         update(1, 1, n, l, r);       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct FenwickTree {     int N;     vector<int> A;     FenwickTree(int N) : N(N), A(N) {}     int rsq(int b) {       int sum = 0;       for (; b; b -= (b & (-b))) sum += A[b];       return sum;     }     int rsq(int a, int b) { return rsq(b) - (a == 1000000000 ? 0 : rsq(a - 1)); }     void adjust(int k, int v) {       for (; k < A.size(); k += k & -k) A[k] += v;     }   };   int n, k, a, b, q;   int main() {     cin >> n >> k >> a >> b >> q;     FenwickTree bef(n + 5), aft(n + 5);     vector<int> befa(n + 1), afta(n + 1);     int i, j, k1;     for (int c = 0; c < q; c++) {       scanf( %d , &i);       if (i == 1) {         scanf( %d%d , &j, &k1);         int befk = min(k1 + befa[j], b);         int aftk = min(k1 + afta[j], a);         bef.adjust(j, befk - befa[j]);         befa[j] = befk;         aft.adjust(j, aftk - afta[j]);         afta[j] = aftk;       } else {         scanf( %d , &j);         printf( %d n , bef.rsq(1, j - 1) + aft.rsq(k + j, n));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, A = 1e5 + 2;   bool v[20][20];   long long dp[20][1 << 20];   int n, m, start = 0;   long long solve(int node, int mask) {     if (~dp[node][mask]) return dp[node][mask];     long long ret = 0;     if (v[node][start] && __builtin_popcount(mask) > 2) ret++;     for (int i = start + 1; i < n; i++) {       if (!(mask >> i & 1) && v[node][i]) ret += solve(i, mask | (1 << i));     }     return dp[node][mask] = ret;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--, y--;       v[x][y] = v[y][x] = 1;     }     long long ans = 0;     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) start = i, ans += solve(i, 1 << i);     cout << ans / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int n, m, q, t, r, c, x;   int R[N], C[N], ans[N][N];   pair<int, pair<int, int> > arr[N][N], temp[N];   int main() {     cin >> n >> m >> q;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         arr[i][j].second.first = i;         arr[i][j].second.second = j;       }     while (q--) {       scanf( %d , &t);       if (t == 1) {         scanf( %d , &r);         r--;         for (int i = 0; i < m; i++) temp[(i - 1 + m) % m] = arr[r][i];         for (int i = 0; i < m; i++) arr[r][i] = temp[i];       }       if (t == 2) {         scanf( %d , &c);         c--;         for (int i = 0; i < n; i++) temp[(i - 1 + n) % n] = arr[i][c];         for (int i = 0; i < n; i++) arr[i][c] = temp[i];       }       if (t == 3) {         scanf( %d %d %d , &r, &c, &x);         r--;         c--;         arr[r][c].first = x;       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         ans[arr[i][j].second.first][arr[i][j].second.second] = arr[i][j].first;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) printf( %d  , ans[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 330, INF = 1000010000;   int n, m, u, x, y, z, I, ans;   int r[N], l[N], X[N], W[N], a[N], b[N], f[N], g[N][N], h[N][N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &X[i], &W[i]);       b[++m] = X[i], b[++m] = X[i] + W[i];       b[++m] = X[i] - W[i];     }     sort(b + 1, b + m + 1);     m = unique(b + 1, b + m + 1) - b - 1;     for (int i = 1; i <= n; i++) {       r[i] = lower_bound(b + 1, b + m + 1, X[i] + W[i]) - b;       l[i] = lower_bound(b + 1, b + m + 1, X[i] - W[i]) - b;       a[X[i] = lower_bound(b + 1, b + m + 1, X[i]) - b] = i;     }     for (int i = 1; i <= m; i++) {       int L = i;       for (int j = i; j <= m; j++) {         h[i][j] = L;         g[i][j] = L == i ? i : g[L][j];         if (a[j]) L = min(L, l[a[j]]);       }     }     for (int i = 1; i <= m; i++) {       f[i] = f[i - 1];       for (int j = 1; j <= i - 1; j++)         if (r[a[j]] >= i) {           if (j < i - 1 && h[j + 1][i] < j) {             int x = g[h[j + 1][i]][j];             f[i] = (f[i] > (f[x] + b[i] - b[x]) ? f[i] : (f[x] + b[i] - b[x]));           } else             f[i] = (f[i] > (f[j] + b[i] - b[j]) ? f[i] : (f[j] + b[i] - b[j]));         }       if (u = a[i - 1])         f[i] = (f[i] > (f[g[l[u]][i]] + b[i - 1] - b[g[l[u]][i]])                     ? f[i]                     : (f[g[l[u]][i]] + b[i - 1] - b[g[l[u]][i]]));     }     cout << f[m] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 1e5 + 10;   vector<int> v[N];   void init() {     int tot = 0;     for (int i = 1; i < N; i++) {       for (int j = i; j < N; j += i) {         v[j].push_back(i);       }       tot = max(tot, (int)v[i].size());     }   }   int C(int n, int m) {     int U = 1, D = 1;     while (m) {       U *= n++;       D *= m--;     }     return U / D;   }   void solve(int n) {     int ret = 0;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         ret++;       }     }     cout << n <<     << ret << endl;   }   int main() {     map<tuple<int, int, int>, int> mp;     for (int i = 1; i < 8; i++) {       if (((i >> 0) & 1) == 0) continue;       for (int j = 1; j < 8; j++) {         if (((j >> 1) & 1) == 0) continue;         for (int k = 1; k < 8; k++) {           if (((k >> 2) & 1) == 0) continue;           int a = i, b = j, c = k;           if (a > b) swap(a, b);           if (b > c) swap(b, c);           if (a > b) swap(a, b);           mp[{a, b, c}] = 1;         }       }     }     init();     int ncase;     scanf( %d , &ncase);     while (ncase--) {       map<int, int> mc;       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       vector<int> v1, v2;       merge(v[a].begin(), v[a].end(), v[b].begin(), v[b].end(),             back_inserter(v1));       merge(v[c].begin(), v[c].end(), v1.begin(), v1.end(), back_inserter(v2));       v2.erase(unique(v2.begin(), v2.end()), v2.end());       int sz[8];       memset((sz), (0), sizeof(sz));       for (auto &x : v2) {         int f = 0;         if (a % x == 0) f |= 1;         if (b % x == 0) f |= 2;         if (c % x == 0) f |= 4;         sz[f]++;       }       int ans = 0;       for (auto &t : mp) {         int a, b, c;         tie(a, b, c) = t.first;         if (a == c)           ans += C(sz[a], 3);         else if (a == b)           ans += C(sz[a], 2) * sz[c];         else if (b == c)           ans += C(sz[b], 2) * sz[a];         else           ans += sz[a] * sz[b] * sz[c];       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   int n, a[MAX], bk[3];   int ans[MAX];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], bk[a[i]]++;     sort(a + 1, a + n + 1, greater<int>());     int cur = 0, top = 0, tar;     for (int i = 1; i <= n; i++) {       cur += a[i];       bk[a[i]]--;       ans[++top] = a[i];       if (cur == 2) {         tar = i;         break;       }     }     if (bk[1] > 0) bk[1]--, cur += 1, ans[++top] = 1, n--;     for (int i = tar + 1; i <= n; i++) {       cur += a[i];       bk[a[i]]--;       ans[++top] = a[i];     }     for (int i = 1; i <= top; i++) printf( %d%c , ans[i], i == top ?   n  :    );     return 0;   }