#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define POWT(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODI 10000 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) using namespace std; typedef pair pii; typedef long long ll; int func(string str) { int ret = 0; int len = str.length(); REP(i, len) { rep(j, i + 1, len) { rep(k, j + 1, len) { if ((str[i] != str[j] )&& (str[j] == str[k])) { string ns(str); ns.erase(ns.begin() + k); ns.erase(ns.begin() + j); ns.erase(ns.begin() + i); int can = (str[i] - '0') * 100 + (str[j] - '0') * 10 + (str[k] - '0'); ret = max(ret, can + func(ns)); } } } } return ret; } signed main() { char str [13]; scanf("%s", str); int ans = func(str); printf("%d\n", ans); return 0; }