#include "iostream" using namespace std; char num[20]; int ans = 0; int box[4] = {}; int main() { cin >> num; for (int i = 0; num[i+2] != NULL; i++) { for (int j = i + 1; num[j+1] != NULL; j++) { if (num[i] != num[j]&&num[i]!='0') { for (int k = j + 1; num[k] != NULL; k++) { if (num[j] == num[k]) { box[0] = (num[i] - '0') * 100 + (num[j] - '0') * 10 + num[k] - '0'; if (ans < box[0])ans = box[0]; for (int l = i + 1; num[l + 2] != NULL; l++) { if (l!=i&&l!=j&&l!=k) { for (int m = l + 1; num[m + 1] != NULL; m++) { if (num[l] != num[m]&&m!=i&&m!=j&&m!=k&&num[l] != '0') { for (int n = m + 1; num[n] != NULL; n++) { if (num[m] == num[n] && n != i&&n != j&&n != k) { box[1] = box[0] + (num[l] - '0') * 100 + (num[m] - '0') * 10 + num[n] - '0'; if (ans < box[1])ans = box[1]; for (int o = l + 1; num[o + 2] != NULL; o++) { if (o!=i&&o!=j&&o!=k&&o!=l&&o!=m&&o!=n&&num[o] != '0') { for (int p = o + 1; num[p + 1] != NULL; p++) { if (num[o] != num[p]&& p != i&&p != j&&p != k&&p != l&&p != m&&p != n) { for (int q = p + 1; num[q] != NULL; q++) { if (num[p] == num[q]&& q != i&&q != j&&q != k&&q != l&&q != m&&q != n) { box[2] = box[1] + (num[o] - '0') * 100 + (num[p] - '0') * 10 + num[q] - '0'; if (ans < box[2])ans = box[2]; for (int r = o + 1; num[r + 2] != NULL; r++) { if (r != i&&r != j&&r != k&&r != l&&r != m&&r != n&&r != o&&r != p&&r != q&&num[r] != '0') { for (int s = r + 1; num[s+1] != NULL; s++) { if (num[r] != num[s]&& s != i&&s != j&&s != k&&s != l&&s != m&&s != n&&s != o&&s != p&&s != q) { for (int t = s + 1; num[t] != NULL; t++) { if (num[s] == num[t]&& t != i&&t != j&&t != k&&t != l&&t != m&&t != n&&t != o&&t != p&&t != q) { box[3] = box[2] + (num[r] - '0') * 100 + (num[s] - '0') * 10 + num[t] - '0'; if (ans < box[3])ans = box[3]; } } } } } } } } } } } } } } } } } } if (box[3] > ans)ans = box[3]; if (box[2] > ans)ans = box[2]; if (box[1] > ans)ans = box[1]; if (box[0] > ans)ans = box[0]; } } } } } cout << ans<<"\n"; return 0; }