#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int dp[1000][4400] = { 0 }; int main() { string s; cin >> s; int n = s.size(); vector> vec; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { if (s[j] == s[k] && s[i] != s[j]) { bitset<12> bit; bit[i] = 1; bit[j] = 1; bit[k] = 1; string s1 = ""; s1 += s[i]; s1 += s[j]; s1 += s[k]; int x = stoi(s1); vec.emplace_back(make_pair(bit.to_ulong(), x)); } } } } for (int i = 0; i < vec.size(); i++) { for (int j = 0; j < (1 << n); j++) { bool b = true; bitset<12> bit = vec[i].first, bit1 = j; for (int i = 0; i < 12; i++) { if (bit[i] == 1 && bit1[i] == 1) { b = false; } } if (b) { dp[i + 1][j | vec[i].first] = max(dp[i + 1][j | vec[i].first], dp[i][j] + vec[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } int ans = 0; for (int i = 0; i < (1 << n); i++) { if (ans < dp[vec.size()][i]) { ans = dp[vec.size()][i]; } } cout << ans << endl; }