# hvi.cpp

Jan 28th, 2022
700
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <bits/stdc++.h>
2. using namespace std;
3.
4. #define int long long
5. #define vi vector<int>
6. #define vii vector<vi>
7. #define ii pair<int,int>
8. #define fi first
9. #define sc second
10. #define pb push_back
11. #define stoi stoll
12. #define popcnt __builtin_popcount
13. #define getbit(x, k) ((x >> k) & 1)
14. #define all(x) (x).begin(),(x).end()
15. #define rall(x) (x).rbegin(),(x).rend()
16. #define FOR(i,j,k) for(int i=j; i<(int)k; ++i)
17. #define look(a) cerr <<#a<<": "<<a<<endl;
18. #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
19.
20. void solve()
21. {
22.     vi a;
23.     int x;
24.     while (cin >> x) a.push_back(x);
25.     int k = a.back();
26.     a.pop_back();
27.     int n = a.size();
28.     vi b;
29.     FOR(i,1,n+1) b.push_back(i);
30.     vi c = b;
31.     // First line
32.     int t = 1;
33.     while (b != a){
34.         t++;
35.         next_permutation(all(b));
36.     }
37.     cout << t << '\n';
38.     // Second line
39.     FOR(i,1,k) next_permutation(all(c));
40.     for(auto&i:c) cout << i << ' ';
41. }
42.
43. signed main()
44. {
45.     cin.tie(0)->sync_with_stdio(0);
46.     freopen("in", "r", stdin);
47.     freopen("out", "w", stdout);
48.     int T = 1;
49.     // cin >> T;
50.     while (T--) {
51.         solve();
52.         cout << '\n';
53.     }
54.     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
55. }