fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define gc getchar_unlocked
  4. #define fo(i,n) for(i=0;i<n;i++)
  5. #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
  6. #define ll long long
  7. #define si(x) scanf("%d",&x)
  8. #define sl(x) scanf("%lld",&x)
  9. #define ss(s) scanf("%s",s)
  10. #define pi(x) printf("%d\n",x)
  11. #define pl(x) printf("%lld\n",x)
  12. #define ps(s) printf("%s\n",s)
  13. #define pb push_back
  14. #define mp make_pair
  15. #define F first
  16. #define S second
  17. #define all(x) x.begin(), x.end()
  18. #define clr(x) memset(x, 0, sizeof(x))
  19. #define sortall(x) sort(all(x))
  20. #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
  21. #define PI 3.1415926535897932384626
  22. typedef pair<int, int> pii;
  23. typedef pair<ll, ll> pl;
  24. typedef vector<int> vi;
  25. typedef vector<ll> vl;
  26. typedef vector<pii> vpii;
  27. typedef vector<pl> vpl;
  28. typedef vector<vi> vvi;
  29. typedef vector<vl> vvl;
  30. int mpow(int base, int exp);
  31. void ipgraph(int m);
  32. void dfs(int u, int par);
  33. const int mod = 1000000007;
  34. const int N = 3e5, M = N;
  35. //=======================
  36.  
  37. vi g[N];
  38. int a[N];
  39. deque<int> Q;
  40.  
  41. void go(ll x){
  42. if(x == 1) return;
  43. int now;
  44. if(x&1){
  45. go(x-1);
  46. now = Q.size() + 1;
  47. Q.push_front(now);
  48. }
  49. else{
  50. go(x/2);
  51. now = Q.size() + 1;
  52. Q.push_back(now);
  53. }
  54. }
  55. int main()
  56. {
  57. ios_base::sync_with_stdio(false);
  58. cin.tie(NULL);
  59. ll i,n,k,j;
  60. cin >> n;
  61. go(n+1);
  62. cout << Q.size() * 2 << endl;
  63. for(int x: Q) cout << x << " " ;
  64. int cnt = 1;
  65. while(cnt <= Q.size()) cout << cnt++ << " " ;
  66. cout << endl;
  67.  
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 24264KB
stdin
7
stdout
6
1 2 3 1 2 3