fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define endl '\n'
  6. ll N = 1e9+7;
  7. ll oo =1e13;
  8. const ll maxx = 1000000 + 3;
  9. ll n,m,k,q,x,y,z,l,r,mid,ans;
  10. stack<ll>a;
  11. stack<ll>b;
  12. stack<ll>c;
  13.  
  14. vector<pair<int,int>>out;
  15.  
  16. void go(ll n,ll a,ll b ,ll c) {
  17. if (n==0)return;
  18. go(n-1,a,c,b);
  19. out.push_back({a,c});
  20. go(n-1,b,a,c);
  21. }
  22. void solve() {
  23. cin>>n;
  24. go(n,1,2,3);
  25. cout<<out.size()<<endl;
  26. for (auto &i:out)cout<<i.first<<' '<<i.second<<endl;
  27. }
  28. int main() {
  29. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  30. ll t=1 ;
  31. // cin >>t;
  32. while (t--) {
  33. ans=0;
  34. solve();
  35. }
  36. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
stdout
7
1 3
1 2
3 2
1 3
2 1
2 3
1 3