Problem:
Problem D:
Private Teacher
You are working as a private teacher. Since you are giving lessons to many pupils, you are very busy,
especially during examination seasons. This season is no exception in that regard.
You know days of the week convenient for each pupil, and also know how many lessons you have to give
to him or her. You can give just one lesson only to one pupil on each day. Now, there are only a limited
number of weeks left until the end of the examination. Can you finish all needed lessons?
Input
The input consists of multiple data sets. Each data set is given in the following format:
N W
t
1
c
1
list-of-days-of-the-week
t
2
c
2
list-of-days-of-the-week
...
t
N
c
N
list-of-days-of-the-week
A data set begins with a line containing two integers
N
(0 <
N
≤ 100) and
W
(0 <
W
≤ 10
10
).
N
is the
number of pupils.
W
is the number of remaining weeks. The following 2
N
lines describe information
about the pupils. The information for each pupil is given in two lines. The first line contains two integers
t
i
and
c
i
.
t
i
(0 <
t
i
≤ 10
10
) is the number of lessons that the
i
-th pupil needs.
c
i
(0 <
c
i
≤ 7) is the number
of days of the week convenient for the
i
-th pupil. The second line is the list of
c
i
convenient days of the
week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday).
The end of input is indicated by a line that contains two zeros. This line should not be processed.
Output
For each data set, print “Yes” if you can finish all lessons, or “No” otherwise.
Sample Input
2 2
6 3
Monday Tuesday Wednesday
8 4
Thursday Friday Saturday Sunday
2 2
7 3
Monday Tuesday Wednesday
9 4
Thursday Friday Saturday Sunday
0 0
Output for the Sample Input
Yes
No

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

struct Dinic {
private:
    const long long inf = 1e18;
    vector<int> dist; //sからの距離
    vector<int> iter; //どこまで調べたか
public:
    struct edge {
        int to, rev; long long cap;
        edge(int t = 0, int r = 0, long long c = 0LL) : to(t), rev(r), cap(c) {}
    };

    int n;
    vector<vector<edge>> to;

    Dinic(int n_ = 1) : n(n_), to(n_), dist(n_), iter(n_) {}

    void addedge(int u, int v, long long cap) {//u->vにcapの容量
        int su = (int)to[u].size(), sv = (int)to[v].size();
        to[u].push_back({ v, sv, cap });
        to[v].push_back({ u, su, 0 });
    }

    long long dfs(int v, int t, long long f) { //t: 終点, f: flow
        if (v == t) return f;
        int sv = (int)to[v].size();
        for (int& i = iter[v]; i < sv; i++) {
            edge& nv = to[v][i];
            if (dist[nv.to] <= dist[v] || nv.cap == 0) continue; //here
            long long nf = dfs(nv.to, t, min(f, nv.cap));
            if (nf > 0) {
                nv.cap -= nf;
                to[nv.to][nv.rev].cap += nf;
                return nf;
            }
        }
        return 0;
    }

    void bfs(int s) {
        dist.assign(n, -1);
        queue<int> q;
        q.push(s);
        dist[s] = 0;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto nv : to[v]) {
                if (nv.cap > 0 && dist[nv.to] < 0) {
                    dist[nv.to] = dist[v] + 1;
                    q.push(nv.to);
                }
            }
        }
    }

    long long maxflow(int s, int t) {//s:始点, t:終点
        long long res = 0, flow = 0;
        while (true) {
            bfs(s);
            if (dist[t] < 0) break;

            iter.assign(n, 0);
            while (flow = dfs(s, t, inf)) res += flow;
        };
        return res;
    }
};

int main()
{
    map<string, int> mp;
    mp["Monday"]    = 0;
    mp["Tuesday"]   = 1;
    mp["Wednesday"] = 2;
    mp["Thursday"]  = 3;
    mp["Friday"]    = 4;
    mp["Saturday"]  = 5;
    mp["Sunday"]    = 6;

    const ll inf = 1e18;

    int n;
    ll w;
    while (cin >> n >> w, n) {
        Dinic dn(n + 9);
        int S = n + 7, T = S + 1;
        ll cnt = 0;
        rep(i, n) {
            ll t;
            int c;
            cin >> t >> c;
            cnt += t;

            dn.addedge(S, i, t);
            rep(j, c) {
                string s;
                cin >> s;
                dn.addedge(i, n + mp[s], inf);
            }
        }

        rep(i, 7) dn.addedge(n + i, T, w);

        ll flow = dn.maxflow(S, T);
        cout << (flow == cnt ? "Yes" : "No") << endl;
    }
    
}
accuracy: 1
time_ms: 10
memory_kb: 3428
final_rank: 13

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

template <typename T> struct dinic {
    struct edge {
        int to;
        T c, f;
    };
    T eps;
    const T inf = numeric_limits<T>::max();
    int n, m = 0;
    vector<edge> e;
    vector<vector<int>> g;
    vector<int> level, ptr;
    dinic(int n) : n(n), g(n), level(n), ptr(n) { eps = (T)1 / (T)1e9; }
    void add_edge(int s, int t, T c) {
        e.push_back({t, c, 0});
        e.push_back({s, 0, 0});
        g[s].push_back(m++);
        g[t].push_back(m++);
    }
    bool bfs(int s, int t) {
        fill(level.begin(), level.end(), -1);
        level[s] = 0;
        for (queue<int> q({s}); q.size(); q.pop()) {
            int s = q.front();
            for (int i : g[s]) {
                int t = e[i].to;
                if (level[t] == -1 and (e[i].c - e[i].f) > eps) {
                    level[t] = level[s] + 1;
                    q.push(t);
                }
            }
        }
        return (level[t] != -1);
    }
    T dfs(int s, int t, T psh) {
        if (!(psh > eps) or s == t) return psh;
        for (int &i = ptr[s]; i < (int)g[s].size(); ++i) {
            auto &eg = e[g[s][i]];
            if (level[eg.to] != level[s] + 1 or !(eg.c - eg.f > eps)) continue;
            T f = dfs(eg.to, t, min(psh, eg.c - eg.f));
            if (f > eps) {
                eg.f += f;
                e[g[s][i] ^ 1].f -= f;
                return f;
            }
        }
        return 0;
    }
    T max_flow(int s, int t) {
        T f = 0;
        while (bfs(s, t)) {
            fill(ptr.begin(), ptr.end(), 0);
            while (1) {
                T c = dfs(s, t, inf);
                if (c > eps) {
                    f += c;
                } else {
                    break;
                }
            }
        }
        return f;
    }
    // ABC239-G
    vector<bool> min_cut(int s) {
        vector<bool> visited(n);
        queue<int> q;
        q.push(s);
        while (q.size()) {
            int p = q.front();
            q.pop();
            visited[p] = true;
            for (auto idx : g[p]) {
                auto eg = e[idx];
                if (eg.c - eg.f > eps and !visited[eg.to]) {
                    visited[eg.to] = true;
                    q.push(eg.to);
                }
            }
        }
        return visited;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll W;
    map<string, int> mp;
    while (cin >> n >> W, n) {
        int S = n + 7, T = n + 8;
        dinic<ll> g(n + 9);
        ll al = 0;
        for (int i = 0; i < n; i++) {
            ll u;
            cin >> u;
            al += u;
            g.add_edge(S, i, u);
            int k;
            cin >> k;
            for (int j = 0; j < k; j++) {
                string s;
                cin >> s;
                if (mp.find(s) == mp.end()) {
                    int id = mp.size();
                    mp[s] = id;
                }
                g.add_edge(i, n + mp[s], 1e18);
            }
        }
        for (int i = 0; i < 7; i++) {
            g.add_edge(n + i, T, W);
        }
        if (g.max_flow(S, T) == al) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;

struct Dinic{
  int INF=1e17;
  
  struct edge {
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<map<int,int> > M;
  vector<int> level,iter;

  Dinic(){}
  Dinic(int sz):n(sz),G(n),M(n),level(n),iter(n){}
  
  void add_edge(int from,int to,int cap){
    M[from][to]=G[from].size();
    M[to][from]=G[to].size();
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  
  void bfs(int s){
    fill(level.begin(),level.end(),-1);
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&level[e.to]<0){
          level[e.to]=level[v]+1;
          que.push(e.to);
        }
      }
    }
  }
  
  int dfs(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
        int d = dfs(e.to,t,min(f,e.cap));
       if(d>0){
         e.cap-=d;
         G[e.to][e.rev].cap+=d;
         return d;
       }
      }
    }
    return 0;
  }
  
  int flow(int s,int t,int lim){
    int fl=0;
    for(;;){
      bfs(s);
      if(level[t]<0||lim==0) return fl;
      fill(iter.begin(),iter.end(),0);
      int f;
      while((f=dfs(s,t,lim))>0){
       fl+=f;
       lim-=f;
      }
    }
  }

  int flow(int s,int t){
    return flow(s,t,INF);
  }

  //cap==1 only
  bool back_edge(int s,int t,int from, int to){
    for(int i=0;i<(int)G[from].size();i++) {
      edge& e=G[from][i];
      if(e.to==to) {
        if(e.cap==0&&flow(from,to,1)==0) {
          flow(from,s,1);
          flow(t,to,1);
          return 1;
        }
      }
    }
    return 0;
  }
};

map<string,int>m;

void init(){
  m["Sunday"]=0;
  m["Monday"]=1;
  m["Tuesday"]=2;
  m["Wednesday"]=3;
  m["Thursday"]=4;
  m["Friday"]=5;
  m["Saturday"]=6;
}

main(){
  init();
  int n,W,t,x,sum;
  while(cin>>n>>W){
    if(!n&&!W)break;
    sum=0;
    Dinic d(n+9);
    r(i,7)d.add_edge(n+7,i,W);
    r(i,n){
      cin>>t>>x;
      sum+=t;
      d.add_edge(i+7,n+8,t);
      r(j,x){
        string s;
        cin>>s;
        d.add_edge(m[s],i+7,W);
      }
    }
    if(sum==d.flow(n+7,n+8,sum))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}
accuracy: 1
time_ms: 40
memory_kb: 3256
final_rank: 19

code_snippet: #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct Dinic {
	using Flow = int;
	struct Edge {
		int to, rev;
		Flow cap;
		Edge() {}
		Edge(int to, int rev, Flow cap) :to(to), rev(rev), cap(cap) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<bool> used;
	vector<int> level;
	vector<int> iter;
	Dinic(int n) :n(n), g(n), used(n), level(n), iter(n) {};
	void addArc(int from, int to, Flow cap) {
		g[from].emplace_back(to, (int)g[to].size(), cap);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0);
	}
	void addEdge(int a, int b, Flow cap) {
		g[a].emplace_back(b, (int)g[b].size(), cap);
		g[b].emplace_back(a, (int)g[a].size() - 1, cap);
	}
	Flow maximumFlow(int s, int t) {
		Flow total = 0;
		while (true) {
			levelize(s);
			if (level[t] < 0)return total;
			fill(iter.begin(), iter.end(), 0);
			Flow f;
			while (true) {
				f = augment(s, t, INF);
				if (f == 0)break;
				total += f;
			}
		}
	}
	Flow augment(int v, int t, Flow f) {
		if (v == t)return f;
		for (int &i = iter[v]; i < g[v].size(); i++) {
			Edge &e = g[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				Flow d = augment(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					g[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	void levelize(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while (q.size()) {
			int v = q.front(); q.pop();
			for (int i = 0; i < g[v].size(); i++) {
				Edge &e = g[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, W; cin >> N >> W&&N;) {
		Dinic dinic(7 + N + 2);
		int src = 7 + N, snk = src + 1;
		rep(i, 0, 7)
			dinic.addArc(src, i, W);
		int total = 0;
		rep(i, 0, N) {
			int t, c; cin >> t >> c;
			total += t;
			dinic.addArc(7 + i, snk, t);
			rep(j, 0, c) {
				string s; cin >> s;
				if (s == "Sunday")
					dinic.addArc(0, 7 + i, W);
				else if (s == "Monday")
					dinic.addArc(1, 7 + i, W);
				else if (s == "Tuesday")
					dinic.addArc(2, 7 + i, W);
				else if (s == "Wednesday")
					dinic.addArc(3, 7 + i, W);
				else if (s == "Thursday")
					dinic.addArc(4, 7 + i, W);
				else if (s == "Friday")
					dinic.addArc(5, 7 + i, W);
				else if (s == "Saturday")
					dinic.addArc(6, 7 + i, W);
			}
		}
		cout << (dinic.maximumFlow(src, snk) == total ? "Yes" : "No") << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3204
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// (?????????,??????,??????)
struct edge{ int to; ll cap; int rev; };

const int MAX_V = 110; // TODO:initialize
const ll F_INF = 12345678901234LL; // TODO:initialize
vector<edge> G[MAX_V];
int level[MAX_V]; // s??????????????¢
int iter[MAX_V]; // ???????????§??????????????£??????

void add_edge(int from, int to, ll cap){
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,0,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

// ?¢?????????????dfs??§??¢???
ll dinic_dfs(int v, int t, ll f){
    if(v==t) return f;
    for(int &i=iter[v]; i<G[v].size(); ++i){
        edge &e=G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            ll d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// s??????t???????????§???
ll max_flow(int s, int t){
    ll flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        ll f;
        while((f=dinic_dfs(s,t,F_INF))>0) flow+=f;
    }
}

int main()
{
    vector<string> days({"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"});
    map<string,int> d;
    rep(i,days.size()) d[days[i]]=i;

    int n;
    ll w;
    while(cin >>n >>w,n)
    {
        rep(i,MAX_V) G[i].clear();

        int S = n+7, T = S+1;
        rep(i,7) add_edge(S,i,w);

        ll sumt = 0;
        rep(i,n)
        {
            ll t;
            int c;
            cin >>t >>c;

            sumt += t;
            add_edge(7+i,T,t);

            while(c--)
            {
                string s;
                cin >>s;
                add_edge(d[s],7+i,w);
            }
        }

        cout << (max_flow(S,T)==sumt?"Yes":"No") << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3276
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef ll Weight;
typedef ll Capacity;
struct Edge {
	int src, dst; Capacity cap;
	Edge(int s, int d, Capacity c) : src(s), dst(d), cap(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
	int n, s, t;
	vector<int> level, prog, que;
	vector<vector<Capacity> > cap, flow;
	vector<vector<int> > g;
	Capacity inf;
	Dinic() {}
	Dinic(const Graph &graph)
		: n(graph.size()),
		cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf((int)1e9) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < graph[i].size(); j++) {
				const Edge& e = graph[i][j];
				int u = e.src, v = e.dst;
				Capacity c = e.cap;
				add_edge(u, v, c);
			}
		}
	}
	Dinic(int n_) : n(n_), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf((int)1e9) {
	}
	void add_edge(int u, int v, Capacity c) {
		cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
		g[u].push_back(v); g[v].push_back(u);
	}
	void reset() {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cap[i][j] = flow[i][j] = 0;
			}
			g[i].clear();
		}
	}
	inline Capacity residue(int u, int v) { return cap[u][v] - flow[u][v]; }
	Capacity solve(int s_, int t_) {
		this->t = t_, this->s = s_;
		que.resize(n + 1);
		Capacity res = 0;
		while(levelize()) { prog.assign(n, 0); res += augment(s, inf); }
		return res;
	}
	bool levelize() {
		int l = 0, r = 0;
		level.assign(n, -1); level[s] = 0; que[r++] = s;
		while(l != r) {
			int v = que[l++]; if(v == t) break;
			for(int i = 0; i < g[v].size(); i++) {
				const int& d = g[v][i];
				if(level[d] == -1 && residue(v, d) != 0) {
					level[d] = level[v] + 1; que[r++] = d;
				}
			}
		}
		return level[t] != -1;
	}
	Capacity augment(int v, Capacity lim) {
		Capacity res = 0;
		if(v == t) return lim;
		for(int &i = prog[v]; i < (int)g[v].size(); i++) {
			const int &d = g[v][i];
			if(residue(v, d) == 0 || level[v] >= level[d]) continue;
			const Capacity aug = augment(d, min(lim, residue(v, d)));
			flow[v][d] += aug; flow[d][v] -= aug;
			res += aug; lim -= aug;
			if(lim == 0) break;
		}
		return res;
	}
};

string day[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N, W;
	while(cin >> N >> W, N + W) {
		Dinic D(N + 7 + 2);
		int S = N + 7, T = S + 1;

		ll tsum = 0;
		for(int i = 0; i < N; i++) {
			ll t, c;
			cin >> t >> c;
			tsum += t;
			for(int j = 0; j < c; j++) {
				string s;
				cin >> s;
				int idx = find(day, day + 7, s) - day;
				//cout << idx << endl;
				D.add_edge(i, N + idx, t);
			}
			D.add_edge(S, i, t);
		}
		for(int i = 0; i < 7; i++) {
			D.add_edge(N + i, T, W);
		}

		if(tsum == D.solve(S, T)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}


}
accuracy: 1
time_ms: 20
memory_kb: 3088
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
struct edge{ int to,rev; ll cap; };
vector< vector<edge> > G(110);
bool used[110];

#define INF (1LL << 55)

void addEdge(int from, int to, ll cap)
{
  G[from].push_back((edge){to, (int)G[to].size(), cap});
  G[to].push_back((edge){from, (int)G[from].size()-1, 0});
}

ll dfs(int v, int t, ll f)
{
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      ll d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

ll maxFlow(int s, int t)
{
  ll flow = 0;
  for(;;){
    memset(used, false, sizeof(used));
    ll f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main()
{
  map<string, int> days = {
    {"Sunday",0},
    {"Monday",1},
    {"Tuesday",2},
    {"Wednesday",3},
    {"Thursday",4},
    {"Friday",5},
    {"Saturday",6}
  };
  ll N, W;
  while(cin >> N >> W, N || W){
    G.clear(); G.resize(N + 9);
    int S = N + 7, T = S + 1;
    ll lesson = 0;
    for(int i = 0; i < N; i++){
      ll t; int c;
      cin >> t >> c;
      lesson += t;
      addEdge(S, i, t);
      for(int j = 0; j < c; j++){
	string day;
	cin >> day;
	addEdge(i, N + days[day], INF);
      }
    }
    for(int i = 0; i < 7; i++){
      addEdge(N + i, T, W);      
    }
    cout << (maxFlow(S, T) >= lesson ? "Yes":"No") << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3068
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define MAX_V 514
#define INF (1LL<<58)
typedef long long ll;

struct Edge {
    ll to, cap, rev;
    Edge(ll to, ll cap, ll rev) :
        to(to), cap(cap), rev(rev) {}
};

vector<Edge> G[MAX_V];
ll level[MAX_V], iter[MAX_V];

void add_edge(int from, int to, ll cap)
{
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to].push_back(Edge(from, 0, G[from].size()-1));
}

void bfs(int s)
{
    memset(level, -1, sizeof(level));
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
	int v = Q.front(); Q.pop();
	for (int i = 0; i < (int)G[v].size(); i++) {
	    Edge &e = G[v][i];
	    if (e.cap > 0 && level[e.to] < 0) {
		level[e.to] = level[v] + 1;
		Q.push(e.to);
	    }
	}
    }
}

ll dfs(int v, int t, ll f)
{
    if (v == t) return f;
    for (ll &i = iter[v]; i < (ll)G[v].size(); i++) {
	Edge &e = G[v][i];
	if (e.cap > 0 && level[v] < level[e.to]) {
	    ll d = dfs(e.to, t, min(f, e.cap));
	    if (d > 0) {
		e.cap -= d;
		G[e.to][e.rev].cap += d;
		return d;
	    }
	}
    }
    return 0;
}

ll max_flow(int s, int t)
{
    ll flow = 0;
    for (;;) {
	bfs(s);
	if (level[t] < 0) return flow;
	memset(iter, 0, sizeof(iter));
	ll f;
	while ((f = dfs(s, t, INF)) > 0) {
	    flow += f;
	}
    }
}

void init()
{
    for (ll i = 0; i < MAX_V; i++) {
        G[i].clear();
    }
}

int main()
{
    map<string, int> w = {
        {"Monday", 0},
        {"Tuesday", 1},
        {"Wednesday", 2},
        {"Thursday", 3},
        {"Friday", 4},
        {"Saturday", 5},
        {"Sunday", 6}
    };
       
    ll N, W;
    while (cin >> N >> W, N) {
        init();
        ll t, c, sum = 0;
        int S = N + 7, T = S + 1;
        for (int i = 0; i < N; i++) {
            cin >> t >> c;
            sum += t;
            add_edge(S, i, t);
            for (int j = 0; j < c; j++) {
                string s;
                cin >> s;                
                add_edge(i, N + w[s], INF);
            }            
        }
        for (int i = 0; i < 7; i++) {
            add_edge(N + i, T, W);
        }

        if (sum > 7*W) {
            cout << "No" << endl;
            continue;
        }
        cout << (max_flow(S, T) >= sum ? "Yes" : "No") << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3260
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define MAX_V 150
#define INF (1LL<<55)
typedef long long ll;

struct Edge {
    int to;
    ll cap, rev;
    Edge(int to, ll cap, ll rev) :
        to(to), cap(cap), rev(rev) {}
};

vector<Edge> G[MAX_V];
ll level[MAX_V], iter[MAX_V];

void add_edge(int from, int to, ll cap)
{
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to].push_back(Edge(from, 0, G[from].size()-1));
}

void bfs(ll s)
{
    memset(level, -1, sizeof(level));
    queue<ll> Q;
    level[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
	ll v = Q.front(); Q.pop();
	for (int i = 0; i < (int)G[v].size(); i++) {
	    Edge &e = G[v][i];
	    if (e.cap > 0 && level[e.to] < 0) {
		level[e.to] = level[v] + 1;
		Q.push(e.to);
	    }
	}
    }
}

ll dfs(int v, int t, ll f)
{
    if (v == t) return f;
    for (ll &i = iter[v]; i < (int)G[v].size(); i++) {
	Edge &e = G[v][i];
	if (e.cap > 0 && level[v] < level[e.to]) {
	    ll d = dfs(e.to, t, min(f, e.cap));
	    if (d > 0) {
		e.cap -= d;
		G[e.to][e.rev].cap += d;
		return d;
	    }
	}
    }
    return 0;
}

ll max_flow(int s, int t)
{
    ll flow = 0;
    for (;;) {
	bfs(s);
	if (level[t] < 0) return flow;
	memset(iter, 0, sizeof(iter));
	ll f;
	while ((f = dfs(s, t, INF)) > 0) {
	    flow += f;
	}
    }
}

void init()
{
    for (int i = 0; i < MAX_V; i++) {
        G[i].clear();
    }
}

int main()
{
    ll N, W;
    string in;
    map<string, int> mp = {
        {"Monday",    0},
        {"Tuesday",   1},
        {"Wednesday", 2},
        {"Thursday",  3},
        {"Friday",    4},
        {"Saturday",  5},
        {"Sunday",    6}
    };
        
    while (cin >> N >> W, N) {
        init();
        
        ll t, c, sum = 0;
        int S = N + 7, T = S + 1;
        for (int i = 0; i < N; i++) {
            cin >> t >> c;
            sum += t;
            add_edge(S, i, t);
            for (int j = 0; j < c; j++) {
                cin >> in;
                add_edge(i, N + mp[in], INF);
            }
        }
        for (int i = 0; i < 7; i++) {
            add_edge(N + i, T, W);
        }
        cout << (max_flow(S, T) >= sum ? "Yes" : "No") << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3180
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const double EPS = 1e-8;
typedef pair<ll,ll> P;
const ll INF = (1000000000000000LL);
const ll MAX_V = 1000;
 
 
//テヲツ慊?・ツ、ツァテヲツオツ?Ford-Fulkerson O(F|E|)
  
struct edge{ll to,cap,rev;};
  
vector<edge> G[MAX_V];
bool used[MAX_V];
  
void add_edge(ll from, ll to, ll cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, 0, G[from].size()-1});
}
  
ll dfs(ll v, ll t, ll f){
  if(v == t)return f;
  used[v] = true;
  for(ll i = 0 ; i < (ll)G[v].size() ; i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      ll d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
  
ll maxflow(ll s,ll t){
  ll flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    ll f = dfs(s,t,INF);  
    //  cout << f<< endl;  
    if(f == 0)return flow;
    flow += f;
  }
}

string weeks[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

ll getday(string s){
  for(ll i=0;i<7;i++) if( s == weeks[i] ) return i;
  assert(false);
}
 

ll N,W;
int main(){
  while( cin >> N >> W && (N|W) ){    
    ll sum = 0;
    int s = N+7, t = N+8;
    for(ll i=0;i<N;i++){
      ll t,c;
      cin >> t >> c;
      sum += t;
      for(ll j=0;j<c;j++){
        string m; 
        cin >> m;
        int d = getday(m);
        add_edge( i, N+d, INF );
      }
      add_edge(s,i,t);      
    }
    for(int i=0;i<7;i++)
      add_edge( N+i, t, W );
    if( maxflow( s,t ) == sum ) cout << "Yes" << endl;
    else cout << "No" << endl;

    for(int i=0;i<=t;i++) G[i].clear();
  }
}
accuracy: 1
time_ms: 80
memory_kb: 1400
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{  ll to,cap,rev;};

vector<edge> G[110];

void add_edge(ll from,ll to,ll cap){
  G[from].push_back( (edge){to,cap, (ll)G[to].size() } );
  G[to].push_back( (edge){from,0, (ll)G[from].size()-1} );
}

bool visited[110];
ll dfs(ll pos,ll ti,ll f){
  if(pos==ti)return f;
  if(visited[pos])return 0;
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    edge &e=G[pos][i];
    if(e.cap==0)continue;
    ll a=dfs(e.to,ti,min(f,e.cap));
    if(a==0)continue;
    e.cap-=a;
    G[e.to][e.rev].cap+=a;
    return a;
  }
  return 0;
}

ll max_flow(ll si,ll ti){
  ll res=0;
  while(1){
    memset(visited,false,sizeof(visited));
    ll f=dfs(si,ti,(1LL<<60));
    if(f==0)break;
    res+=f;
  }
  return res;
}

void init(){
  for(int i=0;i<110;i++)G[i].clear();
}

map<string,int> mp;
ll N,W;
int main(){
  mp["Sunday"]=0;
  mp["Monday"]=1;
  mp["Tuesday"]=2;
  mp["Wednesday"]=3;
  mp["Thursday"]=4;
  mp["Friday"]=5;
  mp["Saturday"]=6;

  while(1){
    cin>>N>>W;
    if(N==0&&W==0)break;
    init();
    ll si=7+N,ti=8+N,sum=0;
    for(int i=0;i<7;i++)add_edge(si,i,W);
    for(int i=0;i<N;i++){
      string str;
      ll t,c;
      cin>>t>>c;
      sum+=t;
      add_edge(7+i,ti,t);
      for(int j=0;j<c;j++){
        cin>>str;
        add_edge(mp[str],7+i,W);
      }
    }

    cout<< (max_flow(si,ti)==sum?"Yes":"No") <<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 1352
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_V=120,MAX=1<<29;

struct edge{
  ll to,cap,rev;
};
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(ll from,ll to,ll cap) {
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

ll dfs(ll v,ll t,ll f) {
  if(v==t) return f;
  used[v]=true;
  for(int i=0; i<G[v].size(); i++) {
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0) {
      ll d=dfs(e.to,t,min(f,e.cap));
      if(d>0) {
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(ll s,ll t) {
  ll flow=0;
  for(;;) {
    memset(used,0,sizeof(used));
    ll f=dfs(s,t,MAX);
    if(f==0) return flow;
    flow+=f;
  }
}
int main() {
  ll n,m;
  while(cin >> n >> m && n) {
    for(int i=0; i<MAX_V; i++) G[i].clear();
    for(int i=0; i<7; i++) add_edge(110,100+i,m);
    ll sum=0;
    for(int i=0; i<n; i++) {
      ll x,y;
      cin >> x >> y;
      sum+=x;
      add_edge(i,111,x);
      for(int j=0; j<y; j++) {
        string t;
        cin >> t;
        if(t=="Sunday") add_edge(100,i,x);
        if(t=="Monday") add_edge(101,i,x);
        if(t=="Tuesday") add_edge(102,i,x);
        if(t=="Wednesday") add_edge(103,i,x);
        if(t=="Thursday") add_edge(104,i,x);
        if(t=="Friday") add_edge(105,i,x);
        if(t=="Saturday") add_edge(106,i,x);
      }
    }
    if(max_flow(110,111)==sum) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 1264
final_rank: 5

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
struct edge { ll to, cap, rev; };//ikisaki youryou gyakuhen
#define MAX 200
vector<vector<edge> >G(MAX);//[MAX];
vector<bool>used(MAX);//[MAX];
void add_edge(ll from, ll to, ll cap){
	edge q={to,cap,ll(G[to].size())};
    G[from].push_back(q);
	q={from,0,ll(G[from].size()-1)};
    G[to].push_back(q);
}

ll dfs(ll v, ll t, ll f) {
    if(v == t) return f;
    used[v] = 1;
    for(int i = 0 ; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(used[e.to] || e.cap <= 0) continue;
        ll d = dfs(e.to, t, min(f, e.cap));
        if(d > 0){
            e.cap -= d;
            G[e.to][e.rev].cap += d;
            return d;
        }
    }
    return 0;
}
ll ford_fulkerson(ll s, ll t) {//from s to t
    ll flow = 0, f;
    while(1){
		used=vector<bool>(MAX,false);
        f = dfs(s, t, inf);
        if(f == 0) return flow;
        flow += f;
    }
}
int gcd(int a,int b){
	if(a<b)swap(a,b);
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	ll n,m;
	map<string,int>ma;
	ma["Sunday"]=0;
	ma["Monday"]=1;
	ma["Tuesday"]=2;
	ma["Wednesday"]=3;
	ma["Thursday"]=4;
	ma["Friday"]=5;
	ma["Saturday"]=6;
	while(cin>>n>>m,n+m){
		rep(i,MAX)G[i].clear();
		ll s=n+7,t=s+1;
		ll out=0;
		rep(i,n){
			ll c,d;
			cin>>c>>d;
			out+=c;
			add_edge(s,i,c);
			rep(j,d){
				string ss;
				cin>>ss;
				add_edge(i,n+ma[ss],m);
			}
		}
		rep(i,7)add_edge(n+i,t,m);
		if(ford_fulkerson(s,t)==out)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}
accuracy: 1
time_ms: 110
memory_kb: 1380
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

static const ll INF = 1000000000000000ll;

#define MAX_V 1000
// Dinic http://www.prefield.com/algorithm/graph/dinic.html
struct dinic{
  struct edge{int to;ll cost;};
  int n;
  vector< vector<edge> > G;
  vector<vl> flow, capacity;
#define RESIDUE(s,t) (capacity[s][t]-flow[s][t])
  vi level;
  vector<bool> finished;
  dinic(int _n){
    n = _n;
    G.assign(n,vector<edge>());
    flow.assign(n,vl(n,0));
    capacity.assign(n,vl(n,0));
    level.assign(n,0);
    finished.assign(n,false);
  }
  void add_edge(int from,int to,ll cost){
    assert(0<=from && from<n);
    assert(0<=to && to<n);
    G[from].push_back((edge){to,cost});
    G[to].push_back((edge){from,0ll});  // ?????????????????????????????????????????????
  }
  ll dfs(int u, int t, ll cur){
    if(u==t || cur==0) return cur;
    if(finished[u]) return 0;
    finished[u] = true;
    REP(i,G[u].size()){
      edge e = G[u][i];
      if(level[e.to] > level[u]){
        ll f = dfs(e.to, t, min(cur, RESIDUE(u,e.to)));
        if(f>0){
          flow[u][e.to] += f;
          flow[e.to][u] -= f;
          finished[u] = false;
          return f;
        }
      }
    }
    return 0;
  }
  ll calc(int s, int t){
    REP(i,n)REP(j,n)flow[i][j]=capacity[i][j]=0;
    REP(u,n)REP(j,G[u].size()){
      edge e = G[u][j];
      capacity[u][e.to] += e.cost;
    }
    ll total = 0;
    while(true){
      REP(i,n)level[i] = -1;
      level[s] = 0;
      queue<int> Q; Q.push(s);
      int d = n;
      while(!Q.empty()){
        int u = Q.front(); Q.pop();
        REP(i,G[u].size()){
          edge e = G[u][i];
          if(RESIDUE(u,e.to) > 0 && level[e.to] == -1){
            Q.push(e.to);
            level[e.to] = level[u] + 1;
          }
        }
      }
      REP(i,n)finished[i]=false;
      bool flag = false;
      while(true){
        ll f = dfs(s,t,INF);
        if(f==0)break;
        total += f;
        flag = true;
      }
      if(!flag)break;
    }
    return total;
  }
};

int main(){
  map<string,int> mp;
  mp["Monday"] = 0;
  mp["Tuesday"] = 1;
  mp["Wednesday"] = 2;
  mp["Thursday"] = 3;
  mp["Friday"] = 4;
  mp["Saturday"] = 5;
  mp["Sunday"] = 6;
  while(true){
    int n;
    ll w;
    cin>>n>>w;
    if(!n)break;
    dinic D(1+7+n+1);
    int src = n;
    int dst = n+1;
    int week[7];
    REP(i,7){
      week[i] = n+2+i;
      D.add_edge(src,week[i],w);
    }
    ll sum = 0;
    REP(i,n){
      ll t;
      int c;
      cin>>t>>c;
      sum += t;
      while(c--){
        string s;
        cin>>s;
        assert(mp.count(s)==1);
        int d = mp[s];
        D.add_edge(week[d],i,INF);
      }
      D.add_edge(i,dst,t);
    }
    ll flow = D.calc(src,dst);
    if(flow==sum){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1388
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using ll = long long;
#define int ll
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
using vi = vector<int>;
const ll inf = 1L << 50;

class dinic{
	public :
		void init(int _n){
			n=_n;
			G.resize(n);
			iter.resize(n);
			level.resize(n);
		}

		void add_edge(int from,int to ,int cap){
			G[from].push_back((edge){to,cap, (int)G[to].size()});
			G[to].push_back((edge){from,0, (int)G[from].size()-1});
		}
	
		void add_edge_both(int from,int to ,int cap){
			add_edge(from,to,cap);
			add_edge(to,from,cap);
		}
	
		int max_flow(int s,int t){
			int flow=0;
			for(;;){
				bfs(s);
				if(level[t]<0) return flow;
				iter.assign(n,0);
				int f;
				while((f=dfs(s,t,DINIC_INF))>0){
					flow+=f;
				}
			}
		}
	private:
	
		int n;
		struct edge{int to,cap,rev;};
		static const int DINIC_INF = inf;
		vector< vector<edge> > G;
		vi level;
		vi iter;
	
		void bfs(int s){
			level.assign(n,-1);
			queue<int> que;
			level[s]=0;
			que.push(s);
			while(!que.empty()){
				int v=que.front();que.pop();
				for(int i=0;i< (int)G[v].size(); i++){
					edge &e=G[v][i];
					if(e.cap>0 && level[e.to] <0){
						level[e.to]=level[v]+1;
						que.push(e.to);
					}
				}
			}
		}

		int dfs(int v,int t,int f){
			if(v==t) return f;
			for(int &i=iter[v];i<(int)G[v].size();i++){
				edge &e= G[v][i];
				if(e.cap>0 && level[v]<level[e.to]){
					int d=dfs(e.to,t,min(f,e.cap));
					if(d>0){
						e.cap -=d;
						G[e.to][e.rev].cap+=d;
						return d;
					}
				}
			}
			return 0;
		}	
};

map<string, int> s2i;
vector<string> T = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

signed main(void){
    rep(i, 7) s2i[T[i]] = i + 1;

    for(int n, w; cin >> n >> w, n;){
        dinic d;
        d.init(n + 9);

        range(i, 1, 8){
            d.add_edge(0, i, w);
        }

        int sum = 0;
        rep(i, n){
            int t, c; cin >> t >> c;
            sum += t;
            d.add_edge(9 + i, 8, t);
            rep(_, c){
                string in; cin >> in;
                int v = s2i[in];
                d.add_edge(v, 9 + i, inf);
            }
        }

        if(d.max_flow(0, 8) == sum){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3272
final_rank: 18

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_GN = MAX_N + 9;

const long long LLINF = 1LL << 62;

const string wdnames[] = {
  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};

/* typedef */

typedef long long ll;

struct Edge {
  int ui, vi;
  ll c;
  Edge(int _ui, int _vi, ll _c): ui(_ui), vi(_vi), c(_c) {}
};

typedef vector<Edge> ve;

/* global variables */

int n, gn, st, gl;
ll w, sumti;
map<string,int> wdnhash;
ve nbrs[MAX_GN];
ll minfs[MAX_GN], flows[MAX_GN][MAX_GN];
int prvs[MAX_GN];

/* subroutines */

/* main */

int main() {
  for (int i = 0; i < 7; i++) wdnhash[wdnames[i]] = i;

  for (;;) {
    cin >> n >> w;
    if (n == 0) break;

    gn = n + 9;
    st = n + 7;
    gl = n + 8;

    for (int i = 0; i < gn; i++) nbrs[i].clear();
    sumti = 0;
    
    for (int i = 0; i < n; i++) {
      ll ti;
      int ci;
      cin >> ti >> ci;

      sumti += ti;
      nbrs[st].push_back(Edge(st, i, ti));

      for (int j = 0; j < ci; j++) {
	string wdname;
	cin >> wdname;
	int wj = n + wdnhash[wdname];

	nbrs[i].push_back(Edge(i, wj, LLINF));
	nbrs[wj].push_back(Edge(wj, i, 0));
      }
    }

    for (int i = 0; i < 7; i++)
      nbrs[n + i].push_back(Edge(n + i, gl, w));

    memset(flows, 0, sizeof(flows));
    ll max_flow = 0;

    for (;;) {
      //printf("max_flow = %lld\n", max_flow);

      memset(prvs, -1, sizeof(prvs));
      prvs[st] = st;
      minfs[st] = LLINF;

      queue<int> q;
      q.push(st);

      while (! q.empty()) {
	int ui = q.front(); q.pop();

	if (ui == gl) break;

	ve& nbru = nbrs[ui];
	for (ve::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	  int vi = vit->vi;
	  ll vc = vit->c - flows[ui][vi];
	  if (prvs[vi] < 0 && vc > 0) {
	    prvs[vi] = ui;
	    minfs[vi] = (minfs[ui] < vc) ? minfs[ui] : vc;
	    q.push(vi);
	  }
	}
      }

      if (prvs[gl] < 0) break;
      ll min_flow = minfs[gl];

      for (int j = gl; j != st;) {
	int i = prvs[j];
	flows[i][j] += min_flow;
	flows[j][i] -= min_flow;
	j = i;
      }

      max_flow += min_flow;
    }

    cout << (max_flow >= sumti ? "Yes" : "No") << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1428
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

constexpr long long Inf = numeric_limits<long long>::max() / 4;
typedef long long ll;

namespace flow_algorithm
{
  template<class Flow>
  struct edge
  {
    int to;
    Flow cap, rev;
  };
  
  /*
  template<class Flow>
  using edges = vector<edge<Flow>>;
  
  template<class Flow>
  using graph = vector<edges<Flow>>;
  */
  typedef vector<edge<ll>> edges;
  typedef vector<edges> graph;
  
  template<class Flow>
  class ford_fulkerson
  {
  private:
    
    int V;
    //    graph<Flow> g;
    graph g;
    vector<bool> used;
    
    //   Flow static constexpr Inf = numeric_limits<Flow>::max() / 4;
    
  private:
    
    Flow dfs(int curr, int tar, Flow flow) {
      if(curr == tar) { return flow; }
      used[curr] = true;
      rep(i, g[curr].size()) {
        edge<Flow>& e = g[curr][i];
        if(!used[e.to] && e.cap > 0) {
          Flow d = dfs(e.to, tar, min(flow, e.cap));
          if(d <= 0) { continue; }
          e.cap -= d;
          g[e.to][e.rev].cap += d;
          return d;
        }
      }
      return 0;
    }
    
  public:
    
    ford_fulkerson(int V_)
    {
      V = V_;
      g.resize(V_);
      used.resize(V_);
    }
    
    void add_edge(int from, int to, Flow cap)
    {
      g[from].push_back({to, cap, (Flow)g[to].size()});
      g[to].push_back({from, 0, (Flow)g[from].size()-1});
    }
    
    Flow max_flow(int s, int t)
    {
      Flow ret = 0;
      for(;;) {
        rep(i, V) used[i] = false;
        Flow f = dfs(s, t, Inf);
        if(f == 0) { return ret; }
        ret += f;
      }
    }
    
  };
}

int const SBASE = 10;
int const SRC = 150, SINK = 151;

int main() {
  
  map<string, int> mp = {
    {"Monday",0},
    {"Tuesday", 1},
    {"Wednesday", 2},
    {"Thursday", 3},
    {"Friday", 4},
    {"Saturday", 5},
    {"Sunday", 6}
  };
  
  int N; ll W;
  while(cin >> N >> W && (N|W)) {
    flow_algorithm::ford_fulkerson<ll> ff(200);
    
    rep(i, 7) ff.add_edge(SRC, i, W);
    
    ll need = 0;
    
    rep(i, N) {
      ll t; int c; cin >> t >> c;
      need += t;
      rep(j, c) {
        string s; cin >> s;
        //        dn.add_edge(mp[s], SBASE+i, flow_algorithm::dinic<ll>::Inf);
        ff.add_edge(mp[s], SBASE+i, Inf);
      }
      ff.add_edge(SBASE+i, SINK, t);
    }
    
    cout << ( ff.max_flow(SRC, SINK) == need ? "Yes" : "No" ) << endl;
    
  }
  
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 1288
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

constexpr long long Inf = numeric_limits<long long>::max() / 4;

namespace flow_algorithm
{
  template<class Flow>
  struct edge
  {
    int to;
    Flow cap, rev;
  };
  /*
  template<class Flow>
  using edges = vector<edge<Flow>>;
  
  template<class Flow>
  using graph = vector<edges<Flow>>;
  */
  
  typedef vector<edge<long long>> edges;
  typedef vector<edges> graph;
  
  template<class Flow>
  class dinic
  {
  private:
    int V;
    //    graph<Flow> g;
    graph g;
    vector<int> level;
    vector<int> iter;
    
  public:
    
    //    Flow static constexpr Inf = numeric_limits<Flow>::max() / 4;
    
  private:
    
    void bfs(int s)
    {
      rep(i, V) level[i] = -1;
      queue<int> q;
      q.push(s);
      level[s] = 0;
      while(!q.empty()) {
        int curr = q.front(); q.pop();
        rep(i, g[curr].size()) {
          edge<Flow>& e = g[curr][i];
          if(level[e.to] != -1) { continue; }
          if(e.cap <= 0) { continue; }
          level[e.to] = level[curr] + 1;
          q.push(e.to);
        }
      }
    }
    
    Flow dfs(int curr, int tar, Flow flow)
    {
      if(curr == tar) { return flow; }
      for(int &i = iter[curr]; i<(int)g[curr].size(); i++) {
        edge<Flow>& e = g[curr][i];
        if(e.cap <= 0) { continue; }
        if(level[curr] >= level[e.to]) { continue; }
        Flow d = dfs(e.to, tar, min(flow, e.cap));
        if(d <= 0) { continue; }
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
      return 0;
    }
    
  public:
    
    dinic(int V_)
    {
      V = V_;
      g.resize(V);
      level.resize(V);
      iter.resize(V);
    }
    
    void add_edge(int from, int to, Flow cap)
    {
      g[from].push_back({to, cap, (Flow)g[to].size()});
      g[to].push_back({from, 0, (Flow)g[from].size()-1});
    }
    
    Flow max_flow(int src, int dest)
    {
      Flow flow = 0;
      for(;;) {
        bfs(src);
        if(level[dest] < 0) { return flow; }
        rep(i, V) iter[i] = 0;
        Flow f;
        while((f = dfs(src, dest, Inf)) > 0) {
          flow += f;
        }
      }
    }
    
  };
  
  
}

typedef long long ll;

int const SBASE = 10;
int const SRC = 150, SINK = 151;

int main() {
  
  map<string, int> mp = {
    {"Monday",0},
    {"Tuesday", 1},
    {"Wednesday", 2},
    {"Thursday", 3},
    {"Friday", 4},
    {"Saturday", 5},
    {"Sunday", 6}
  };
  
  int N; ll W;
  while(cin >> N >> W && (N|W)) {
    flow_algorithm::dinic<ll> dn(200);
    
    rep(i, 7) dn.add_edge(SRC, i, W);
    
    ll need = 0;
    
    rep(i, N) {
      ll t; int c; cin >> t >> c;
      need += t;
      rep(j, c) {
        string s; cin >> s;
        //        dn.add_edge(mp[s], SBASE+i, flow_algorithm::dinic<ll>::Inf);
        dn.add_edge(mp[s], SBASE+i, Inf);
      }
      dn.add_edge(SBASE+i, SINK, t);
    }
    
    cout << ( dn.max_flow(SRC, SINK) == need ? "Yes" : "No" ) << endl;
    
  }
  
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1292
final_rank: 2

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct edge{
  int to;
  long long cap;
  int rev;
};

vector<vector<edge> > G;
bool used[109];

void add_edge(int from,int to,long long cap){
  G[from].push_back({to,cap,(int)G[to].size()});
  G[to].push_back({from,0,(int)G[from].size()-1});
}

long long dfs(int v,int t,long long f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      long long d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

long long max_flow(int s,int t){
  long long flow=0;
  for(;;){
    fill(begin(used),end(used),false);
    long long f=dfs(s,t,1LL<<62);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(){
  for(long long N,W;cin>>N>>W,N;){
    G=vector<vector<edge> >(109);
    for(int i=0;i<7;i++){
      add_edge(107,100+i,W);
    }
    long long tsum=0;
    for(int i=0;i<N;i++){
      long long t,c;
      cin>>t>>c;
      tsum+=t;
      while(c--){
	char dow[99];
	cin>>dow;
	add_edge(100+(
		 (dow[0]=='S')?(dow[1]=='u')?0:1:
		 (dow[0]=='M')?2:
		 (dow[0]=='T')?(dow[1]=='u')?3:4:
		 (dow[0]=='W')?5:6),i,1LL<<62);
      }
      add_edge(i,108,t);
    }
    cout<<((max_flow(107,108)==tsum)?"Yes":"No")<<endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 1252
final_rank: 8

code_snippet: #include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;

const int N = 1000 + 10;

int n;
long long w;

int convert(char *x)
{
	if (x[0] == 'S') {
		if (x[1] == 'u') return 0;
		return 6;
	} else if (x[0] == 'T') {
		if (x[1] == 'u') return 2;
		return 4;
	} else if (x[0] == 'M') {
		return 1;
	} else if (x[0] == 'W') {
		return 3;
	}
	return 5;
	assert(0);
}

void read(long long &x)
{
	char ch;
	for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar());
	for(x = 0; ch >= '0' && ch <= '9'; ch = getchar())
		x = x * 10 + ch - '0';
}

int id[N];
long long a[N];
int s[N];

void solve()
{
	int cnt;
	char buf[10];
	for(int i = 0; i < n; ++ i) {
		read(a[i]);
		scanf("%d", &cnt);
		s[i] = 0;

		for( ; cnt --; ) {
			scanf("%s", buf);
			int x = convert(buf);
			s[i] |= (1 << x);
		}
	}
	int flag = true;
	for(int t = 0; t < (1 << 7); ++ t) {
		long long tmp = 0;
		for(int i = 0; i < n; ++ i) {
			if ((s[i] | t) == t) {
				tmp += a[i];
			}
		}
		int x = 0;
		for(int tmp = t; tmp; tmp -= tmp & -tmp)
			++ x;
		if (tmp > x * w) {
			flag = false;
			break;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
}

int main()
{
	for( ; cin >> n >> w && (n || w); ) {
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1256
final_rank: 1