Submission
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3574809#1
Code
#include<bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() ostream& operator<<(ostream& o, vector<ll> &A){ FOR(i, 0, A.size()){ if(i){ o << ' '; } o << A[i]; } o << endl; return o; } int main(){ ll N; cin >> N; vector<ll> A(N); FOR(i, 0, N){ cin >> A[i]; } auto B = A; auto C = A; if(prev_permutation(ALL(A))){ cout << A; } cout << B; if(next_permutation(ALL(C))){ cout << C; } return 0; }