// yukicoder: No.437 cwwゲーム // 2019.7.12 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了 { char *_s = s, c; do c = gc(), *s++ = c & 0xf; while (c > ' '); return s -_s - 1; } char N[15], w; int ans; int two[200][2], sz; void rec(int i, int j, int b, int s) { while (i < w-2) { while (j < sz && (two[j][0] <= i || N[i] == N[two[j][0]] || (b & two[j][1]))) j++; if (j < sz) { int bb = b | two[j][1], ss = s + N[i]*100 + N[two[j][0]]*11, ii = i+1; while (ii < w-2 && (N[ii] == 0 || (bb & (1< ans) ans = ss; j++; } else { i++, j = 0; while (i < w-2 && (N[i] == 0 || (b & (1<= w-2) { if (s > ans) ans = s; break; } } } } int main() { int i, j, k; w = ins(N); if (w >= 3) { for (j = 1; j < w; j++) for (k = j+1; k < w; k++) { if (N[k] == N[j]) two[sz][0] = j, two[sz++][1] = (1<