#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; // graph const ll MAX_V = 1; const ll MAX_E = 1; struct edge { ll from, to, cost; }; edge ES[MAX_E]; vector G[MAX_V]; ll d[MAX_V]; ll prev_path[MAX_V]; ll V, E; const ll MOD = (ll) 1e9 + 7; const int MAX_INT = 1 << 17; vector prime; #define all(x) (x).begin(),(x).end() #define PRI(n) cout << n < C(r + 1); C[0] = 1; FOR(i, 1, n) for (ll j = min(i, r); j < 1; --j) C[j] = (C[j] + C[j - 1]); return C[r]; } template class SegTree { int n; vector data; T def; function operation; function update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: SegTree(size_t _n, T _def, function _operation, function _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; struct UnionFind { vector par; vector rank; UnionFind(int N) { for (int i = 0; i < N; ++i) { par.push_back(i); rank.push_back(0); } } int find(int x) { if (par[x] == x)return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (rank[x] < rank[y])par[x] = y; else { par[y] = x; if (rank[x] == rank[y])rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; void Bellman_short(int s) { REP(i, V)d[i] = 1LL << 50; d[s] = 0; REP(i, V)REP(i, E) { edge e = ES[i]; if (d[e.from] != 1LL << 50 && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; } } } bool Bellman_negLoop(int s) { REP(i, V)d[i] = 1LL << 50; d[s] = 0; REP(i, V)REP(j, E) { edge e = ES[j]; if (d[e.from] != 1LL << 50 && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == V - 1)return true; } } return false; } void dijkstra(int s) { typedef pair P; priority_queue, greater

> Q; fill(d, d + V, LLONG_MAX); fill(prev_path, prev_path + V, -1); d[s] = 0; Q.push(P(0, s)); while (!Q.empty()) { P p = Q.top(); Q.pop(); ll v = p.second; if (d[v] < p.first)continue; for (edge e:G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; Q.push(P(d[e.to], e.to)); prev_path[e.to] = v; } } } } vector getPath(int t) { vector path; for (; t != -1; t = prev_path[t]) { path.push_back(t); } reverse(all(path)); return path; } // //int A[100001]; // //bool dfs(ll x, int a) { // A[x] = a; // for (edge e : G[x]) { // if (e.cost % 2 == 0) { // if (A[e.to] == -a)return false; // if (A[e.to] == 0 && !dfs(e.to, a))return false; // } else { // if (A[e.to] == a)return false; // if (A[e.to] == 0 && !dfs(e.to, -a))return false; // } // } // return true; //} string s; bool a[15]; int dfs(int d) { int ans = 0; REP(i, s.size() - 2) { if (s[i] == '0')continue; FOR(j, i + 1, s.size() - 2) { if (s[i] == s[j])continue; FOR(k, j + 1, s.size() - 1) { if (s[j] != s[k]) continue; if (a[i] || a[j] || a[k])continue; a[i] = 1, a[j] = 1, a[k] = 1; int v = (s[i] - '0') * 100 + (s[j] - '0') * 10 + (s[k] - '0'); int x = dfs(v); ans = max(ans, x); a[i] = 0, a[j] = 0, a[k] = 0; } } } return ans + d; } int main() { cin >> s; PRI(dfs(0)) return 0; }