#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- ll S[30]; string T; int L; vector V[26]; int num[26]; ll mo=1000003; ll rev[1010101]; ll modpow(ll a, ll n = mo-2) { ll r=1; while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1; return r; } struct comp { bool operator()(const pair,pair> a, const pair,pair> b) const { return a.first.first*b.first.second < a.first.second*b.first.first; } }; __int128 hoge(ll s,vector p) { if(p.empty()) return 1; sort(ALL(p)); ll a=1,b=1; priority_queue,pair>,vector,pair>>,comp> Q; FORR(r,p) s-=r, Q.push(make_pair(make_pair(r+1,1),make_pair(r,r))); int dif=0; while(s--) { auto r=Q.top(); Q.pop(); ll x=r.first.first; while(x%mo==0) { dif++; x/=mo; } x=r.first.second; while(x%mo==0) { dif--; x/=mo; } a = a*r.first.first%mo; b = b*r.first.second%mo; r.second.first++; Q.push(make_pair(make_pair(r.second.first+1,r.second.first+1-r.second.second),r.second)); } if(dif) return 0; return a*rev[b]%mo; } void solve() { int i,j,k,l,r,x,y; string s; for(i=1;i>S[i]; cin>>T; L=T.size(); V[T[0]-'a'].push_back(1); FOR(i,L-1) { if(T[i]==T[i+1]) V[T[i+1]-'a'].back()++; else V[T[i+1]-'a'].push_back(1); } FOR(i,L) num[T[i]-'a']++; __int128 ret=1; FOR(i,26) if(num[i]>S[i]) return _P("0\n"); FOR(i,26) (ret*=hoge(S[i],V[i]))%=mo; cout<<(ll)ret<