#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); set S; for(int i=0; i<6; i++){ string s; cin >> s; int x = stoi(s); S.insert(x); } vector already(1000000); already.at(0) = true; queue Q; Q.push(0); int answer = 0; while(Q.size()){ int pos = Q.front(); Q.pop(); answer++; for(auto s : S){ int x = pos,y = s; if(x+s >= 1000000) continue; if(already.at(x+s)) continue; bool ok = true; for(int k=0; k<6; k++){ int a = x%10,b = y%10; if(a+b >= 10){ok = false; break;} x /= 10,y /= 10; } if(ok) already.at(pos+s) = true,Q.push(pos+s); } } cout << answer << endl; }