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的更多相关文章

  1. Educational Codeforces Round 54 (Rated for Div. 2) Solution

    A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...

  2. Educational Codeforces Round 54 (Rated for Div. 2) ABCD

    A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...

  3. codeforces1076 A.B.C.D.E

    1076A 1076B 1076C 1076D 1076D A. Minimizing the String  You are given a string s consisting of n low ...

  4. CoderForces Round54 (A~E)

    ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字 ...

  5. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

  6. Codeforces Edu Round 54 A-E

    A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str ...

  7. Codeforces Round #598 (Div. 3) D. Binary String Minimizing 贪心

    D. Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of ...

  8. Codeforces Round #598 (Div. 3) D. Binary String Minimizing

    You are given a binary string of length nn (i. e. a string consisting of nn characters '0' and '1'). ...

  9. cf round 598div3 D.Binary String Minimizing

    题目:https://codeforces.com/contest/1256/problem/D 题意:给你长度为n的01串,能将任意两相邻字符交换k次,求最小字典序的交换结果. 思路:贪心...甚至 ...

随机推荐

  1. 7-EasyNetQ之Request & Response

    EasyNetQ也支持Request/Response这种方式的消息模式.这种方式很容易在client/Server应用中执行,客户端发送一个请求到服务器,服务器然后处理请求后返回一个响应.和传统的R ...

  2. close、flush、read、readline、seek、tell、truncate、write的使用

    1.close关闭文件 f1= open("ha.log","r+",encoding="utf-8") data = f1.read() ...

  3. KNN算法实现

    import csvimport randomimport mathimport operatorimport numpy as np def loadDataset(filename,split,t ...

  4. QGraphicsScene绘制网格背景

    博客转载自:https://blog.csdn.net/u010177010/article/details/51496038 //两条轴线QPolygonF myPolygon1; myPolygo ...

  5. backstop bsg6

  6. (数组)对数组中的数字加1(plus one)

    题目:https://www.nowcoder.com/practice/4d135ddb2e8649ddb59ee7ac079aa882?tpId=46&tqId=29111&tPa ...

  7. 监控linux系统的简易脚本

    我先把脚本粘贴在这吧,方便大家观看,其中也是借鉴了不少其他大神的东西,这个脚本主要是用来监控服务器.用户.日志,还得创建备份,等等等等.最近学的shell比较多,就用这个来练练手了,比较简单,大家凑合 ...

  8. C++笔记--函数

    函数的定义和声明 函数的声明和定义都必须描述相同的类型,但是声明可以不写参数名,定义则必须写参数名,但是他们的参数名字可以不同. 一个局部变量被声明为static,那么这个局部变量将只会被初始化一次, ...

  9. CodeForces 478D Red-Green Towers (DP)

    题意:给定 n 块红砖,m 块绿砖,问有多少种方式可以建造成最高的塔,每一层颜色必须一样. 析:首先要确定最高是多少层h,大约应该是用 h * (h+1) <= (m+n) * 2,然后dp[i ...

  10. Java分层概念(转)

    Java分层概念(转) 对于分层的概念,似乎之间简单的三层,多了,就有点难以区分了,所以收藏了这个. ervice是业务层 action层即作为控制器 DAO (Data Access Object) ...