简单题,直接模拟即可,注意是收到的钱数-花出钱数(不是总钱数)

program gift1;
type
  node=record
    s:string;
    v1,v2:longint;
  end;
var
  a:array[1..10] of node;
  i,j,n,p,q:integer;
  s1:string;
begin
  assign(input,'gift1.in');
  reset(input);
  assign(output,'gift1.out');
  rewrite(output);
  readln(n);
  for i:=1 to n do
  begin
    readln(a[i].s);
    a[i].v1:=0;
    a[i].v2:=0;
  end;
  while not eof do
  begin
    readln(s1);
    readln(p,q);
    if q<>0 then
    begin
      for i:=1 to n do
        if a[i].s=s1 then
        begin
          a[i].v1:=(p div q)*q;
          break;
        end;
      for i:=1 to q do
      begin
        readln(s1);
        for j:=1 to n do
          if a[j].s=s1 then
          begin
            inc(a[j].v2,p div q);
            break;
          end;
      end;
    end;
  end;
  for i:=1 to n do
    writeln(a[i].s,' ',a[i].v2-a[i].v1);
  close(input);
  close(output);
end.