{Checker задачи ДВЕ ДРОБИ }
{Киндер М., версия 03.11.2015...}
{$APPTYPE CONSOLE}
uses
    testlib, sysutils;
var
    a, b, c, d : integer;
      t, i, sp : integer;
            pa : string;
{****************************************************}
begin
    sp:= ouf.Readlongint;
    if sp > 2000000 then quit(_wa,'number of symbols greater than 10000000.');
    if sp < 1 then quit(_wa,'');

    a := inf.Readlongint;
    b := inf.Readlongint;
    c := inf.Readlongint;
    d := inf.Readlongint;

    pa := ouf.readword(blanks, blanks);
    if sp > length(pa) then quit(_pe, 'too few symbols');
    if sp < length(pa) then quit(_pe, 'too many symbols');

    ]for i := 1 to sp do
        if not (pa[i] in ['A','B','C']) then
           quit(_pe, inttostr(i) + '-st symbol is bad: ' + pa[i);

    for i := 1 to sp do begin
        if pa[i] = 'A' then inc(a,b);
        if pa[i] = 'B' then dec(a,b);
        if pa[i] = 'C' then begin
           if b = 0 then quit(_wa, 'operation C is can not applied to zero.');
              t := a; a := b; b := t;
           end;
    end;
    if not ouf.seekeof then quit(_pe, 'too many symbols');

    if (a * d <> b * c) then quit(_wa,'numbers differ - expected: ' +
    inttostr(c) + '/' + inttostr(d) + ', found: ' + inttostr(a) + '/' + inttostr(b));
    quit(_ok,'');
end.
