#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
using namespace std;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int N = 1e3 + 5, M = 1e2 + 2, K = 5e2 + 5;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
void fast()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
int id = 0;
string s, t, ans;
int dp[N][N], vis[N][N];
int lcs(int i, int j)
{
if (i == s.size() || j == t.size())
return 0;
int &ret = dp[i][j];
if (vis[i][j] == id)
return ret;
vis[i][j] = id, ret = 0;
if (s[i] == t[j])
return ret = 1 + lcs(i + 1, j + 1);
ret = max(ret, lcs(i + 1, j));
ret = max(ret, lcs(i, j + 1));
return ret;
}
void build(int i, int j)
{
if (i == s.size() || j == t.size())
return;
if (s[i] == t[j])
{
ans += s[i];
build(i + 1, j + 1);
return;
}
if (lcs(i + 1, j) == lcs(i, j + 1))
{
if (s[i] >= t[j])
build(i + 1, j);
else
build(i, j + 1);
return;
}
if (lcs(i + 1, j) > lcs(i, j + 1))
build(i + 1, j);
else
build(i, j + 1);
}
int32_t main()
{
fast();
while (cin >> s)
{
t = s, ans = "";
reverse(all(t));
id++;
int x = lcs(0, 0);
build(0, 0);
cout << ans << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCksIHguZW5kKCkKI2RlZmluZSByYWxsKHgpIHgucmJlZ2luKCksIHgucmVuZCgpCiNkZWZpbmUgc3ooeCkgKGludCkoeCkuc2l6ZSgpCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBkb3VibGUgcGkgPSBhY29z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ICAgaWYgKHNbaV0gPT0gdFtqXSkKICAgIHsKICAgICAgICBhbnMgKz0gc1tpXTsKICAgICAgICBidWlsZChpICsgMSwgaiArIDEpOwogICAgICAgIHJldHVybjsKICAgIH0KCiAgICBpZiAobGNzKGkgKyAxLCBqKSA9PSBsY3MoaSwgaiArIDEpKQogICAgewogICAgICAgIGlmIChzW2ldID49IHRbal0pCiAgICAgICAgICAgIGJ1aWxkKGkgKyAxLCBqKTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIGJ1aWxkKGksIGogKyAxKTsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgaWYgKGxjcyhpICsgMSwgaikgPiBsY3MoaSwgaiArIDEpKQogICAgICAgIGJ1aWxkKGkgKyAxLCBqKTsKICAgIGVsc2UKICAgICAgICBidWlsZChpLCBqICsgMSk7Cn0KCmludDMyX3QgbWFpbigpCnsKICAgIGZhc3QoKTsKCiAgICB3aGlsZSAoY2luID4+IHMpCiAgICB7CiAgICAgICAgdCA9IHMsIGFucyA9ICIiOwogICAgICAgIHJldmVyc2UoYWxsKHQpKTsKICAgICAgICBpZCsrOwogICAgICAgIGludCB4ID0gbGNzKDAsIDApOwogICAgICAgIGJ1aWxkKDAsIDApOwogICAgICAgIGNvdXQgPDwgYW5zIDw8ICJcbiI7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=