#include #include int dfs(const std::string& s) { int n = s.length(); int ret = 0; for (int k = 0; k < n; ++k) { for (int j = 0; j < k; ++j) { for (int i = 0; i < j; ++i) { if (s[i] == '0' || s[i] == s[j] || s[j] != s[k]) continue; int x = (s[i] - '0') * 100 + (s[j] - '0') * 10 + (s[k] - '0') * 1; std::string t; for (int l = 0; l < n; ++l) { if (l == i || l == j || l == k) continue; t.push_back(s[l]); } ret = std::max(ret, dfs(t) + x); } } } return ret; } void solve() { std::string s; std::cin >> s; std::cout << dfs(s) << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }