#include #include #include #include #include #include using namespace std; // Function to add two strings representing numbers digit by digit and mod by 10 string f(const string& a, const string& b) { string c = ""; for (int i = 0; i < 6; ++i) { int x = (a[i] - '0') + (b[i] - '0'); x %= 10; c += to_string(x); } return c; } int main() { set L; vector K(6); // Read input strings for (int i = 0; i < 6; ++i) { cin >> K[i]; } vector dp(1000001, 0); deque S; // Initialize the deque with unique strings for (const string& s : K) { int x = 0; for (int i = 0; i < 6; ++i) { x += (s[5 - i] - '0') * pow(10, i); } if (dp[x] == 0) { dp[x] = 1; S.push_back(s); } } // Process the deque while (!S.empty()) { string h = S.back(); S.pop_back(); for (int i = 0; i < 6; ++i) { string s = K[i]; string b = f(h, s); int x = 0; for (int j = 0; j < 6; ++j) { x += (b[5 - j] - '0') * pow(10, j); } if (dp[x] == 0) { dp[x] = 1; S.push_back(b); } } } // Sum the dp array int result = 0; for (int i = 0; i < 1000000; ++i) { result += dp[i]; } cout << result << endl; return 0; }