#include<bits/stdc++.h>
#define int long long
#define lbt(x) x&(-x)
using namespace std;
const int inf=0x3f3f3f3f3f3f3f3f,p=998244353;
void solve() {}
vector<int>a;
signed main() {
// freopen("text.in","r",stdin);
// freopen("text.out","w",stdout);
cin.tie(0)->sync_with_stdio(false);
cout.tie(0);
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
default_random_engine rng(seed);
int n;cin>>n;
for(int i=1;i<=n;++i) {
int x;cin>>x;
a.push_back(x);
}
while(prev_permutation(a.begin(),a.end())) {
shuffle(a.begin(),a.end(),rng);
}
next_permutation(a.begin(),a.end());
for(auto t:a)cout<<t<<" ";
return 0;
}当然,随机数生成我搜了一下