#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); string a; cin >> a; const int n = a.size(); vector> cand; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { for (int k = j + 1; k < n; ++k) { if (a[i] != '0' && a[i] != a[j] && a[j] == a[k]) cand.push_back({ i, j, k }); } } } vector dp(1 << n, -1e18); queue q; dp[0] = 0; q.push(0); while (!q.empty()) { int bit = q.front(); q.pop(); for (auto [i, j, k] : cand) { if (bit & ((1 << i) | (1 << j) | (1 << k))) continue; int nbit = bit | (1 << i) | (1 << j) | (1 << k); ll nscore = dp[bit] + (a[i] - '0') * 100 + (a[j] - '0') * 10 + (a[k] - '0'); if (dp[nbit] < nscore) { dp[nbit] = nscore; q.push(nbit); } } } cout << *max_element(dp.begin(), dp.end()) << '\n'; return 0; }