uses SysUtils, testlib;
var
  js, ps : string;
  cnt : array[1..26] of longint;
  pk, jk, i : longint;

function count(s : string; n : longint) : longint;
var
  i :longint;
begin
  if (n = 1) then begin
    count := 1;
    exit;
  end;
  for i := 1 to n do begin
    if (s[i] <> s[n - i + 1]) then begin
      count := 0;
      exit;
      end;
  end;
  count := 1 + count(s, n div 2);
end;

function readtoken(var str : InStream) : string;
var
  ch : array of char;
  n : longint;
  s : string;
  i : longint;
begin
  setlength(ch, 1);
  n := 0;
  str.skip(blanks);
  while (str.cur <> EofChar) and not(str.cur in Blanks) do begin
    if (n = length(ch)) then begin
      setlength(ch, 2 * length(ch));
    end;
    ch[n] := str.cur;
    n := n + 1;
    str.nextchar;
  end;
  setlength(s, n);
  for i := 0 to n - 1 do begin
    s[i + 1] := ch[i];
  end;
  result := s;
end;

begin
//  js := ans.readstring;
//  ps := ouf.readstring;
  js := readtoken(ans);
  ps := readtoken(ouf);

  for i := 1 to 26 do begin
    cnt[i] := inf.readlongint;
  end;
  for i := 1 to length(ps) do begin
    if (ps[i] < 'a') or (ps[i] > 'z') then 
      quit(_pe, 'Wrong symbols in output');
    if (cnt[ord(ps[i]) - ord('a') + 1] = 0) then
      quit(_wa, 'Too much symbols ' + ps[i] + ' in output');
    dec(cnt[ord(ps[i]) - ord('a') + 1]);
  end;
  for i := 1 to 26 do begin
    if (cnt[i] <> 0) then
      quit(_wa, 'Some symbols are not used');
  end;
  jk := count(js, length(js));
  pk := count(ps, length(ps));
  if (jk < pk) then
    quit(_fail, 'Contestant has better answer');
  if (pk < jk) then
    quit(_wa, 'Jury has better answer');
  quit(_ok, 'OK: ' + IntToStr(pk));
end.
