program checka;

uses
    testlib, sysutils;
    
var
    ja, pa: string;
    sum, i, k, n, p: longint;
    c, l: array [1..5000] of longint;
    s, count: array [1..100] of longint;
    u: array [1..5000] of boolean;
    
begin
    n := inf.readlongint;
    k := inf.readlongint;

    fillchar(s, sizeof(s), 0);
    for i := 1 to n do
    begin
        l[i] := inf.readlongint;
        if (l[i] > 100) then
            quit(_fail, 'too huge brick ' + inttostr(i) + ': ' + inttostr(l[i]));
        if (l[i] <= 0) then
            quit(_fail, 'invalid brick ' + inttostr(i) + ': ' + inttostr(l[i]));
        c[i] := inf.readlongint;
        if (c[i] > k) then
            quit(_fail, 'invalid color: ' + inttostr(c[i]));
        s[c[i]] := s[c[i]] + l[i];
        inc(count[c[i]]);
    end;        
    
    for i := 1 to k do
    begin
        if count[i] > 50 then
            quit(_fail, inttostr(count[i]) + ' bricks of color ' + inttostr(i));
        if s[i] <> s[1] then
            quit(_fail, 'cannot make rectangular wall');
    end;
    sum := s[1];
    
    ja := uppercase(trim(ans.readstring));
    pa := uppercase(trim(ouf.readstring));
    
    if ja <> pa then
        quit(_wa, 'expected: ' + ja + ', found: ' + pa);

    if ja = 'NO' then
        quit(_ok, 'NO');

    if ouf.seekeof then
        quit(_wa, 'bricks expected');
        
    fillchar(u, sizeof(u), false);
    fillchar(s, sizeof(s), 0);
    while not ouf.seekeof do
    begin
        p := ouf.readlongint;
        if (p <= 0) or (p > n) then
            quit(_wa, 'invalid brick: ' + inttostr(p));
        if u[p] then
            quit(_wa, 'duplicate brick: ' + inttostr(p));
        u[p] := true;
        s[c[p]] := s[c[p]] + l[p];
    end;
    
    for i := 1 to k do
        if s[i] <> s[1] then
            quit(_wa, 'wall is not rectangular');
            
    for i := 1 to n do
        if not u[i] then
            quit(_ok, 'YES ' + inttostr(s[1]) + ' of ' + inttostr(sum));
    quit(_wa, 'all bricks used for first wall');
end.