#include #include #include #include #include using namespace std; typedef long long ll; map match; char s[100010][20]; int n,m,point[100010],one[100010],two[100010],sum_one[100010],sum_two[100010]; bool cmp(char a,char b) { return a=1;i--) { len=strlen(s[i]); sort(s[i],s[i]+len,cmp); k=match[s[i]]; if(k==0) point[i]=n+1; else point[i]=k; match[s[i]]=i; } a=n+1;b=n+1; for(i=n;i>=1;i--) { c=point[i]; if(c=l) ans+=r*(pos-l+1)-(sum_one[pos]-sum_one[l-1]); pos=upper_bound(two+1,two+n,r)-two-1; if(pos>=l) ans-=r*(pos-l+1)-(sum_two[pos]-sum_two[l-1]); printf("%I64d\n",ans); } } }