ll@N;mapS;string T;rep(j,N){getline(cin,T);S[T]+=(j+1)*(N-j);}auto i=S.begin(),e=S.end();for(;i!=e;i++)wt(i->second,T=i->first);