#include using namespace std; template void chmax(T1 &a, T2 b) { if (a < b) a = b; } int main() { string s; cin >> s; int n = s.size(); vector dp(1 << n, -1e9); dp[0] = 0; for (int m = 0; m < 1 << n; m++) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { if (m & 1 << i) continue; if (m & 1 << j) continue; if (m & 1 << k) continue; if (s[i] != s[j] && s[j] == s[k] && s[i] != '0') { chmax(dp[m | 1 << i | 1 << j | 1 << k], dp[m] + (s[i] - '0') * 100 + (s[j] - '0') * 10 + (s[k] - '0')); } } } } } cout << *max_element(dp.begin(), dp.end()) << endl; }