Language: C++

#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    string s; cin>>s;
    vector<ll> X(26,0);
    rep(i,sz(s)){
        X[(ll)(s[i]-'a')]++;
    }
    
    string t="";
    rrep(i,26){
        t+=('a'+i);
    }
    if(s==t){
        cout<<-1<<endl;
        return 0;
    }
    
    ll tmp=INF;
    rep(i,26){
        if(X[i]==0){
            tmp=i;
            break;
        }
    }
    
    //全文字
    if(tmp==INF){
        ll c;
        rrep1(i,sz(s)-1){
            if(s[i]>s[i-1]){
                c=i-1;
                break;
            }
        }
        rep(i,sz(s)){
            if(c==i){
                cout<<(char)(s[i]+1)<<endl;
                return 0;
            }
            else cout<<s[i];
        }
    }
    else{
        cout<<s<<(char)('a'+tmp)<<endl;
    }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:45:15: error: 'cin' was not declared in this scope
   45 |     string s; cin>>s;
      |               ^~~
a.cc:14:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
   13 | #include<utility>
  +++ |+#include <iostream>
   14 | using namespace std;
a.cc:56:9: error: 'cout' was not declared in this scope
   56 |         cout<<-1<<endl;
      |         ^~~~
a.cc:56:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:56:19: error: 'endl' was not declared in this scope
   56 |         cout<<-1<<endl;
      |                   ^~~~
a.cc:14:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
   13 | #include<utility>
  +++ |+#include <ostream>
   14 | using namespace std;
a.cc:79:17: error: 'cout' was not declared in this scope
   79 |                 cout<<(char)(s[i]+1)<<endl;
      |                 ^~~~
a.cc:79:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:79:39: error: 'endl' was not declared in this scope
   79 |                 cout<<(char)(s[i]+1)<<endl;
      |                                       ^~~~
a.cc:79:39: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:82:18: error: 'cout' was not declared in this scope
   82 |             else cout<<s[i];
      |                  ^~~~
a.cc:82:18: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:86:9: error: 'cout' was not declared in this scope
   86 |         cout<<s<<(char)('a'+tmp)<<endl;
      |         ^~~~
a.cc:86:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:86:35: error: 'endl' was not declared in this scope
   86 |         cout<<s<<(char)('a'+tmp)<<endl;
      |                                   ^~~~
a.cc:86:35: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'