#define NOFOOTER

#include "testlib.h"

#include <algorithm>
#include <sstream>
#include <vector>

struct outcome_handler
{
    virtual void wa(std::string const &str) const = 0;
};

struct jury_handler : outcome_handler
{
    virtual void wa(std::string const &str) const
    {
        quitf(_fail, str.c_str());
    }
};

struct cont_handler : outcome_handler
{
    virtual void wa(std::string const &str) const
    {
        quitf(_wa, str.c_str());
    }
};

void validate
(
    int v0, 
    std::vector<int> const &v, 
    std::vector<int> const &c, 
    std::vector<int> const &p, 
    int cost, 
    std::vector<int> &items,
    outcome_handler const &handler
)
{
    std::sort(items.begin(), items.end());
    if (std::unique(items.begin(), items.end()) != items.end())
    {
        handler.wa("Some items are duplicated");
    }
    for (int i = 0; i < items.size(); ++i)
    {
        if (items[i] < 1 || items[i] > v.size())
        {
            std::string s = "Item index is out of bounds: items[";
            s += i;
            s += "] = ";
            s += items[i];
            
            handler.wa(s);
        }
        --items[i];
    }
    int sumv = 0;
    int sumc = 0;
    int maxp = 1000000000;
    for (int i = 0; i < items.size(); ++i)
    {
        int j = items[i];
        sumv += v[j];
        sumc += c[j];
        maxp = std::min(maxp, p[j]);
    }
    if (sumc != cost)
    {
        handler.wa("Cost of the specified set is wrong");
    }
    if (sumv - v0 > maxp)
    {
        handler.wa("Pressure is too high");
    }
}

int main(int argc, char *argv[])
{
    registerTestlibCmd(argc, argv);

    int n = inf.readInt();
    int v0 = inf.readInt();
    
    std::vector<int> v(n), p(n), c(n);

    int sumcost = 0;
    
    for (int i = 0; i < n; ++i)
    {
        v[i] = inf.readInt();
        c[i] = inf.readInt();
        p[i] = inf.readInt();
        sumcost += c[i];
    }
    
    int juryCount = ans.readInt();
    int juryCost = ans.readInt();
    std::vector<int> juryItems(juryCount);
    for (int i = 0; i < juryCount; ++i)
    {
        juryItems[i] = ans.readInt();
    }
    
    int contCount = ouf.readInt();
    int contCost = ouf.readInt();
    std::vector<int> contItems(contCount);
    for (int i = 0; i < contCount; ++i)
    {
        contItems[i] = ouf.readInt();
    }
    
    validate(v0, v, c, p, juryCost, juryItems, jury_handler());
    validate(v0, v, c, p, contCost, contItems, cont_handler());
    
    if (contCost > juryCost)
    {
        quitf(_fail, "Contestant found a better answer");
    }
    if (contCost < juryCost)
    {
        quitf(_wa, "Jury has a better answer");
    }
    quitf(_ok, "Ok (cost=%d/total=%d)", juryCost, sumcost);
}
