#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _MSC_VER #include #endif #define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define REV(v) v.rbegin(), v.rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end()) #define MP make_pair #define MT make_tuple using namespace std; typedef long long ll; typedef long double ld; typedef pair P; int mod_pow(long long x, long long n, long long p){ long long res = 1 % p; x %= p; while (n){ if (n & 1) res = res*x%p; x = x*x%p; n /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); string s; cin >> s; int cnt[256] = {}; for (auto c : s) cnt[c]++; int n = s.size(); const int m = 573; vector rem; vector pf = { 3, 191 }; for (int p : pf){ ll x = 1; rep(i, 256){ FOR(j, 1, cnt[i] + 1){ x *= j; x %= p; } } ll y = 1; FOR(i, 1, n + 1) y = y*i%p; int k = y * mod_pow(x, p - 2, p) % p; if (x == y) k = 1; rem.push_back(k); } rep(i, m){ if (i % pf[0] == rem[0] && i % pf[1] == rem[1]){ cout << (i+m-1)%m << endl; break; } } }