Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- using namespace std;
- #define ff first
- #define ss second
- #define int long long
- #define pb push_back
- #define mp make_pair
- #define pii pair<int,int>
- #define vi vector<int>
- #define mii map<int,int>
- #define pqb priority_queue<int>
- #define pqs priority_queue<int,vi,greater<int> >
- #define setbits(x) __builtin_popcountll(x)
- #define zrobits(x) __builtin_ctzll(x)
- #define mod 1000000007
- #define inf 1e18
- #define ps(x,y) fixed<<setprecision(y)<<x
- #define mk(arr,n,type) type *arr=new type[n];
- #define w(x) int x; cin>>x; while(x--)
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- #define fastio ios_base::sync_with_stdio(0); cin.tie(0);
- int32_t main()
- {
- fastio;
- int n;
- string s;
- cin>>s;n=s.length();
- if(n==1){cout<<"NO"<<endl;}
- int p=2,mx=1; char ch='a';
- vi hash(50,0);
- for(int i=0;i<n;i++) {
- hash[s[i]-'a']++;
- if(mx<=hash[s[i]]-'a'){
- mx=hash[s[i]-'a'];
- ch=s[i];
- }
- }
- if(mx<(n/p)){cout<<"NO"<<endl;return 0;}
- string ans(n,'a');
- for(int i=p;i<=n;i+=p) {ans[i-1]=ch;hash[ch-'a']--;}
- int j=0;
- for(int i=1;i<=n;i++)
- {
- if(i%p==0) continue;
- while(j<26 && hash[j]==0) j++;
- hash[j]--;
- char ch='a'+j;
- ans[i-1]=ch;
- }
- cout<<"YES"<<endl;
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment