#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; int m; struct node{ char name[100]; int time,acno; }p[100]; bool cmp(node a,node b){ if(a.acno==b.acno&&a.time==b.time) return (strcmp(b.name,a.name)>0); else if(a.acno==b.acno) return a.time<b.time; else return a.acno>b.acno; } int change(char tmp[]){ int sum,res=0,i,t=0,k,j; double cnt; int l=strlen(tmp); if(tmp[l-1]==')'){ cnt=0; for(i=l-2;tmp[i]!='(';--i){ k=1; for(j=0;j<cnt;++j) k*=10; t+= k * (tmp[i]-'0'); cnt=cnt+1; } tmp[i]='\0'; l=strlen(tmp); } cnt=0; for(i=l-1;i>=0;--i){ k=1; for(j=0;j<cnt;++j) k*=10; res+= k * (tmp[i]-'0'); cnt=cnt+1; } return res+t*m; } int main(){ int n,i,j,cnt=0; while(~scanf("%d%d",&n,&m)){ cnt=0; char tmp[100]; for(j=0;j<6;++j){ scanf("%s",p[cnt].name); p[cnt].acno=0; p[cnt].time=0; for(i=0;i<n;++i){ scanf("%s",tmp); if(tmp[0]=='-'||tmp[0]=='0') continue; else p[cnt].time+= change(tmp); p[cnt].acno++; } cnt++; } sort(p,p+cnt,cmp); for(i=0;i<cnt;++i){ printf("%-10s %2d %4d\n",p[i].name,p[i].acno,p[i].time); } } return 0; }