/* #include void self::main(){ auto a=sinen_alphabet(); zip(a); ll N=a.size(); auto g=a.pos_groups(a.max()+1); use_ml1000000007 ml iv2=ml(2).inv(); vecs(N); fo(i,N)s[i]=iv2.pow(i); zeta(s); ml ans=0; fo(i,N)ans+=ml(2).pow(N+i-1)*(s[N-1]-s[i]); FenwickTreefw(N); fo(x,g.size()){ fe(g[x],i)fw.add(i,iv2.pow(i)); fe(g[x],i)ans-=ml(2).pow(N+i-1)*fw.sum(i+1,N); fe(g[x],i)fw.add(i,-iv2.pow(i)); } pp(ans+ml(2).pow(N)-1); } */ #include #include using namespace std; namespace self{void main();void sub();void pp(auto&&...a);void ppe(auto&&...a);} int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<(0,__VA_ARGS__);iconstexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} void lin(auto&...a){(cin>>...>>a);} auto encode_alphabet(char c){return c-'a';} templatestruct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} auto operator<=>(const pair&)const=default; }; templateusing pack_back_t=tuple_element_t>; } namespace self{ templateclass FenwickTree{ public: ll n_; vectordata_; FenwickTree(ll n):n_(n),data_(n){} void add(ll i,T x){ assert(0<=i&&i0)res+=data_[r-1],r-=r&-r; while(l>0)res-=data_[l-1],l-=l&-l; return res; } }; } namespace self{ templateconcept vectorial=is_base_of_v::value_type>,remove_cvref_t>; templateconstexpr int depth=0; templateconstexpr int depth =depth+1; templatestruct core_t_helper{using type=T;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ using C=core_t; using vector::vector; ll size()const{return vector::size();} auto&emplace_back(auto&&...a){vector::emplace_back(std::forward(a)...);return*this;} templatevoid for_each_core(F&&f)const{fe(*this,e){if constexpr(vectorial){ }else f(e);}} templateauto fold(auto&&f)const{ pairres{}; for_each_core([&](const C&e){ if(res.b)f(res.a,e); else res={e,1}; }); return res; } auto max()const{return fold([](auto&a,auto b){if(a>vec stable_sort(F f={})const{vec v=*this;ranges::stable_sort(v,f);return v;} template>auto sort_from(F f={})const{ veco(size()); std::iota(o.begin(),o.end(),0); return o.stable_sort([&](ll i,ll j){return f((*this)[i],(*this)[j]);}); } auto pos_groups(C M)const{ assert(min()>=0); vec>res(M); fo(i,size())res[(*this)[i]].eb(i); return res; } }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; templateauto zip_by(F f,A&...a){ auto v=(a^...); auto o=v.sort_from(f); vecz(v.size()); decltype(v)u; fe(o,i){ if(u.empty()||f(u.back(),v[i]))u.push_back(v[i]); z[i]=u.size()-1; } ll i=0; ([&](auto&x){fe(x,e)e=z[i++];}(a),...); return u; } auto zip(auto&...a){return zip_by(less<>{},a...);} templatevoid zeta(V&&v){if constexpr(depth>>1){ }fo(i,v.size()-1)v[i+1]+=v[i];} auto sin(){string s;lin(s);return s;} templateauto sinen_alphabet(){vecr;fe(sin(),e)r.eb(encode_alphabet(e));return r;} } void self::pp(auto&&...a){const char*c="";((cout<s(N); fo(i,N)s[i]=iv2.pow(i); zeta(s); ml ans=0; fo(i,N)ans+=ml(2).pow(N+i-1)*(s[N-1]-s[i]); FenwickTreefw(N); fo(x,g.size()){ fe(g[x],i)fw.add(i,iv2.pow(i)); fe(g[x],i)ans-=ml(2).pow(N+i-1)*fw.sum(i+1,N); fe(g[x],i)fw.add(i,-iv2.pow(i)); } pp(ans+ml(2).pow(N)-1); }