#include using namespace std; int solve(vector a) { int n = a.size(); int res = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) continue; for (int j = i + 1; j < n; j++) { if (a[i] == a[j]) continue; for (int k = j + 1; k < n; k++) { if (a[j] != a[k]) continue; vector tmp; for (int idx = 0; idx < n; idx++) { if (idx == i || idx == j || idx == k) continue; tmp.push_back(a[idx]); } res = max(res, a[i] * 100 + a[j] * 10 + a[k] + solve(tmp)); } } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = s.length(); vector a(n); for (int i = 0; i < n; i++) a[i] = s[i] - '0'; cout << solve(a) << endl; return 0; }