#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int i, j, k; string stn; //vectorlist(10, 0); vectorflag(1000, false); long sum = 0; cin >> stn; while (true) { //vector>list(10, vector(1, 0)); bool flag2 = false; char chw1, chw2, chc; vectorlist(10, -1); for (i = 0; i < stn.length(); i++) { //list[(int)stn[i] - 48]++; if (flag[i] == true)continue; if (list[(int)stn[i] - 48] == -1) { list[(int)stn[i] - 48] = i; } } int num; for (i = 9; i >= 1; i--) { if (list[i] >= 0) { num = i; vectorlist2(10, 0); vector>list3(10, vector(2)); for (j = list[i] + 1; j < stn.length(); j++) { if (flag[j] == true)continue; if (i == (int)stn[j] - 48)continue; if (list2[(int)stn[j] - 48] < 2) { list2[(int)stn[j] - 48]++; if (list2[(int)stn[j] - 48] == 1) { list3[(int)stn[j] - 48][0] = j; } else if (list2[(int)stn[j] - 48] == 2) { list3[(int)stn[j] - 48][1] = j; } } } for (j = 9; j >= 1; j--) { if (list2[j] >= 2) { chw1 = (char)j + 48; chw2 = (char)j + 48; chc = (char)num + 48; list2[j] -= 2; flag[list3[j][0]] = true; flag[list3[j][1]] = true; flag[list[i]] = true; string str = { chc,chw1,chw2 }; //cout << "str->" << str << endl; sum += stol(str); //cout << "sum->" << sum << endl; flag2 = true; break; } } if (flag2 == true)break; } } if (flag2 == false)break; } cout << sum << endl; /* for (i = 0; i < stn.length(); i++) { list[(int)stn[i] - 48]++; } long long sum = 0; for (i = 9; i >= 1; i--) { char chw1, chw2, chc; if (list[i] >= 2) { chw1 = (char)list[i] + 48; chw2 = (char)list[i] + 48; list[i] -= 2; for (j = 9; j >= 1; j--) { if (list[i] >= 1) { chc = (char)list[i] + 48; list[i]--; string str={ch} } } } }*/ getchar(); getchar(); return 0; }