#define NOFOOTER
#include "testlib.h"
#include <set>
#include <sstream>
#include <string>

int main(int argc, char *argv[])
{
    registerTestlibCmd(argc, argv);
    std::string expected = inf.readString();
    int count = inf.readInteger();
    std::set<int> possible;
    for (int i = 0; i < count; ++i)
    {
        int val = inf.readInteger();
        possible.insert(val);
    }
    //Jury section
    int juryCount = ans.readInteger();
    std::set<int> juryUsed;
    std::ostringstream juryConcat;
    for (int i = 0; i < juryCount; ++i)
    {
        int curr = ans.readInteger();
        if (possible.count(curr) == 0)
        {
            quitf(_fail, "Illegal number %d", curr);
        }
        if (juryUsed.count(curr) > 0)
        {
            quitf(_fail, "Duplicate number %d", curr);
        }
        juryConcat << curr;
    }
    std::string juryResult = juryConcat.str();
    if (juryResult != expected)
    {
        quitf(_fail, "Concatenation is wrong: expected %s, found %s", expected.c_str(), juryResult.c_str());
    }
    //Cont section
    int contCount = ouf.readInteger();
    std::set<int> contUsed;
    std::ostringstream contConcat;
    for (int i = 0; i < contCount; ++i)
    {
        int curr = ouf.readInteger();
        if (possible.count(curr) == 0)
        {
            quitf(_wa, "Illegal number %d", curr);
        }
        if (contUsed.count(curr) > 0)
        {
            quitf(_wa, "Duplicate number %d", curr);
        }
        contConcat << curr;
    }
    std::string contResult = contConcat.str();
    if (contResult != expected)
    {
        quitf(_wa, "Concatenation is wrong: expected %d, found %s", expected.c_str(), contResult.c_str());
    }
    if (juryCount < contCount)
    {
        quitf(_wa, "Jury has a solution %d, while contestant gives %d", juryCount, contCount);
    }
    else if (juryCount > contCount)
    {
        quitf(_fail, "Contestant has solution %d while jury's %d is worse", contCount, juryCount);
    }
    else
    {
        quitf(_ok, "Answer contains %d numbers", juryCount);
    }
}
