package main import . "fmt" import . "os" import bf "bufio" import . "slices" func main() { rd:=bf.NewReader(Stdin) wr:=bf.NewWriter(Stdout) var line = new(Line) Fscan(rd,line) var n int Sscan(line.s,&n) m:=make(map[string]int64) p:=make([]string,n) for i:=range p { Fscan(rd,line) c:=int64(i+1)*int64(n-i) p[i]=line.s m[line.s]+=c } Sort(p) p=Compact(p) for _,s:=range p { Fprintln(wr,m[s],s) } wr.Flush() } type Line struct { s string } func (l *Line) Scan(st ScanState, verb rune) error { token, _ := st.Token(false, func(r rune) bool { return r != '\n' }) l.s = string(token) _, _, err := st.ReadRune() return err } func (l *Line) String() string { return l.s }