#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mod 1000000007 int main() { string n; cin >> n; int count[10] = {}; int sum = 0; for(int i = 0; i < n.length(); i++){ int tmp = n[i] - '0'; count[tmp]++; sum += tmp; } int num = 0; for(int i = 0; i < 10; i++){ if(count[i] > 0) num++; } if(num == 1){ cout << n << endl; return 0; } int ans = 1; if(sum % 9 == 0) ans = ans * 9; else if(sum % 3 == 0) ans = ans * 3; bool isalleven = true; for(int i = 0; i < 5; i++){ if(count[2 * i + 1] > 0) isalleven = false; } if(isalleven){ if(count[2] == 0 && count[4] == 0 && count[6] == 0) ans = ans * 8; else if(count[2] == 0 && count[6] == 0) ans = ans * 4; else if(sum % 6 == 0) ans = ans * 6; else ans = ans * 2; } cout << ans << endl; return 0; }