#include using namespace std; bool is_made_of_one_digit(vector &freq){ int used = 0; for (auto f : freq) if (f > 0) ++used; return used == 1; } int check5(int num, const vector & freq){ return (num == freq[0] + freq[5])? 5 : 1; } int check7(int num, const vector & freq){ if(num == freq[0] + freq[7]){ return 7; }else if(num == freq[1] + freq[8]){ return (num % 6 == 0) ? 7 : 1; }else if(num == freq[2] + freq[9]){ return (num % 6 == 0) ? 7 : 1; }else{ return 1; } } int check2(int num, const vector & freq){ if (num == freq[0] + freq[8]){ return 8; }else if (num == freq[0] + freq[4] + freq[8]){ return 4; }else if (num == freq[0] + freq[2] + freq[4] + freq[6] + freq[8]){ return 2; }else{ return 1; } } int check3(int num, const vector & freq){ int sum = 0; for (int i = 0; i < 10; ++i) sum += i * freq[i]; if (sum % 9 == 0){ if (num == freq[0] + freq[9]){ if (freq[9] % 9 == 0){ return 81; }else if (freq[9] % 3 == 0){ return 27; }else{ return 9; } }else if (num == freq[0] + freq[3] + freq[6] + freq[9]){ return (sum % 27 == 0) ? 27 : 9; }else if (num == freq[1] + freq[4] + freq[7]){ return (num % 27 == 0 and sum % 27 == 0) ? 27 : 9; }else if (num == freq[2] + freq[5] + freq[8]){ return (num % 27 == 0 and sum % 27 == 0) ? 27 : 9; }else{ return 9; } }else if (sum % 3 == 0){ return 3; }else{ return 1; } } int solve(vector &freq){ int ans = 1; int num = accumulate(freq.begin(), freq.end(), 0); ans *= check2(num, freq); ans *= check5(num, freq); ans *= check7(num, freq); ans *= check3(num, freq); return ans; } int main(){ string N; cin >> N; vector freq(10, 0); for (auto n : N){ ++freq[n - '0']; } if (is_made_of_one_digit(freq)){ cout << N << endl; }else{ cout << solve(freq) << endl; } return 0; }