description: Let's call a set of positive integers a_1, a_2, ..., a_k quadratic if the product of the factorials of its elements is a square of an integer, i. e. ∏_{i=1}^{k} a_i! = m^2, for some integer m.
  
  You are given a positive integer n.
  
  Your task is to find a quadratic subset of a set 1, 2, ..., n of maximum size. If there are multiple answers, print any of them.
  
  Input
  
  A single line contains a single integer n (1 ≤ n ≤ 10^6).
  
  Output
  
  In the first line, print a single integer — the size of the maximum subset. In the second line, print the subset itself in an arbitrary order.
  
  Examples
  
  Input
  
  
  1
  
  
  Output
  
  
  1
  1 
  
  
  Input
  
  
  4
  
  
  Output
  
  
  3
  1 3 4 
  
  
  Input
  
  
  7
  
  
  Output
  
  
  4
  1 4 5 6 
  
  
  Input
  
  
  9
  
  
  Output
  
  
  7
  1 2 4 5 6 7 9 
solution: #include <bits/stdc++.h>
  const int N = 1000005;
  int n, lp[N], in[N], u[N];
  unsigned long long pr[N], ex[N];
  std::set<std::pair<long long, int> > st;
  std::vector<int> p;
  std::mt19937_64 rng(
      std::chrono::steady_clock::now().time_since_epoch().count());
  int main() {
    scanf("%d", &n);
    memset(lp, -1, N << 2);
    for (int i = 2; i <= n; ++i) {
      if (lp[i] == -1) {
        pr[p.size()] = rng();
        lp[i] = p.size();
        p.push_back(i);
      }
      for (int j = 0; j < (int)p.size() && j <= lp[i] && p[j] * i < N; ++j)
        lp[p[j] * i] = j;
    }
    unsigned long long cur = 0, ov = 0;
    for (int i = 1; i <= n; ++i) {
      int val = i;
      while (val > 1) {
        int t = lp[val];
        do {
          cur ^= pr[t];
          val /= p[t];
        } while (!(val % p[t]));
      }
      st.insert(std::make_pair(cur, i));
      ov ^= cur;
      ex[i] = cur;
    }
    std::set<std::pair<long long, int> >::iterator it, it1;
    if (ov) {
      if ((it = st.lower_bound(std::make_pair(ov, 0))) != st.end() &&
          it->first == ov)
        u[it->second] = 1;
      else {
        bool ok = 0, fi = 0;
        int i = n;
        while (!ok) {
          if (fi) st.erase(std::make_pair(ex[i], i));
          for (it = st.begin(); it != st.end() && !ok; ++it) {
            it1 = st.lower_bound(
                std::make_pair(ov ^ it->first ^ (fi ? ex[i] : 0), 0));
            if (it1 == it) ++it1;
            if (it1 != st.end() &&
                it1->first == (ov ^ it->first ^ (fi ? ex[i] : 0))) {
              ok = 1;
              u[it->second] = 1;
              u[it1->second] = 1;
              if (fi) u[i] = 1;
            }
          }
          if (fi) st.insert(std::make_pair(ex[i], i));
          if (fi) --i;
          fi = 1;
        }
      }
    }
    int ans = n;
    for (int i = 1; i <= n; ++i) ans -= u[i];
    printf("%d\n", ans);
    for (int i = 1; i <= n; ++i)
      if (!u[i]) printf("%d ", i);
    printf("\n");
    return 0;
  }
  