malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 3123;   int n, m;   vector<tuple<int, int, int>> g[N];   vector<int> lpos, rpos;   bool vis[N];   bool dfs(int u, int l, int r) {     vis[u] = 1;     if (u == n) return 1;     bool ret = 0;     for (auto t : g[u]) {       int v, tl, tr;       tie(v, tl, tr) = t;       if (tl > l or tr < r or vis[v]) continue;       ret |= dfs(v, l, r);     }     return ret;   }   bool has_path(int l, int r) {     memset(vis, 0, sizeof vis);     return dfs(1, l, r);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, l, r;       cin >> a >> b >> l >> r;       g[a].emplace_back(b, l, r);       g[b].emplace_back(a, l, r);       lpos.emplace_back(l);       rpos.emplace_back(r);     }     sort(begin(lpos), end(lpos));     sort(begin(rpos), end(rpos));     lpos.resize(unique(begin(lpos), end(lpos)) - lpos.begin());     rpos.resize(unique(begin(rpos), end(rpos)) - rpos.begin());     int ans = 0;     for (int l : lpos) {       int lo = lower_bound(begin(rpos), end(rpos), l) - rpos.begin(),           hi = rpos.size();       while (lo < hi) {         int mi = (lo + hi) / 2;         if (has_path(l, rpos[mi]))           lo = mi + 1;         else           hi = mi;       }       if (lo - 1 >= 0) ans = max(ans, rpos[lo - 1] - l + 1);     }     if (ans == 0) {       cout <<  Nice work, Dima!  << endl;       return 0;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     string s;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  Tetrahedron ) {         sum += 4;       } else if (s ==  Cube ) {         sum += 6;       } else if (s ==  Octahedron ) {         sum += 8;       } else if (s ==  Dodecahedron ) {         sum += 12;       } else if (s ==  Icosahedron ) {         sum += 20;       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> start_years;   vector<long long> start_numbers;   vector<long long> mods;   void init() {     long long start = 1989;     start_years.resize(10);     start_numbers.resize(10);     mods.resize(10);     start_years[0] = start;     start_numbers[0] = 9;     mods[0] = 10;     long long p = 10;     for (int i = 1; i < 10; ++i) {       start_years[i] = start_years[i - 1] + p;       p *= 10;       start_numbers[i] = start_years[i] % p;       mods[i] = p;     }   }   long long solve(int i, long long num) {     long long pos = num - start_numbers[i] + mods[i];     pos %= mods[i];     return start_years[i] + pos;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     init();     int n = 0;     cin >> n;     for (int i = 0; i < (n); ++i) {       string str;       cin >> str;       int len = str.size() - 4;       stringstream ss(str.substr(4, len));       long long num;       ss >> num;       cout << solve(len - 1, num) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string com;     map<string, bool> mp;     int ans = 0;     while (getline(cin, com)) {       if (com[0] ==  + ) {         com.erase(com.begin(), com.begin() + 1);         mp[com] = 1;       } else if (com[0] ==  - ) {         com.erase(com.begin(), com.begin() + 1);         mp[com] = 0;       } else {         int len = com.size() - com.find( : ) - 1, cnt = 0;         for (map<string, bool>::iterator it = mp.begin(); it != mp.end(); it++) {           if (it->second) cnt++;         }         ans += cnt * len;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   namespace {   using namespace std;   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T>   bool space(vector<T>) {     return false;   }   template <typename T>   bool space(T) {     return true;   }   bool space(char) { return false; }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (const T &t : v) {       os << t << (space(t) ?     :   );     }     os <<   n ;     return os;   }   long long gcd(long long a, long long b) {     while (b) {       long long mod = a % b;       a = b;       b = mod;     }     return a;   }   template <typename T>   void incr_sort(vector<T> &v) {     stable_sort(v.begin(), v.end());   }   template <typename T>   void decr_sort(vector<T> &v) {     stable_sort(v.rbegin(), v.rend());   }   long long sum(const vector<int> &v) {     long long s = 0;     for (long long value : v) s += value;     return s;   }   vector<long long> prefix_sum(const vector<int> &v) {     vector<long long> res(v.size());     res[0] = v[0];     for (int i = 1; i < v.size(); ++i) res[i] = res[i - 1] + v[i];     return res;   }   }  // namespace   void solve();   int main() {     cin.tie(nullptr);     cout.tie(nullptr);     ios::sync_with_stdio(false);     int t = 1;     cin >> t;     for (int i = 0; i < t; ++i) solve();     return 0;   }   void solve() {     int h, n;     cin >> h >> n;     vector<int> p(n);     cin >> p;     p.push_back(0);     long long ans = 0;     int i = 0;     while (p[i] > 2) {       if (p[i + 1] < p[i] - 1) p[i] = p[i + 1] + 1;       if (p[i] <= 2) break;       if (p[i + 2] == p[i + 1] - 1)         i += 2;       else {         ++ans;         p[i + 1] = p[i + 2] + 1;         i++;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, v, k, cnt;   signed main() {     scanf( %lld%lld%lld , &n, &m, &v), k = (v == 1) ? 2 : 1;     if (m < n - 1 || m > n - 1 + (n - 2) * (n - 3) / 2) puts( -1 ), exit(0);     for (long long i = 1; i <= n; i++)       if (i != v) printf( %lld %lld n , i, v);     cnt = n - 1;     for (long long i = 1; i <= n; i++) {       if (i == v || i == k) continue;       for (long long j = i + 1; j <= n; j++) {         if (j == v || j == k) continue;         if (cnt + 1 <= m) cnt++, printf( %lld %lld n , i, j);         if (cnt == m) break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fac(long long n) {     long long m = 1;     for (long long i = 1; i <= n; i++) {       m = m * i;     }     return m;   }   long long gcd(long long x, long long y) {     if (x > y) swap(x, y);     long long md;     while (1) {       md = y % x;       if (md == 0) break;       y = x;       x = md;     }     return x;   }   long long nCr(long long n, long long r) {     long long rs = (fac(n)) / (fac(r) * fac(n - r));     return rs;   }   long long nPr(long long n, long long r) {     long long rs = fac(n) / fac(n - r);     return rs;   }   bool flag, fl;   long long i, j;   long long pw(long long n, long long p) {     long long mn = 1;     if (p == 0) return 1;     for (long long z = 0; z < p; z++) {       mn *= n;     }     return mn;   }   int main() {     long long n;     scanf( %lld , &n);     long long num = 0;     vector<int> bn;     long long rsl;     for (i = 1; i <= 1024; i++) {       bn.clear();       j = i;       num = 0;       while (j > 0) {         bn.push_back(j % 2);         j = j / 2;       }       long long ln = bn.size();       for (j = 0; j < ln; j++) {         num += (bn[j] * pw(10, j));       }       if (num <= n) {         rsl = i;       } else         break;     }     printf( %lld n , rsl);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = int(1e6) + 10;   int n;   char buffer[MAX_N];   int main() {     gets(buffer);     n = strlen(buffer);     reverse(buffer, buffer + n);     vector<pair<char, int> > v;     for (int i = 0, j, l = -1; i < n; i = j) {       for (j = i; j < n && buffer[j] ==  1 ; j++)         ;       if (j > i + 1) {         if (l == i) {           v.pop_back();         }         v.push_back(make_pair( - , i));         v.push_back(make_pair( + , j));         buffer[l = j--] =  1 ;       } else if (j == i + 1 && l != i) {         v.push_back(make_pair( + , i));       }       j++;     }     cout << (int)v.size() << endl;     for (__typeof((v).begin()) e = (v).begin(); e != (v).end(); ++e) {       printf( %c2^%d n , e->first, e->second);     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int N;     cin >> N;     string s1, s2;     cin >> s1 >> s2;     int num_different = 0;     vector<pair<bool, int>> differences;     int num_s1_has_a = 0;     int num_s1_has_b = 0;     for (int i = 0; i < N; ++i) {       if (s1[i] != s2[i]) {         bool s1_has_a = (s1[i] ==  a );         if (s1_has_a) {           ++num_s1_has_a;         } else {           ++num_s1_has_b;         }         differences.push_back({s1_has_a, i});       }     }     if ((num_s1_has_a + num_s1_has_b) % 2 != 0) {       cout << -1 << endl;       return;     } else {       sort(differences.begin(), differences.end());       int answer = (num_s1_has_a + num_s1_has_b) / 2;       if (num_s1_has_a % 2 != 0) {         ++answer;       }       cout << answer << endl;       for (int i = 0; i < differences.size(); i += 2) {         if (differences[i].first != differences[i + 1].first) {           cout << differences[i].second + 1 <<     << differences[i].second + 1                << endl;         }         cout << differences[i].second + 1 <<     << differences[i + 1].second + 1              << endl;       }     }   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<pair<int, int> > ans;     if (n == 1) {       if (m == 1) {         printf( 1 1 );         return 0;       }       for (int j = 0; j < m / 2; j++) {         printf( 1 %d n , j + 1);         printf( 1 %d n , m - (j + 1) + 1);       }       if (m % 2 != 0) {         printf( 1 %d , m / 2 + 1);       }       return 0;     }     for (int i = 0; i < n / 2; i++) {       for (int j = 0; j < m; j++) {         printf( %d %d n , i + 1, j + 1);         printf( %d %d n , n - i, m - j);       }     }     if (n % 2 != 0) {       if (m == 1) {         printf( %d %d n , n / 2 + 1, 1);         return 0;       }       for (int j = 0; j < m / 2; j++) {         printf( %d %d n , n / 2 + 1, j + 1);         printf( %d %d n , n / 2 + 1, m - j);       }       if (m % 2 != 0) {         printf( %d %d n , n / 2 + 1, m / 2 + 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {       srand(time(NULL));       if (1) {         ios_base::Init i;         cin.sync_with_stdio(0);         cin.tie(0);       }     }     ~__s() {       if (!1)         fprintf(stderr,  Execution time: %.3lf s. n ,                 (double)clock() / CLOCKS_PER_SEC);       int n;       cin >> n;     }   } __S;   struct vertex {     int go[26];     int link;     int ans;     int p;     int pch;     bool root;     bool isAns;     vertex(int p, int pch, bool root) : p(p), pch(pch), root(root) {       memset(go, 255, sizeof(go));       link = -1;       ans = 0;       isAns = false;     };   };   vector<vertex> t;   void add(string &s, int v) {     for (int i = 0; i < (int)(s.size()); i++) {       int c = s[i] -  a ;       if (t[v].go[c] == -1) {         t[v].go[c] = t.size();         t.push_back(vertex(v, c, false));       }       v = t[v].go[c];     }     t[v].ans++;   }   int getGo(int v, int c);   int getLink(int v) {     if (t[v].link == -1) {       if (t[t[v].p].root)         return t[v].link = t[v].p;       else         return t[v].link = getGo(getLink(t[v].p), t[v].pch);     }     return t[v].link;   }   int getGo(int v, int c) {     if (t[v].go[c] == -1) {       if (t[v].root)         return t[v].go[c] = v;       else         return t[v].go[c] = getGo(getLink(v), c);     }     return t[v].go[c];   }   int getAns(int v) {     if (t[v].isAns) return t[v].ans;     t[v].isAns = true;     return t[v].ans += getAns(getLink(v));   }   int getAns(string &s, int v) {     int res = 0;     for (int i = 0; i < (int)(s.size()); i++) {       int c = s[i] -  a ;       v = getGo(v, c);       res += getAns(v);     }     return res;   }   int n[2];   int root[2][20];   queue<string> p[2][20];   queue<string> q[2];   void build() {     for (int i = 0; i < (int)(2); i++) {       int N = n[i] + q[i].size();       for (int j = 0; j < (int)(20); j++) {         bool a = ((n[i] >> j) & 1);         bool b = ((N >> j) & 1);         if (a == b) continue;         if (a) {           root[i][j] = 0;           while (p[i][j].size()) {             q[i].push(p[i][j].front());             p[i][j].pop();           }           continue;         }         root[i][j] = t.size();         t.push_back(vertex(root[i][j], 0, true));         for (int k = 0; k < (int)(1LL << j); k++) {           add(q[i].front(), root[i][j]);           p[i][j].push(q[i].front());           q[i].pop();         }       }       n[i] = N;     }   }   int get(string &s, int i) {     int res = 0;     for (int j = 0; j < (int)(20); j++) {       if (root[i][j] == 0) continue;       res += getAns(s, root[i][j]);     }     return res;   }   int get(string &s) { return get(s, 0) - get(s, 1); }   int main(void) {     t.push_back(vertex(0, 0, false));     int n;     cin >> n;     for (int _ = 0; _ < (int)(n); _++) {       int t;       string s;       cin >> t >> s;       if (t == 1 || t == 2) {         q[t - 1].push(s);       } else {         build();         cout << get(s) <<   n ;         cout.flush();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int _ = 2e5 + 7;   const int __ = 8e5 + 7;   const long long inf = 1e17;   int n, m, q;   long long wgt[2][_], cst[_], minx[__], tag[__];   struct edge {     int x, y;     long long w;   } e[_];   void build(int k, int l, int r, bool id) {     tag[k] = 0;     if (l == r) {       if (!id) {         minx[k] = wgt[0][l] + cst[l];       } else         minx[k] = wgt[1][l];       return;     }     int mid = (l + r) >> 1;     build(k << 1, l, mid, id);     build(k << 1 | 1, mid + 1, r, id);     minx[k] = min(minx[k << 1], minx[k << 1 | 1]);   }   bool rule_x(edge a, edge b) { return a.x < b.x; }   void init() {     cin >> n >> m >> q;     n--;     for (int i = 1; i <= n; i++) scanf( %lld%lld , &wgt[0][i], &wgt[1][i]);     for (int i = 1; i <= m; i++) scanf( %d%d%lld , &e[i].x, &e[i].y, &e[i].w);     sort(e + 1, e + 1 + m, rule_x);     build(1, 0, n, 1);   }   void upd(int k, long long w) {     minx[k] += w;     tag[k] += w;   }   void psd(int k) {     if (!tag[k]) return;     upd(k << 1, tag[k]);     upd(k << 1 | 1, tag[k]);     tag[k] = 0;   }   void modify(int k, int l, int r, int x, int y, long long w) {     if (l >= x && r <= y) {       upd(k, w);       return;     }     psd(k);     int mid = (l + r) >> 1;     if (x <= mid) modify(k << 1, l, mid, x, y, w);     if (y > mid) modify(k << 1 | 1, mid + 1, r, x, y, w);     minx[k] = min(minx[k << 1], minx[k << 1 | 1]);   }   long long query(int k, int l, int r, int x, int y) {     if (l >= x && r <= y) return minx[k];     psd(k);     int mid = (l + r) >> 1;     long long t1 = inf, t2 = inf;     if (x <= mid) t1 = query(k << 1, l, mid, x, y);     if (y > mid) t2 = query(k << 1 | 1, mid + 1, r, x, y);     return min(t1, t2);   }   void pre() {     int p = 1;     for (int i = 1; i <= n + 1; i++) {       while (p <= m && e[p].x <= i) {         modify(1, 0, n, 0, e[p].y - 1, e[p].w);         p++;       }       if (i == n + 1)         cst[0] = query(1, 0, n, 0, n);       else         cst[i] = query(1, 0, n, 0, n);     }     build(1, 0, n, 0);   }   void run() {     printf( %lld n , query(1, 0, n, 0, n));     int x;     long long w;     for (int i = 1; i <= q; i++) {       scanf( %d%lld , &x, &w);       modify(1, 0, n, x, x, -wgt[0][x] + w);       wgt[0][x] = w;       printf( %lld n , query(1, 0, n, 0, n));     }   }   int main() {     init();     pre();     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void file_handling() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   void solve() {     string dish;     cin >> dish;     long long b, c, s;     b = s = c = 0;     for (long long i = 0; i < dish.size(); ++i)       if (dish[i] ==  B )         b++;       else if (dish[i] ==  S )         s++;       else         c++;     long long nb, nc, ns;     cin >> nb >> ns >> nc;     long long pb, pc, ps;     cin >> pb >> ps >> pc;     long long rubles;     cin >> rubles;     long long left = 0;     long long right = 1e15;     long long ans = 0;     while (left <= right) {       long long mid = (right + left) / 2;       long long cost = 0;       if (mid * b >= nb) cost += (mid * b - nb) * pb;       if (mid * c >= nc) cost += (mid * c - nc) * pc;       if (mid * s >= ns) cost += (mid * s - ns) * ps;       if (cost <= rubles) {         ans = mid;         left = mid + 1;       } else         right = mid - 1;     }     cout << ans <<   n ;   }   signed main() {     file_handling();     long long testCases = 1;     while (testCases--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int i, j, k, n, m, x;       cin >> n >> x >> k;       vector<long long int> a(n);       for (i = 0; i < n; i++) cin >> a[i];       sort(a.begin(), a.end());       long long int ans = 0;       for (i = 0; i < n; i++) {         long long int l = a[i] / x;         if (a[i] % x) {           ans += lower_bound(a.begin(), a.end(), x * (l + k + 1)) -                  lower_bound(a.begin(), a.end(), max((l + k) * x, a[i]));         } else {           ans += lower_bound(a.begin(), a.end(), (l + k) * x) -                  lower_bound(a.begin(), a.end(), max((l + k - 1) * x, a[i]));         }       }       cout << ans;     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   const int maxn=1e5+10;   int a[maxn],b[maxn],c[maxn];   vector<int> v1[maxn],v2[maxn],app[maxn];   int ans[maxn];   int main()   {    int t;    cin>>t;    while(t--)    {     memset(ans,-1,sizeof(ans));     int n,m;     cin>>n>>m;     for(int i=1;i<=n;i++)     {      v1[i].clear();      v2[i].clear();      app[i].clear();      cin>>a[i];     }     for(int i=1;i<=n;i++)     {      cin>>b[i];      if(a[i]!=b[i])      {       v1[b[i]].push_back(i);      }      else      {       app[a[i]].push_back(i);      }     }     for(int i=1;i<=m;i++)     {      cin>>c[i];      v2[c[i]].push_back(i);     }     bool flag=true;     for(int i=1;i<=n;i++)     {      if((int)v1[i].size()>(int)v2[i].size())      {       puts( NO );       flag=false;       break;      }      int pp=-1;      if(!v1[i].empty())      {       pp=v1[i].back();      }      for(int j=0;j<v2[i].size();j++)      {       if(v1[i].empty())       {        if(pp!=-1)        {         ans[v2[i][j]]=pp;        }        else if(!app[i].empty())        {         ans[v2[i][j]]=app[i].back();        }       }       else       {        ans[v2[i][j]]=v1[i].back();        v1[i].pop_back();       }      }     }     if(!flag)     {      continue;     }     if(ans[m]==-1)     {      puts( NO );      continue;     }     puts( YES );     for(int i=1;i<=m;i++)     {      if(ans[i]==-1)      {       ans[i]=ans[m];      }      cout<<ans[i]<<   ;     }     cout<<endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, step, smallest, count = 0;     bool possible = true;     cin >> n >> step;     vector<long long> p(n);     cin >> p[0];     smallest = p[0];     for (int i = 1; i < n; i++) {       cin >> p[i];       if (p[i] < smallest) {         smallest = p[i];       }     }     for (int i = 0; i < n; i++) {       if ((p[i] - smallest) % step != 0) {         cout << -1 << endl;         possible = false;         break;       } else {         count += (p[i] - smallest) / step;       }     }     if (possible == true) {       cout << count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long read1() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 200010;   const int P = 1e9 + 7;   int dp[110][110][110];   int pw[110];   int Add(int a, int b) {     a += b;     return a >= P ? a - P : a;   }   char ch[110];   int main() {     int n, x;     n = read();     x = read();     scanf( %s , ch + 1);     for (int i = 1; i <= n; i++) dp[ch[i] -  0 ][i][i] = 1;     pw[0] = pw[1] = 2;     for (int i = 2; i <= x; i++) {       pw[i] = (long long)(pw[i - 1]) * pw[i - 2] % P;       for (int l = 1; l <= n; l++)         for (int r = l; r <= n; r++) {           dp[i][l][r] =               Add((long long)(dp[i - 1][l][r]) * (r == n ? pw[i - 2] : 1) % P,                   (long long)(dp[i - 2][l][r]) * (l == 1 ? pw[i - 1] : 1) % P);           for (int m = l; m <= r - 1; m++)             dp[i][l][r] = Add(dp[i][l][r], (long long)(dp[i - 1][l][m]) *                                                dp[i - 2][m + 1][r] % P);         }     }     cout << dp[x][1][n] << endl;     return 0;   }
#include <bits/stdc++.h>   int n, sum, ans[6050];   bool isprime(int x) {     if (x < 2 || (x & 1) == 0) {       return 0;     }     for (int i = 2; i * i <= x; ++i) {       if (x % i == 0) {         return 0;       }     }     return 1;   }   int main() {     scanf( %d , &n);     sum = n * (n + 1) / 2;     if (isprime(sum)) {       for (int i = 1; i <= n; ++i) {         ans[i] = 1;       }     } else if ((sum & 1) == 0) {       for (int i = 3; i <= n; ++i) {         if (isprime(i) && isprime(sum - i)) {           ans[i] = 2;           break;         }       }       for (int i = 1; i <= n; ++i) {         if (!ans[i]) {           ans[i] = 1;         }       }     } else {       if (isprime(sum - 2)) {         for (int i = 1; i <= n; ++i) {           ans[i] = 1;         }         ans[2] = 2;       } else {         sum -= 3;         ans[3] = 3;         for (int i = 5; i <= n; ++i) {           if (isprime(i) && isprime(sum - i)) {             ans[i] = 2;             break;           }         }         for (int i = 1; i <= n; ++i) {           if (!ans[i]) {             ans[i] = 1;           }         }       }     }     for (int i = 1; i <= n; ++i) {       printf( %d  , ans[i]);     }     return 0;   }