我是靠谱客的博主 迅速美女,最近开发中收集的这篇文章主要介绍A. Minimizing the String,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

ou are given a string ss consisting of nn lowercase Latin letters.

You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.

String s=s1s2…sns=s1s2…sn is lexicographically smaller than string t=t1t2…tmt=t1t2…tm if n<mn<m and s1=t1,s2=t2,…,sn=tns1=t1,s2=t2,…,sn=tn or n≥mn≥m and there exists a number pp such that p≤mp≤m and s1=t1,s2=t2,…,sp−1=tp−1s1=t1,s2=t2,…,sp−1=tp−1 and sp<tpsp<tp .

For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".

Input

The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105 ) — the length of ss .

The second line of the input contains exactly nn lowercase Latin letters — the string ss .

Output

Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string ss .

Examples

Input

3
aaa

Output

aa

Input

5
abcda

Output

abca

Note

In the first example you can remove any character of ss to obtain the string "aa".

In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{   
  int n;
  cin>>n;
	string s;
	cin>>s;
	int k;
	for(int t=0;t<n-1;t++)
	{
		if(s[t]>s[t+1])
		{
			k=t;
			break;
		}
	}
	for(int t=0;t<n;t++)
	{
		if(t==k)
		{
			continue;
		}
		cout<<s[t];
	}
    cout<<endl;
	return 0;
}

 

最后

以上就是迅速美女为你收集整理的A. Minimizing the String的全部内容,希望文章能够帮你解决A. Minimizing the String所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部