Problem:
Minimum MAW
A contiguous substring of a string $S$ is a sequence of characters of length zero or more removed from the beginning and the end of $S$, respectively (except for all the characters of $S$ that have been removed). For example, the string abc has six consecutive substrings: a, ab, abc, b, bc, c.
Given a string $S$ and $T$, if $T$ satisfies the following conditions, then $T$ is said to be a minimal absent word (hereafter written as MAW) of $S$.
$T$ is at least two in length.
$T$ is not a continuous substring of $S$.
Any continuous substring of $T$ that is not a $T$ is a continuous substring of $S$.
For example, if the string $S$ is aabb, then the MAW of $S$ is the string aaa, ba, bbb.
The string is given. Write a program to find the smallest string in the MAW of that string in lexicographic order (the order in which words are arranged in an English-Japanese dictionary).
Input
The input is given in the following form.
$N$
$str$
The first line is the length of the string $N$ ($3 \leq N \leq 400,000$), and the second line is a string of length $N$ consisting of lowercase letters.
Output
Output the smallest MAW in lexical order in a line.
Sample Input and Output
Sample Input 1
4
aabb
Sample Output 1
aaa
Sample Input 2
4
tree
Sample Output 2
eee

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int N;cin >> N;
	string S;cin >> S;
	int mn = 28;
	for (int i = 0;i < N;i++) mn = min(mn, S[i]-'a');
	int it = 0;
	int mx = 0;
	char mm = 'a';
	mm += mn;
	while (it < N) {
		
		if (S[it] == mm) {
			int cnt = 0;
			for (int i = it;it < N;i++) {
				if (S[i] == mm) {
					cnt++;
				} else {
					it = i + 1;
					break;
				}
			}
			mx = max(mx, cnt);
		} else {
			it++;
		}
	}
	for (int i = 0;i < mx+1;i++) cout << mm;
	cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3968
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int c=0,f=0,ii=0,mx=0,n,b[26]={};
    string s,a={"abcdefghijklmnopqrstuvwxyz"};
    cin>>n>>s;
    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            if(s[i]==a[j]){
                b[j]=1;
            }
        }
    }
    for(int i=0;i<26;i++){
        if(b[i]==1){
            ii=i;
            break;
        }
    }
    for(int i=0;i<n;i++){
        if(s[i]==a[ii])f=1;
        if(f==1&&s[i]==a[ii]){c++;if(mx<c)mx=c;}
        else{f=0;c=0;}
    }
    for(int i=0;i<mx;i++){
        cout<<a[ii];
    }
    cout<<a[ii]<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3736
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{

    ll f=0,c=0,mx=0,n,a[26]={},ii; string s,g={"abcdefghijklmnopqrstuvwxyz"};
    cin>>n>>s;
    for(int i=0;i<26;i++){
        for(int j=0;j<n;j++){
            if(s[j]==g[i])a[i]=1;
        }
    }
    for(int i=0;i<26;i++){
        if(a[i]==1){
            ii=i;
            break;
        }
    }
    for(int i=0;i<n;i++){
        if(g[ii]==s[i])f=1;
        if(f==1&&g[ii]==s[i]){
            c++;
            if(mx<c)mx=c;
        }
        else{f=0;c=0;}
    }
    for(int i=0;i<mx+1;i++){
        cout<<g[ii];
    }
    cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3748
final_rank: 5

code_snippet: #include<bits/stdc++.h>
#include <vector>
using namespace std;
typedef pair<int,int>P;
map<char,int>mp;
int main(void)
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int a,b;
	b=1;
	for(int i=0;i<s.size();i++){
		if(s[i]==s[i+1]) b++;
		else {
			if(mp[s[i]]<b) mp[s[i]]=b;
			b=1;
		}
	}
	for(char i='a';i<='z';i++){
		if(mp[i]>=1){
			a=mp[i];
			for(int j=0;j<=a;j++){
				cout<<i;
			}
			break;
		}
	}
	cout<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3764
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<pair<char,int>> a;
  for(int i = 0;i < n;i++){
    if(a.empty() || a.back().first != s[i]){
      a.push_back({s[i],-1});
    }else{
      a.back().second--;
    }
  }
  sort(a.begin(),a.end());
  for(int i = 0;i <= -a[0].second;i++){
    cout << a[0].first;
  }
  cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 8408
final_rank: 14

code_snippet: #include <bits/stdc++.h>
//
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define rreps(i ,a, n) for (ll i = (ll)(n)-1; i >=(ll) a; i--)
#define ALL(box) (box).begin(), (box).end()
#define all(box) (box).begin(), (box).end()
#define RALL(box) (box).rbegin(), (box).rend()
#define rall(box) (box).rbegin(), (box).rend()
ll inf=((1LL<<62)-(1LL<<31))/15;
ll sum = 0;
ll num = 0;
int pum = 0;
ll mum = 0;
int min1 = 1000000;
int max1 = 0;
ll min2 = inf;
ll max2 = -inf;
ll MOD1 = 1000000007;
ll MOD = 998244353;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0}; // 右、下、左、上
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// sort(box.rbegin(), box.rend());
// printf("%.7Lf", n);
// reverse(t.begin(), t.end());
// unique(box.begin(), box.end());
// auto It = lower_bound(ALL(box), n);以上 4
// auto It = upper_bound(ALL(box), n);含まない上 7
// cout << box.end() - It ; 末尾までの距離
// cout << It - a.begin() ; 先頭までの距離
// auto It =box.upper_bound( k);set,multiset
// pqueue < int, vector<int>, greater<int>> q;
// priority_queue<pii, vector<pii>, greater<pii>> pq;//小さい順
// segtree<ll, op, e> seg(N);
// lazy_segtree<S, op, e, F, mapping, composition, id> seg(N);
// box.erase(unique(all(box), box.end());
// st.erase(st.find(5));
ll zaatu(vector<ll>&A){map<ll,ll>m;for(auto&&x:A)m[x]=0;ll ret = 0;for(auto&&[key,val]:m)val=ret++;for(auto&&x:A)x=m[x];return ret;}
vector<pair<char, ll>> runLengthEncoding(string s) {
    ll n = s.length();

    vector<pair<char, ll>> res;
    char pre = s[0];
    ll cnt = 1;
    reps(i, 1, n) {
        if (pre != s[i]) {
            res.push_back({ pre, cnt });
            pre = s[i];
            cnt = 1;
        }
        else cnt++;
    }

    res.push_back({ pre, cnt });
    return res;
}
int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    auto box=runLengthEncoding(S);
    rep(i,box.size()){
        box[i].second*=-1;
    }
    sort(all(box));
    rep(i,box[0].second*-1+1){
    cout <<box[0].first;
    }
    cout<<endl;
    
}
accuracy: 1
time_ms: 10
memory_kb: 14092
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;


int main() {
//#ifndef ONLINE_JUDGE
//    freopen("Input.txt", "r", stdin);
//    freopen("Output.txt", "w", stdout);
//#endif
    int n ;
    cin >> n;
  string s;
  cin >> s ;
  map<char,int>mp;
  char st = s[0] ;
  int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if(s[i] == st){
            cnt++;
        }
        else {
            mp[st] = max((int)mp[st] , cnt);
            cnt = 1;
            st = s[i];
        }
    }
    mp[st] = max((int)mp[st] , cnt);
    string t;
    for (int i = 0; i <= mp.begin()->second ; ++i) {
        t += mp.begin()->first;
    }
    cout << t << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3880
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    string S;
    cin >> N >> S;
    // len[i] := a ~ z の S の最大の連続長
    vector<int> len(26);
    for(int i = 0; i < 26; i++){
        int l = 0;
        for(int j = 0; j < N; j++){
            if(S[j] == (char)(i + 'a')){
                l++;
            }else{
                l = 0;
            }
            len[i] = max(len[i], l);
        }
    }

    debug(len);
    for(int i = 0; i < 26; i++){
        if(len[i] == 0) continue;
        string ans = string(len[i] + 1, (char)(i + 'a'));
        cout << ans << '\n';
        return 0;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3988
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,b = -1;
    string s;
    cin >> n >> s;
    s += '1';
    set<string> st;
    
    for(int i = 0; i < n; i++){
        if(s[i] != s[i+1]){ 
            st.insert(s.substr(b+1,i-b)); 
            b = i;
        }
    }
    s = *st.begin();
    char c = s[0];
    vector<string> vec;
    for(auto ss : st) if(ss[0] == c) vec.push_back(ss);
    reverse(vec.begin(),vec.end());
    cout << vec[0] << vec[0][0] << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4740
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF INT64_MAX;
int main(void)
{
    int n,mx=-1,cnt=0;
    string s,t;
    cin>>n>>s;
    t=s;
    sort(t.begin(),t.end());
    for(int i=0;i<s.size();i++){
        if(s[i]==t[0]){
            cnt++;
        }
        else{
            mx=max(mx,cnt);
            cnt=0;
        }
    }
    mx=max(mx,cnt);
    for(int i=0;i<=mx;i++) cout<<t[0];
    cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3952
final_rank: 9

code_snippet: #include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define   int             long long int
#define   endl            '\n'
#define   mod             1000000007
#define   pb              push_back
#define   operation();    ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define   ff              first
#define   ss              second
#define   srt             sort(ar,ar+n)
#define   yes             cout<<"YES"<<endl;
#define   no              cout<<"NO"<<endl;
#define   cn              for(int i=0;i<n;i++) cin>>ar[i]
#define   df              cout<<"NOTICE"<<endl;
const int  inf=10e+15;
int ar[500009];
int  gcd(int  a,int  b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int vis[200001];
vector<int>vt;
pair<int,char>pr[500009];
int arr[200001];
set<int>st;

//vector<vector<int>>adj;
int32_t main()
{
    // operation();
    int tt;
     // cin>>tt;
     // for(int ii=1; ii<=tt; ii++)
    {
          string s;int n;
          cin>>n;
          cin>>s;
           char c;
             c= s[0];
             for(int i=1;i<n;i++)
             {
                 if(s[i]<c) c=s[i];
             }
             int mx = -1;
             int cnt =1;
          //   cout<<cnt<<endl;
        for(int i=0;i<n-1;i++)
        {
            if(s[i]==s[i+1]&& s[i]==c)
                cnt++;
                else
                {
                    mx=max(cnt,mx);
                    cnt =1;
                }
        }
        if(s[n-1]==s[n-2])
            mx= max(cnt,mx);
           // cout<<mx<<endl;
        for(int i=1;i<=mx+1;i++) cout<<c;
        cout<<endl;


    }

}
accuracy: 1
time_ms: 10
memory_kb: 5744
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF INT64_MAX;
int main(void)
{
    int n;
    string s,st;
    cin>>n>>s;
    st=s; 
    vector<bool> f(n+1,false);
    sort(st.begin(),st.end());
    char nxt=st[0];
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]==nxt) cnt++;
        else{
            f[cnt]=true;
            cnt=0;
        }
        f[cnt]=true;
    }
    f[cnt]=true;
    for(int i=1;i<=n;i++){
        if(f[i+1]==false){
            for(int j=0;j<i;j++) cout<<st[0];
            cout<<st[0]<<endl;
            return 0;
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3908
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define overload(a,b,c,d,...) d
#define rep1(a) for(ll _=0;_<a;++_)
#define rep2(i,a) for(ll i=0;i<a;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define eb emplace_back
#define pb push_back
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
template<typename T,typename U>inline bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>inline bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}
static constexpr ll inf=numeric_limits<ll>::max()/2;
int main(){
    ll n;cin>>n;
    string s;
    cin>>s;
    char mi='z';
    ll mx=0;
    rep(i,n){
        char c=s[i];
        ll l=i;
        while(s[i]==c){
            i++;
        }
        ll sz=i-l;
        if(mi>c){
            mi=c;
            mx=sz;
        }
        else if(mi==c&&mx<sz){
            mx=sz;
        }
        i--;
    }
    rep(i,mx+1)cout<<mi;
    cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3672
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n, k, u;
string s;
char t = 'z';

int main(){
    cin >> n >> s;
    
    for(int i = 0; i < s.size(); i++){
        if(t >= s[i]){
            if(t > s[i]){
                t = s[i];
                k = 1;
            }
            
            u = 1;
            
            while(i < s.size() && s[i] == t){
                u++;
                i++;
            }
            
            i--;
            k = max(k, u);
        }
    }
    
    for(int i = 0; i < k; i++)
        cout << t;
    cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3560
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()

int main() {
  int N; cin >> N;
  string S; cin >> S;
  vector<char> V(N);
  rep(i, N) V[i] = S[i];
  sort(V.begin(), V.end());
  int max_count = 0;
  int f = 0;
  rep(i, N) {
    int count = 0;
    if (S[i] != V[0]) continue;
    else f = 1;
    int j = 0;
    for (;; j++) {
      if (S[i + j] != V[0]) break;
      count++;
    }
    f = 0;
    i += j;
    max_count = max(max_count, count);
  }
    
  string T = "";
  rep(i, max_count + 1) {
    T += V[0];
  }
  cout << T << endl;

}
accuracy: 1
time_ms: 10
memory_kb: 4496
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main()
{
    int n; cin>>n;
    string s; cin>>s;
    char use='z';
    for(int i=0; i<n; i++)
    {
        if(use>s[i])
        {
            use=s[i];
        }
    }
    int ans=0;
    int now=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=use)now=0;
        else{
        now++;
        ans=max(now,ans);
        }
    }
    ans=max(now,ans);
    //cout<<ans<<endl;
    for(int i=0; i<ans+1; i++)
    {
        cout<<use;
    }
    cout<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3764
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
const long long INF = 1e17;
using P = pair<ll, ll>;
void solve() {
    ll N; cin >> N;
    string S; cin >> S;
    string T = S;
    sort(T.begin(), T.end());
    char ch = T[0];
    vector<ll>A(N, 0);
    if (S[0] == ch) A[0] = 1;
    for (ll i = 1; i < N; i++) {
        if (S[i] == ch) A[i] = A[i - 1] + 1;
        else A[i] = 0;
    }
    sort(A.begin(), A.end());
    for (ll i = 0; i <= A.back(); i++) {
        cout << ch;
    }
    cout << endl;
}   
int main() {
    ll T = 1; //cin >> T;
    while (T--) {
        solve();
    }
}
accuracy: 1
time_ms: 20
memory_kb: 7208
final_rank: 18

code_snippet: //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
#define accumulate you cannot use this word!
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> max_len;
    
    char c = s[0];
    int len = 1;
    max_len[c] = max(max_len[c], len);
    
    rep2(i, 1, n){
        if(s[i] == c){
            len++;
        }else{
            c = s[i];
            len = 1;
        }
        max_len[c] = max(max_len[c], len);
        assert(len >= 1);
    }
    
    for(auto [c0, len0]: max_len){
        if(len0 <= 0) continue;
        
        rep(_, len0 + 1) cout << c0;
        cout << endl;
        return 0;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3740
final_rank: 4

code_snippet: //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
#define accumulate you cannot use this word!
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> max_len;
    
    char c = s[0];
    int len = 1;
    max_len[c] = max(max_len[c], len);
    
    rep2(i, 1, n){
        if(s[i] == c){
            len++;
        }else{
            c = s[i];
            len = 1;
        }
        max_len[c] = max(max_len[c], len);
        assert(len >= 1);
    }
    
    char c0 = (*max_len.begin()).first;
    char len0 = (*max_len.begin()).second;
//    assert('a' <= c0 && c0 <= 'z');
    rep(_, len0 + 1) cout << c0;
    cout << endl;
}
accuracy: 0.96
time_ms: 10
memory_kb: 3744
final_rank: 19

code_snippet: //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
#define accumulate you cannot use this word!
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> max_len;
    
    char c = s[0];
    int len = 1;
    max_len[c] = max(max_len[c], len);
    assert(len >= 1);
    
    rep2(i, 1, n){
        if(s[i] == c){
            len++;
        }else{
            c = s[i];
            len = 1;
        }
        max_len[c] = max(max_len[c], len);
        assert(len >= 1);
    }
    
    char c0 = (*max_len.begin()).first;
    char len0 = (*max_len.begin()).second;
//    assert('a' <= c0 && c0 <= 'z');
    assert(len0 >= 1);
    rep(_, len0 + 1) cout << c0;
    cout << endl;
}
accuracy: 0.96
time_ms: 10
memory_kb: 3744
final_rank: 19