#include using namespace std; typedef unsigned long long ull; inline ull testn(vector &ns, ull b) { ull v = ns[0]; for (int i = 1; i < ns.size(); i++) { switch (b % 3) { case 0: v += ns[i]; break; case 1: v *= ns[i]; break; case 2: v *= pow(10, (int)log10(ns[i]) + 1); v += ns[i]; } b /= 3; } return v; } int main() { ios::sync_with_stdio(0); cin.tie(0); ull sum = 0; string line; while (getline(cin, line) && !line.empty()) { istringstream l(line); ull n; int a; vector ns; l >> n; l.ignore(); while (l >> a) { ns.push_back(a); } ull btot = pow(3, (ns.size() - 1)); for (ull b = 0; b <= btot; b++) { if (testn(ns, b) == n) { sum += n; break; } } } cout << sum << '\n'; }