#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; bool div(string& s, int d) { int res = 0; for (int i = 0; i < s.size(); i++) { res = res * 10 + (s[i] - '0'); res %= d; } return res == 0; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ string s; cin >> s; sort(s.begin(), s.end()); if (s[0] == s.back()) { cout << s << endl; return 0; } ll res = 1; if (div(s, 9)) res *= 9; else if (div(s, 3)) res *= 3; { bool ok = true; for (int i = 0; i < s.size(); i++) if ((s[i] - '0') % 2 == 1) ok = false; if (ok) res *= 2; } { bool ok = true; for (int i = 0; i < s.size(); i++) if ((s[i] - '0') % 4 != 0) ok = false; if (ok) res *= 2; } cout << res << endl; return 0; }