跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2794. Lexicographically Maximum Subsequence

  • ID: 2800
  • 传统题
  • 2000ms
  • 256MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:基础
  • 上传者:
  • 贪心
  • 字符串
  • 算法思想
  • 基础
  • 难度
  • 共享题库
  • Codeforces
  • 英文题面
  • 题目来源
  • 题面语言

Lexicographically Maximum Subsequence

题目描述

A. Lexicographically Maximum Subsequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.

We'll call a non-empty string s[p1p2... pk]=sp1sp2... spk(1≤p1<p2<...<pk≤|s|) a subsequence of string s=s1s2... s|s|.

String x=x1x2... x|x| is lexicographically larger than string y=y1y2... y|y|, if either |x|>|y| and x1=y1,x2=y2,... ,x|y|=y|y|, or exists such number r (r<|x|,r<|y|), that x1=y1,x2=y2,... ,xr=yr and xr+1>yr+1. Characters in lines are compared like their ASCII codes.

Input

The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.

Output

Print the lexicographically maximum subsequence of string s.

Examples
Input
ababba
Output
bbba
Input
abbcbccacbbcbaaba
Output
cccccbba
Note

Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).

The first sample: aBaBBA

The second sample: abbCbCCaCbbCBaaBA


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2464 题。保留原作者与原赛事署名。