#include #include using namespace std; const int N=1e5+10; vectorg[N]; int sumc[N],sumw[N],totc,totw; long long ans; char s[N]; void dfs(int u,int fa) { s[u]=='c'?sumc[u]++:sumw[u]++; for(auto v:g[u]) { if(v==fa) continue; dfs(v,u),sumc[u]+=sumc[v],sumw[u]+=sumw[v]; if(s[u]=='w') ans+=1ll*sumc[v]*(totw-sumw[v]-1); } if(fa&&s[u]=='w') ans+=1ll*(totc-sumc[u])*(sumw[u]-1); } int main() { //freopen("cww.in","r",stdin); //freopen("cww.out","w",stdout); int n; scanf("%d %s",&n,s+1); for(int i=1;i<=n;i++) s[i]=='c'?totc++:totw++; for(int i=1,u,v;i