#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int n,k;

int a[1000000+5], b[1000000+5];

int mt[1000000+5];

bool used[1000000+5];

vector<vector<pair<int, int> > > d;

bool try_kuhn(int v, int l)
{
    if (used[v]) return false;
    used[v]=true;
    for (int i=0; i<d[v].size(); i++)
    {
        if (d[v][i].second>l) continue;
        int to=d[v][i].first;
        if (mt[to]==-1 || try_kuhn(mt[to],l))
        {
            mt[to]=v;
            return true;
        }
    }
}

bool check(int l)
{
    for (int i=0; i<k; i++)
    {
        mt[i]=-1;
    }
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            used[j]=false;
        }
        try_kuhn(i,l);
    }
    int cnt=0;
    for (int i=0; i<k; i++)
    {
        if (mt[i]!=-1) cnt++;
    }
    return cnt==n;
}

int binsearch(int l, int r)
{
    if (l==r) return l;
    if (l+1==r)
    {
        if (check(l)) return l;
        else return r;
    }
    int m=(l+r)/2;
    if (check(m)) return binsearch(l,m);
    else return binsearch(m,r);
}

int main()
{
    int p;
    cin>>n>>k>>p;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for (int i=0; i<k; i++)
    {
        cin>>b[i];
    }
    d.resize(n);
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<k; j++)
        {
            int dst=abs(b[j]-a[i])+abs(b[j]-p);
            d[i].push_back({j,dst});
            //cout<<i<<" "<<j<<" "<<dst<<endl;
        }
    }
    int ans=binsearch(1,1000000000);
    cout<<ans;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long

int n,k;

int a[1000000+5], b[1000000+5];

int mt[1000000+5];

bool used[1000000+5];

bool used1[1000000+5];

vector<vector<pair<int, int> > > d;

bool try_kuhn(int v, int l)
{
    if (used[v]) return false;
    used[v]=true;
    for (int i=0; i<d[v].size(); i++)
    {
        if (d[v][i].second>l) continue;
        int to=d[v][i].first;
        if (mt[to]==-1 || try_kuhn(mt[to],l))
        {
            mt[to]=v;
            return true;
        }
    }
    return false;
}

bool check(int l)
{
    for (int i=0; i<k; i++)
    {
        mt[i]=-1;
    }
    for (int i=0; i<n; i++)
    {
        used1[i]=false;
    }
    for (int i=0; i<n; i++)
    {
        for (auto j:d[i])
        {
            if (j.second>l) continue;
            if (mt[j.first]==-1)
            {
                mt[j.first]=i;
                used1[i]=true;
                break;
            }
        }
    }
    for (int i=0; i<n; i++)
    {
        if (used1[i]) continue;
        for (int j=0; j<n; j++)
        {
            used[j]=false;
        }
        try_kuhn(i,l);
    }
    int cnt=0;
    for (int i=0; i<k; i++)
    {
        if (mt[i]!=-1) cnt++;
    }
    return cnt==n;
}

int binsearch(int l, int r)
{
    if (l==r) return l;
    if (l+1==r)
    {
        if (check(l)) return l;
        else return r;
    }
    int m=(l+r)/2;
    if (check(m)) return binsearch(l,m);
    else return binsearch(m,r);
}

main()
{
    int p;
    cin>>n>>k>>p;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for (int i=0; i<k; i++)
    {
        cin>>b[i];
    }
    d.resize(n);
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<k; j++)
        {
            int dst=abs(b[j]-a[i])+abs(b[j]-p);
            d[i].push_back({j,dst});
        }
    }
    int ans=binsearch(1,1000000000000000000LL);
    cout<<ans;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int n,k;

int a[1000000+5], b[1000000+5];

int mt[1000000+5];

bool used[1000000+5];

bool used1[1000000+5];

vector<vector<pair<int, int> > > d;

bool try_kuhn(int v, int l)
{
    if (used[v]) return false;
    used[v]=true;
    for (int i=0; i<d[v].size(); i++)
    {
        if (d[v][i].second>l) continue;
        int to=d[v][i].first;
        if (mt[to]==-1 || try_kuhn(mt[to],l))
        {
            mt[to]=v;
            return true;
        }
    }
}

bool check(int l)
{
    for (int i=0; i<k; i++)
    {
        mt[i]=-1;
    }
    for (int i=0; i<n; i++)
    {
        used1[i]=false;
    }
    for (int i=0; i<n; i++)
    {
        for (auto j:d[i])
        {
            if (j.second>l) continue;
            if (mt[j.first]==-1)
            {
                mt[j.first]=i;
                used1[i]=true;
                break;
            }
        }
    }
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            used[j]=false;
        }
        try_kuhn(i,l);
    }
    int cnt=0;
    for (int i=0; i<k; i++)
    {
        if (mt[i]!=-1) cnt++;
    }
    return cnt==n;
}

int binsearch(int l, int r)
{
    if (l==r) return l;
    if (l+1==r)
    {
        if (check(l)) return l;
        else return r;
    }
    int m=(l+r)/2;
    if (check(m)) return binsearch(l,m);
    else return binsearch(m,r);
}

int main()
{
    int p;
    cin>>n>>k>>p;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for (int i=0; i<k; i++)
    {
        cin>>b[i];
    }
    d.resize(n);
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<k; j++)
        {
            int dst=abs(b[j]-a[i])+abs(b[j]-p);
            d[i].push_back({j,dst});
            //cout<<i<<" "<<j<<" "<<dst<<endl;
        }
    }
    int ans=binsearch(1,1000000000);
    cout<<ans;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long

int n,k;

int a[1000000+5], b[1000000+5];

int mt[1000000+5];

bool used[1000000+5];

bool used1[1000000+5];

vector<vector<pair<int, int> > > d;

bool try_kuhn(int v, int l)
{
    if (used[v]) return false;
    used[v]=true;
    for (int i=0; i<d[v].size(); i++)
    {
        if (d[v][i].second>l) continue;
        int to=d[v][i].first;
        if (mt[to]==-1 || try_kuhn(mt[to],l))
        {
            mt[to]=v;
            return true;
        }
    }
    return false;
}

bool check(int l)
{
    for (int i=0; i<k; i++)
    {
        mt[i]=-1;
    }
    for (int i=0; i<n; i++)
    {
        used1[i]=false;
    }
    for (int i=0; i<n; i++)
    {
        for (auto j:d[i])
        {
            if (j.second>l) continue;
            if (mt[j.first]==-1)
            {
                mt[j.first]=i;
                used1[i]=true;
                break;
            }
        }
    }
    for (int i=0; i<n; i++)
    {
        if (used1[i]) continue;
        for (int j=0; j<n; j++)
        {
            used[j]=false;
        }
        try_kuhn(i,l);
    }
    int cnt=0;
    for (int i=0; i<k; i++)
    {
        if (mt[i]!=-1) cnt++;
    }
    return cnt==n;
}

int binsearch(int l, int r)
{
    if (l==r) return l;
    if (l+1==r)
    {
        if (check(l)) return l;
        else return r;
    }
    int m=(l+r)/2;
    if (check(m)) return binsearch(l,m);
    else return binsearch(m,r);
}

main()
{
    int p;
    cin>>n>>k>>p;
    for (int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for (int i=0; i<k; i++)
    {
        cin>>b[i];
    }
    d.resize(n);
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<k; j++)
        {
            int dst=abs(b[j]-a[i])+abs(b[j]-p);
            d[i].push_back({j,dst});
        }
    }
    int ans=binsearch(0,1000000000000000000LL);
    cout<<ans;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool check(const long long t, const vector<long long> & a, const vector<long long> & b, const long long p) {
    // vector<bool> used(b.size(), false);
    vector<pair<long long, long long> > right;
    for (size_t ptr = 0; ptr < a.size(); ++ptr) {
        long long togo = (t - abs(a[ptr] - p));
        if (togo < 0) {
            return false;
        } else {
            togo = togo / 2;
        }
        //left.emplace_back(max(p + togo, a[ptr] + togo));
        right.push_back(pair<long long, long long>(min(p - togo, a[ptr] - togo), max(p + togo, a[ptr] + togo)));
    }
    /*
    for (long long i = 0; i < b.size(); ++i) {
        right.emplace_back(b[i], 2);
    }*/
    sort(right.begin(), right.end());
    //sort(left.begin(), left.end());
    //long long forbidden = upper_bound(b.begin(), b.end(), right[0] - t - 1) - b.begin();
    long long balance = 0;
    long long ptr = -1;
    for (size_t i = 0; i < a.size(); ++i) {
        /*if (upper_bound(b.begin(), b.end(), right[i]) - b.begin() <= forbidden + i) {
            return false;
        }*/
        long long leftmostkey = lower_bound(b.begin(), b.end(), right[i].first) - b.begin();
        long long rightmostkey = upper_bound(b.begin(), b.end(), right[i].second) - b.begin() - 1;
        if (rightmostkey >= leftmostkey && ptr + 1 <= rightmostkey) {
            ptr = max(leftmostkey, ptr + 1);
        } else {
            return false;
        }
    }
    return true;
}

int main()
{
    long long n, k, p;
    vector<long long> a, b;
    cin >> n >> k >> p;
    long long bb;
    for (long long i = 0; i < n; ++i) {
        cin >> bb;
        a.push_back(bb);
    }
    for (long long i = 0; i < k; ++i) {
        cin >> bb;
        b.push_back(bb);
    }
    sort(b.begin(), b.end());
    sort(a.begin(), a.end());
	long long l = -1, r = 2 * 1000 * 1000 * 1000 + 3, t;
	while (r - l > 1) {
        t = (r + l) / 2;
        if (check(t, a, b, p)) {
            r = t;
        } else {
            l = t;
        }
	}
	cout << r << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool check(const long long t, const vector<long long> & a, const vector<long long> & b, const long long p) {
    // vector<bool> used(b.size(), false);
    vector<pair<long long, long long> > right;
    for (size_t ptr = 0; ptr < a.size(); ++ptr) {
        long long togo = (t - abs(a[ptr] - p));
        if (togo < 0) {
            return false;
        } else {
            togo = togo / 2;
        }
        //left.emplace_back(max(p + togo, a[ptr] + togo));
        right.push_back(pair<long long, long long>(min(p - togo, a[ptr] - togo), max(p + togo, a[ptr] + togo)));
    }
    /*
    for (long long i = 0; i < b.size(); ++i) {
        right.emplace_back(b[i], 2);
    }*/
    sort(right.begin(), right.end());
    //sort(left.begin(), left.end());
    //long long forbidden = upper_bound(b.begin(), b.end(), right[0] - t - 1) - b.begin();
    long long balance = 0;
    long long ptr = -1;
    for (size_t i = 0; i < a.size(); ++i) {
        /*if (upper_bound(b.begin(), b.end(), right[i]) - b.begin() <= forbidden + i) {
            return false;
        }*/
        long long leftmostkey = lower_bound(b.begin(), b.end(), right[i].first) - b.begin();
        long long rightmostkey = lower_bound(b.begin(), b.end(), right[i].second) - b.begin();
        if (rightmostkey >= leftmostkey && ptr + 1 <= rightmostkey) {
            ptr = max(leftmostkey, ptr + 1);
        } else {
            return false;
        }
    }
    return true;
}

int main()
{
    long long n, k, p;
    vector<long long> a, b;
    cin >> n >> k >> p;
    long long bb;
    for (long long i = 0; i < n; ++i) {
        cin >> bb;
        a.push_back(bb);
    }
    for (long long i = 0; i < k; ++i) {
        cin >> bb;
        b.push_back(bb);
    }
    sort(b.begin(), b.end());
    sort(a.begin(), a.end());
	long long l = -1, r = 2 * 1000 * 1000 * 1000 + 3, t;
	while (r - l > 1) {
        t = (r + l) / 2;
        if (check(t, a, b, p)) {
            r = t;
        } else {
            l = t;
        }
	}
	cout << r << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a, q[100100];
int main() {
	int p = 0;
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		cin >> a;
		for(int j = 0; j < a; j++) {
			cin >> k[j];
		}
		sort(k, k + a);
		if(v > k[0]) {
			q[p] = a;
			p++;
		}
	}
	cout << p << endl;
	sort(q, q + p);
	for(int i = 0; i < p; i++) {
		cout << q[i] << " ";
	}
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a, q[100100];
int main() {
	int p = 0;
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		cin >> a;
		for(int j = 0; j < a; j++) {
			cin >> k[j];
		}
		sort(k, k + a);
		if(v > k[0]) {
			q[p] = i + 1;
			p++;
		}
	}
	cout << p << endl;
	sort(q, q + p);
	for(int i = 0; i < p; i++) {
		cout << q[i] << " ";
	}
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a[100100], p, q[100100];
int main() {
	cin >> n >> v;
	bool ch = false;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 1; j <= a[i]; j++) {
			cin >> k[j];
			if(v > k[j]) {
				if(p == 0) {
					q[p] = a[i];
					p++;
				} else {
					for(int l = 0; l < p; l++) {
						if(k[j] != q[p]) {
							ch = true;
						} else {
							ch = false;
							break;
						}
					}
					if(ch) {
						q[p] = a[i];
						p++;
						ch = false;

						q[p] = a[i];
						p++;
					}					}
						q[p] = a[i];
						p++;
				}

			}
		}
	}
	cout << p << endl;
	}*/
	if(p != 0) {
		for(int i = 0; i < p; i++) {
			cout << q[i] << " ";
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a[100100], p, q[100100];
int main() {
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 1; j <= a[i]; j++) {
			cin >> k[j];
			if(v > k[j]) {
				if(p == 0) {
					q[p] = a[i];
					p++;
				} else {
					for(int l = 0; l < p; l++) {
						if(k[j] != q[p]) {
							ch = true;
						} else {
							ch = false;
							break;
						}
					}
					if(ch) {
						q[p] = a[i];
						p++;
						ch = false;
					}
				}
			}
		}
	}
	cout << p << endl;
	sort(q, q + p);
	if(p != 0) {
		for(int i = 0; i < p; i++) {
			cout << q[i] << " ";
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a[100100], p, q[100100];
int main() {
	cin >> n >> v;
	bool ch = false;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 1; j <= a[i]; j++) {
			cin >> k[j];
			if(v > k[j]) {
				if(p == 0) {
					q[p] = a[i];
					p++;
				} else {
					for(int l = 0; l < p; l++) {
						if(k[j] != q[p]) {
							ch = true;
						} else {
							ch = false;
							break;
						}
					}
					if(ch) {
						q[p] = a[i];
						p++;
						ch = false;
					}
				}
			}
		}
	}
	cout << p << endl;
	sort(q, q + p);
	if(p != 0) {
		for(int i = 0; i < p; i++) {
			cout << q[i] << " ";
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a[100100], p, q[100100];
int main() {
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 0; j < a[i]; j++) {
			cin >> k[j];
			if(v > k[j]) {
				q[p] = i + 1;
				p++;
			}
		}
	}
	cout << p << endl;
	sort(q, q + p);
	if(p != 0) {
		for(int i = 0; i < p; i++) {
			cout << q[i] << " ";
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define ld long double
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
int n, v, k[100100], a[100100], p, q[100100], out[100100];
int main() {
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 1; j <= a[i]; j++) {
			cin >> k[j];
			if(v > k[j]) {
				q[p] = a[i];
				p++;
			}
		}
	}
	cout << p << endl;
	sort(q, q + p);
	/*out[0] = q[0];
	int counter = 1;
	for(int i = 1; i < p; i++) {
		if(q[i] > q[i - 1]) {
			out[counter] = q[i];
			counter++;
		}
	}*/
	if(p != 0) {
		for(int i = 0; i < p; i++) {
			cout << q[i] << " ";
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> ans;
int n, v;

int main() {
    cin >> n >> v;
    for(int i = 0; i < n; i++) {
        int k, price;
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> price;
            if(price + 1 <= v && ans[ans.size() - 1] != i + 1) {
                ans.push_back(i + 1);
            }
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> ans;
int n, v;

int main() {
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		int k, price;
		cin >> k;
		for(int j = 0; j < k; j++) {
			cin >> price;
			if(price + 1 <= v && ((ans.size() != 0 && ans[ans.size() - 1] != i + 1) || ans.size() == 0)) {
				ans.push_back(i + 1);
			}
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> ans;
int n, v;

int main() {
    cin >> n >> v;
    for(int i = 0; i < n; i++) {
        int k, price;
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> price;
            if(price + 1 <= v && ans.size() != 0 && ans[ans.size() - 1] != i + 1) {
                ans.push_back(i + 1);
            }
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> ans;
int n, v;

int main() {
	cin >> n >> v;
	for(int i = 0; i < n; i++) {
		int k, price;
		cin >> k;
		for(int j = 0; j < k; j++) {
			cin >> price;
			if(price + 1 <= v) {
				ans.push_back(i + 1);
				break;
			}
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


//GCD COMPLICATED
#include <iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<sstream>
#include<string>
#include<map>
#include<stack>
using namespace std;
int main() {
	#if !ONLINE_JUDGE
	freopen("input.in","r",stdin);
	freopen("output.out", "w", stdout);
	#endif
	int n, m;
	vector<int> x;
	cin >> n >> m;
	int c = 1;
	while(n > 0){
		int s, item, flg = 0;
		cin >> s;
		for(int i = 0; i < s ; i++){
			cin >> item;
			if(item < m)
				flg++;
		}
		if(flg)
			x.push_back(c++);
		n--;
	}
	cout << x.size() << endl;
	sort(x.begin(), x.end());
	for(int i = 0; i < x.size(); i++)
		if(i != x.size()-1)
			cout << x[i] << " ";
		else
			cout << x[i] << endl;
	return 0;
}


//GCD COMPLICATED
#include <iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<sstream>
#include<string>
#include<map>
#include<stack>
using namespace std;
int main() {
	#if !ONLINE_JUDGE
	freopen("input.in","r",stdin);
	freopen("output.out", "w", stdout);
	#endif
	int n, m;
	vector<int> x;
	cin >> n >> m;
	while(n > 0){
		int s, item, flg = 0;
		cin >> s;
		for(int i = 0; i < s ; i++){
			cin >> item;
			if(item < m)
				flg++;
		}
		if(flg)
			x.push_back(s);
		n--;
	}
	cout << x.size() << endl;
	sort(x.begin(), x.end());
	for(int i = 0; i < x.size(); i++)
		if(i != x.size()-1)
			cout << x[i] << " ";
		else
			cout << x[i] << endl;
	return 0;
}


#include <iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<sstream>
#include<string>
#include<map>
#include<stack>
using namespace std;
int main() {
	#if !ONLINE_JUDGE
	freopen("input.in","r",stdin);
	freopen("output.out", "w", stdout);
	#endif
	int n, m;
	vector<int> x;
	cin >> n >> m;
	int c = 1;
	while(n > 0){
		int s, item, flg = 0;
		cin >> s;
		for(int i = 0; i < s ; i++){
			cin >> item;
			if(item < m)
				flg++;
		}
		if(flg)
			x.push_back(c);
		n--;
		c++;
	}
	cout << x.size() << endl;
	sort(x.begin(), x.end());
	for(int i = 0; i < x.size(); i++)
		if(i != x.size()-1)
			cout << x[i] << " ";
		else
			cout << x[i] << endl;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int main()
{
    int n, c, ans[101], t = 0, v, k = 0;
    scanf("%d%d", &n, &c);
    while (cin >> v)
    {
        if (v < 101)
        {
            k = v;
        }
        else
        {
            if (v < c && (t == 0 || ans[t - 1] != k))
            {
                ans[t] = k;
                ++t;
            }
        }
    }
    printf("%d/n", t);
    for (int i = 0; i < t; ++i)
    {
        printf("%d ", ans[i]);
    }

}


#include <stdio.h>
#include <iostream>

using namespace std;
int main()
{
    int n, c, ans[101], t = 0, v, k = 0;
    scanf("%d%d", &n, &c);
    while (cin >> v)
    {
        if (v < 101)
        {
            k = v;
        }
        else
        {
            if (v < c && (t == 0 || ans[t - 1] != k))
            {
                ans[t] = k;
                ++t;
            }
        }
    }
    printf("%d\n", t);
    for (int i = 0; i < t; ++i)
    {
        printf("%d ", ans[i]);
    }

}


#include <stdio.h>
#include <algorithm>

using namespace std;
int main()
{
    int n, c, ans[101], t = 0, v, k = 0;
    scanf("%d%d", &n, &c);

    for (int i = 0; i < n; ++i)
    {
        int m;
        scanf ("%d", &m);
        for (int j = 0; j < m; ++j)
        {
            scanf ("%d", &k);
            if (k < c && (t == 0 || ans[t - 1] != i + 1))
            {
                ans[t] = i + 1;
                ++t;
            }
        }
    }
    printf("%d\n", t);
    for (int i = 0; i < t; ++i)
    {
        printf("%d ", ans[i]);
    }

}


#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
int main()
{
    int n, c, ans[101], t = 0, v, k = 0;
    scanf("%d%d", &n, &c);
    while (cin >> v)
    {
        if (v < 101)
        {
            k = v;
        }
        else
        {
            if (v < c && (t == 0 || ans[t - 1] != k))
            {
                ans[t] = k;
                ++t;
            }
        }
    }
    printf("%d\n", t);
    sort(ans, ans + t);
    for (int i = 0; i < t; ++i)
    {
        printf("%d ", ans[i]);
    }

}


#include <iostream>
using namespace std;
int n , money , k , x , num , seller[50];
bool token;
int main()
{
    cin >> n >> money ;
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> x;
            if (x < money && !token)
            {
                seller[num++] = i+1;
                token = true;
            }
        }
    }
    cout << num << endl;
    for (int i = 0; i < num; i++)
        cout << seller[i] << ' ';
    return 0;
}


#include <iostream>
using namespace std;
int n , money , k , x , num , seller[50];
int main()
{
    cin >> n >> money ;
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> x;
            if (x < money && !seller[num])
                seller[num++] = i+1;
        }
    }
    cout << num << endl;
    for (int i = 0; i < num; i++)
        cout << seller[i] << ' ';
    return 0;
}


#include <iostream>
using namespace std;
int n , money , k , x , num , seller[50];
bool token;
int main()
{
    cin >> n >> money ;
    for (int i = 0; i < n; i++)
    {
        token = false;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> x;
            if (x < money && !token)
            {
                seller[num++] = i+1;
                token = true;
            }
        }
    }
    cout << num << endl;
    for (int i = 0; i < num; i++)
        cout << seller[i] << ' ';
    return 0;
}


// 441A.cpp : Defines the entry point for the console application.
//

#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	bool *b = new bool[n];
	for (int i = 0; i < n; i++)
		b[i] = 0;
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		int m;
		cin >> m;
		int *a = new int[m];
		for (int j = 0; j < m; j++)
		{
			cin >> a[j];
			if (a[j] < k)
			{
				b[i] = 1;
			}
		}
		if (b[i])
			c++;
	}
	cout << c << endl;
	for (int i = 0; i < n; i++)
		if (b[i])
			cout << i + 1 << " ";
    return 0;
}


// 441A'.cpp : Defines the entry point for the console application.
//
/* In thee name of ALLAH */
#include<iostream>
using namespace std;
struct seller
{
	bool a;
	seller ()
	{
		a = 0;
	}
};
int main()
{
	int n, v;
	cin >> n >> v;
	seller *x = new seller[n];
	int q =0;
	int c = 0;
	while (q!=n)
	{
		int s;
		cin >> s;
		for (int i = 0; i < s; i++)
		{
			int k;
			cin >> k;
			if (k < v&&!x[q].a)
			{
				x[q].a = 1;
				c++;
			}
		}
		q++;
	}
	cout << c << endl;
	for (int i = 0; i < n; i++)
	{
		if (x[i].a)
			cout << i + 1 << " ";
	}
//	system("pause");
    return 0;
}


// 441A.cpp : Defines the entry point for the console application.
//

#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	bool *b = new bool[n];
	for (int i = 0; i < n; i++)
		b[i] = 0;
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		int m;
		cin >> m;
		int *a = new int[m];
		for (int j = 0; j < m; j++)
		{
			cin >> a[j];
			if (a[j] < k)
			{
				c++;
				b[i] = 1;
			}
		}
	}
	cout << c << endl;
	for (int i = 0; i < n; i++)
		if (b[i])
			cout << i + 1 << " ";
    return 0;
}


// 441A'.cpp : Defines the entry point for the console application.
//
/* In the name of ALLAH */
#include<iostream>
using namespace std;
struct seller
{
	bool a;
	seller ()
	{
		a = 0;
	}
};
int main()
{
	int n, v;
	cin >> n >> v;
	seller *x = new seller[n];
	int q =0;
	int c = 0;
	while (q!=n)
	{
		int s;
		cin >> s;
		for (int i = 0; i < s; i++)
		{
			int k;
			cin >> k;
			if (k < v)
			{
				x[q].a = 1;
				c++;
			}
		}
		q++;
	}
	cout << c << endl;
	for (int i = 0; i < n; i++)
	{
		if (x[i].a)
			cout << i + 1 << " ";
	}
//	system("pause");
    return 0;
}


#include "stdio.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#include <locale>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <ctime>
#include <sstream>
using namespace std;

int main(){
	int n, v,c=0,buf,buf2; cin >> n >> v;
	bool ok = false;
	int ans[51];
	for (int i = 0; i < n; i++){
		cin >> buf;
		for (int j = 0; j < buf; j++){
			cin >> buf2;
			if (buf2 < v){ ans[j] = 1; ok = true; }
		}
		if (ok)c++;
		ok = false;
	}
	cout << c << endl;
	for (int i = 0; i < n;i++){
	if (ans[i] == 1)
		cout << i + 1 << " ";
}
}


#include "stdio.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#include <locale>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <ctime>
#include <sstream>
using namespace std;

int main(){
	vector<int>ans;
	int n, v; cin >> n >> v;
	bool ok = false;
	for (int i = 1; i <= n; i++)
	{
		int buf,buf2; cin >> buf;
		for (int j = 1; j <= buf; j++){
			cin >> buf2;
			buf2 < v ? ok = !ok : ok;
		}
		ok ? ans.push_back(i):ok;
		ok = !ok;
	}
	cout << ans.size()<<endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
}


#include "stdio.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#include <locale>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <ctime>
#include <sstream>
using namespace std;

int main(){
	int n, v,c=0,buf,buf2; cin >> n >> v;
	bool ok = false;
	int ans[51];
	for (int i = 0; i < n; i++){
		cin >> buf;
		for (int j = 0; j < buf; j++){
			cin >> buf2;
			if (buf2 < v){ ans[j] = 1; ok = true; }
		}
		if (ok)c++;
		ok = false;
	}
	cout << c << endl;
	for (int i = 0; i < n;i++)
	if (ans[i] == 1)
		cout << i + 1 << " ";
}


#include "stdio.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#include <locale>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <ctime>
#include <sstream>
using namespace std;

int main(){
	vector<int>ans;
	long long  n, v; cin >> n >> v;
	bool ok = false;
	for (int i = 1; i <= n; i++)
	{
		long long  buf,buf2; cin >> buf;
		for (int j = 1; j <= buf; j++){
			cin >> buf2;
			buf2 < v ? ok = !ok : ok;
		}
		ok ? ans.push_back(i):ok;
		ok = false;
	}
	cout << ans.size()<<endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
}


#include "iostream"
#include <locale>
#include <array>
using namespace std;
int main(){
	vector<int>ans;
	int n, v; cin >> n >> v;
	bool ok = false;
	for (int i = 1; i <= n; i++)
	{
		int buf,buf2; cin >> buf;
		for (int j = 1; j <= buf; j++){
			cin >> buf2;
			buf2 < v ? ok = !ok : ok;
		}
		ok ? ans.push_back(i):ok;
		ok = !ok;
	}
	cout << ans.size()<<endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
}


#include "stdio.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#include <locale>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <ctime>
#include <sstream>
using namespace std;

int main(){
	vector<int>ans;
	long long  n, v; cin >> n >> v;
	bool ok = false;
	for (int i = 1; i <= n; i++)
	{
		long long  buf,buf2; cin >> buf;
		for (int j = 1; j <= buf; j++){
			cin >> buf2;
			if(buf2<v)ok=true;
		}
		ok ? ans.push_back(i):ok;
		ok = false;
	}
sort(ans.begin(),ans.end());
	cout << ans.size()<<endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n , v , x=0 , y=0 , z , v1;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=0 ; i<n ; i++)
{
	 bool d = false;
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(!d && v>v1)
         {
              x++;
              asd[y]=z;
              y++;
			   d = true;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0 , z , v1 , m;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=1 ; i<=n ; i++)
{
	m=0;
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(m==0 && v>v1)
         {
              x++;
              asd[y]=i;
              y++;
			   m=1;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0 , z , v1;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=0 ; i<n ; i++)
{
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(v1<v)
         {
              x++;
              asd[y]=z;
              y++;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n , v , x=0 , y=0 , z , v1;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=1 ; i<=n ; i++)
{
	 bool d = false;
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(!d && v>v1)
         {
              x++;
              asd[y]=i;
              y++;
			   d = true;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0;
    cin>>n>>v;
   int *arr = new int[n+1];
   int *v1 = new int[n+1];
  int *asd = new int[3000];
for(int i=0 ; i<n ; i++)
{
       cin>>arr[i];
for(int j=0 ; j<arr[i] ; j++)
{
   cin>>v1[j];
if(v1[j]<v)
{
   x++;
   asd[y]=arr[i];
   y++;
}
}
}
sort(asd , asd+y);
cout<<x<<"\n";
for(int i=0 ; i<y ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0;
    cin>>n>>v;
   int *arr = new int[n+1];
   int *v1 = new int[n+1];
  int *asd = new int[n+1];
for(int i=0 ; i<n ; i++)
{
       cin>>arr[i];
for(int j=0 ; j<arr[i] ; j++)
{
   cin>>v1[i];
if(v1[i]<v)
{
   x++;
   asd[y]=arr[i];
   y++;
}
}
}
sort(asd , asd+y);
cout<<x<<"\n";
for(int i=0 ; i<y ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n , v , x=0 , y=0 , z , v1;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=0 ; i<n ; i++)
{
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(v1<v)
         {
              x++;
              asd[y]=z;
              y++;
			  v=v1;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0;
    cin>>n>>v;
   int *arr = new int[n+1];
   int *v1 = new int[n+1];
  int *asd = new int[n+1];
for(int i=0 ; i<n ; i++)
{
       cin>>arr[i];
for(int j=0 ; j<arr[i] ; j++)
{
   cin>>v1[j];
if(v1[j]<v)
{
   x++;
   asd[y]=arr[i];
   y++;
}
}
}
sort(asd , asd+y);
cout<<x<<"\n";
for(int i=0 ; i<y-1 ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0 , z , v1;
    cin>>n>>v;
  int *asd = new int[3000];
for(int i=0 ; i<n ; i++)
{
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(v1<v)
         {
              x++;
              asd[y]=z;
              y++;
         }
}
}
sort(asd , asd+y);
cout<<x<<"\n";
for(int i=0 ; i<y ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n , v , x=0 , y=0 , v1;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=0 ; i<n ; i++)
{
	 bool d = false;
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(!d && v>v1)
         {
              x++;
              asd[y]=i;
              y++;
			   d = true;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n , v , x=0 , y=0 , z , v1;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=0 ; i<n ; i++)
{
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(v>v1)
         {
              x++;
              asd[y]=z;
              y++;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n , v , x=0 , y=0;
    cin>>n>>v;
   int *arr = new int[n+1];
   int *v1 = new int[n+1];
  int *asd = new int[n+1];
for(int i=0 ; i<n ; i++)
{
       cin>>arr[i];
for(int j=0 ; j<arr[i] ; j++)
{
   cin>>v1[j];
if(v1[j]<v)
{
   x++;
   asd[y]=arr[i];
   y++;
}
}
}
sort(asd , asd+y);
cout<<x<<"\n";
for(int i=0 ; i<y ; i++)
     cout<<asd[i]<<" ";
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n , v , x=0 , y=0 , z , v1 , n;
  int *asd = new int[3000];
  cin>>n>>v;
for(int i=1 ; i<=n ; i++)
{
	n=0;
       cin>>z;
for(int j=0 ; j<z ; j++)
{
     cin>>v1;
       if(n==0 && v>v1)
         {
              x++;
              asd[y]=i;
              y++;
			   n=1;
         }
}
}
sort(asd , asd+x);
cout<<x<<"\n";
for(int i=0 ; i<x ; i++)
     cout<<asd[i]<<" ";
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n;
	long s;
	cin>>n>>s;
	long **arr=new  long*[n];
	int *arr1=new int[n];
	int temp;
	for (int i=0;i<n;i++)
	{
		cin>>temp;
		arr1[i]=temp;
		arr[i]=new long[temp];
		for(int j=0;j<temp;j++)
		{
			cin>>arr[i][j];
		}
	}

	long * min=new long[n];
	int count=0;
	for (int k=0;k<n;k++)
	{
		min[k]=arr[k][0];
		for(int i=0;i<arr1[k];i++)
		{
			if (arr[k][i]<min[k])
				min[k]=arr[k][i];
		}
		if((s-min[k]-1)>=0)
		{
			count++;
		}
	}
	cout<<count<<'\n';
	for (int k=0;k<n;k++)
	if((s-min[k]-1)>=0)
	{
		cout<<k+1<<' ';
	}
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	long s;
	cin>>n>>s;
	long **arr=new  long*[n];
	int *arr1=new int[n];
	int temp;
	for (int i=0;i<n;i++)
	{
		cin>>temp;
		arr1[i]=temp;
		arr[i]=new long[temp];
		for(int j=0;j<temp;j++)
		{
			cin>>arr[i][j];
		}
	}

	long min;
	for (int k=0;k<n;k++)
	{
		min=arr[k][0];
		for(int i=0;i<arr1[k];i++)
		{
			if (arr[k][i]<min)
				min=arr[k][i];
		}
		if((s-min-1)>=0)
		{
			cout<<k+1;
			if (k<n-1)
				cout<<' ';
		}
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n;
	long s;
	cin>>n>>s;
	long **arr=new  long*[n];
	int *arr1=new int[n];
	int temp;
	for (int i=0;i<n;i++)
	{
		cin>>temp;
		arr1[i]=temp;
		arr[i]=new long[temp];
		for(int j=0;j<temp;j++)
		{
			cin>>arr[i][j];
		}
	}

	long * min=new long[n];
	int count=0;
	string str="";
	for (int k=0;k<n;k++)
	{
		min[k]=arr[k][0];
		for(int i=0;i<arr1[k];i++)
		{
			if (arr[k][i]<min[k])
				min[k]=arr[k][i];
		}
		if((s-min[k]-1)>=0)
		{
			count++;
		}
	}
	cout<<count<<'\n';
	for (int k=0;k<count;k++)
	if((s-min[k]-1)>=0)
	{
		cout<<k+1<<' ';
	}
	cout<<'\n'<<str;
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	long s;
	//int ss=0;
	cin>>n>>s;
	long **arr=new  long*[n];
	int *arr1=new int[n];
	int temp;
	for (int i=0;i<n;i++)
	{
		cin>>temp;
		arr1[i]=temp;
		arr[i]=new long[temp];
		for(int j=0;j<temp;j++)
		{
			cin>>arr[i][j];
		}
		//ss+=temp;
	}

	long min;
	for (int k=0;k<n;k++)
	{
		min=arr[k][0];
		for(int i=0;i<arr1[k];i++)
		{
			if (arr[k][i]<min)
				min=arr[k][i];
		}
		if((s-min-1)>0)
			cout<<k+1<<' ';
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n;
	long s;
	cin>>n>>s;
	long **arr=new  long*[n];
	int *arr1=new int[n];
	int temp;
	for (int i=0;i<n;i++)
	{
		cin>>temp;
		arr1[i]=temp;
		arr[i]=new long[temp];
		for(int j=0;j<temp;j++)
		{
			cin>>arr[i][j];
		}
	}

	long * min=new long[n];
	int count=0;
	for (int k=0;k<n;k++)
	{
		min[k]=arr[k][0];
		for(int i=0;i<arr1[k];i++)
		{
			if (arr[k][i]<min[k])
				min[k]=arr[k][i];
		}
		if((s-min[k]-1)>=0)
		{
			count++;
		}
	}
	cout<<count<<'\n';
	for (int k=0;k<n;k++)
	if((s-min[k]-1)>=0)
	{
		cout<<k+1<<' ';
	}
	system("pause");
	return 0;
}


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	int * number = new int[n];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;

	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	int * number = new int[n];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	long * number = new long[n+1];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				Flag = 1;
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		cout << Counter << endl;
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	int * number = new int[n];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		cout << Counter << endl;
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	int * number = new int[n];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;

	system("pause");
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	long * number = new long[n];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		cout << Counter << endl;
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	int * number = new int[n];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;

	//system("pause");
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	long * number = new long[n+1];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		cout << Counter << endl;
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;
	return 0;
		   }


#include <iostream>
#include<vector>
using namespace std;

int main() {

	int n;
	long Money;
	int n2;
	cin >> n >> Money;
	int Counter = 0;
	long * number = new long[n+1];
	int Flag = 0;
	long price;
	for (int i = 0; i < n; i++) {
		Flag = 0;
		cin >> n2;
		for (int j = 0; j < n2; j++) {
			cin >> price;
			if (!Flag && price < Money) {
				number[Counter] = i+1;
				Counter++;
										}

		 		   				     }
								}

	if (!Counter)
		cout << "0";
	else {
		cout << Counter << endl;
		for (int i = 0; i < Counter; i++)
			cout << number[i] << " ";
		 }
	cout << endl;
	return 0;
		   }


#include <iostream>
#include <vector>
#include <set>
#include <iterator>

using namespace std;

int main()
{
	int n,b;
	cin>>n>>b;
	set <int>v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		for(int j=0;j<x;j++)
		{
			int num;
			cin>>num;
			if(num<b)
			{
				v.insert(x);
			}
		}
	}
	cout<<v.size()<<endl;
	set <int>::iterator it;
	for(it=v.begin();it!=v.end();it++)
	{
		cout<<(*it)<<" ";
	}
	cout<<endl;

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n,b;
	cin>>n>>b;
	vector <int>v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		for(int j=0;j<x;j++)
		{
			int num;
			cin>>num;
			if(num<b)
			{
				v.push_back(x);
			}
		}
	}
	if(v.size()>0)
	{
		for(int i=0;i<v.size();i++)
		{
			cout<<v[i]<<" ";
		}
	}
	else
	{
		cout<<0;
	}
	cout<<endl;

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n,b;
	cin>>n>>b;
	vector <int>v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		for(int j=0;j<x;j++)
		{
			int num;
			cin>>num;
			if(num<b)
			{
				v.push_back(x);
			}
		}
	}
	cout<<v.size()<<endl;
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i]<<" ";
	}

	cout<<endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <iterator>

using namespace std;

int main()
{
	int n,b;
	cin>>n>>b;
	set <int>v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		for(int j=0;j<x;j++)
		{
			int num;
			cin>>num;
			if(num<b)
			{
				v.insert(i+1);
			}
		}
	}
	cout<<v.size()<<endl;
	set <int>::iterator it;
	for(it=v.begin();it!=v.end();it++)
	{
		cout<<(*it)<<" ";
	}
	cout<<endl;

	return 0;
}


#include<iostream>
using namespace std;
struct Seller
{
int* Items, Size;
};
//Function to Create Jagged Struct Data Structure.
void CreateAuction(Seller**&, int&,int&);
//Function to Traverse Auction and Find Sellers.
void FindSellers(Seller**, int,int);
//Function to Free Memory.
void DeleteAuction(Seller**&, int);
//Function incorporating Solution.
void Solution(void);
void main(void)
{
Solution();
}
void Solution(void)
{
int Size = 0,Bid = 0;
Seller** Auction = NULL;
    CreateAuction(Auction, Size,Bid);
      FindSellers(Auction, Size,Bid);
}
void FindSellers(Seller**Auction, int Size,int Bid)
{
int SellerCount = 0;
bool SellerFound = false;
   for (int X = 0; X < Size;++X)
   {
       for (int V = 0; V < Auction[X]->Size &&
                                      !SellerFound; ++V)
       {
           if (Bid > Auction[X]->Items[V])
           {
                SellerFound = !SellerFound;
                ++SellerCount;
           }
       }
         SellerFound = false;
   }
       cout << SellerCount<<endl;
        for (int X = 1; X <= SellerCount; ++X)
            cout << X << " ";
   cout << endl;
}
void CreateAuction(Seller**& Auction, int& Size,int& Bid)
{
  cin >> Size >> Bid;
   Auction = new Seller*[Size];
   for (int X = 0; X < Size; ++X)
   {
     Auction[X] = new Seller;
      cin >> Auction[X]->Size;
       Auction[X]->Items = new int[Auction[X]->Size];
         for (int V = 0; V < Auction[X]->Size; ++V)
         {
            cin >> Auction[X]->Items[V];
         }
   }
}
void DeleteAuction(Seller**&Auction, int Size)
{
    for (int X = 0; X < Size; ++X)
    {
        delete [] Auction[X]->Items;
        delete Auction[X];
    }
    delete [] Auction;
}


#include<iostream>
using namespace std;
struct Seller
{
int* Items, Size;
};
//Function to Create Jagged Struct Data Structure.
void CreateAuction(Seller**&, int&,int&);
//Function to Traverse Auction and Find Sellers.
void FindSellers(Seller**, int,int);
//Function to Free Memory.
void DeleteAuction(Seller**&, int);
//Function incorporating Solution.
void Solution(void);
void main(void)
{
Solution();
}
void Solution(void)
{
int Size = 0,Bid = 0;
Seller** Auction = NULL;
    CreateAuction(Auction, Size,Bid);
      FindSellers(Auction, Size,Bid);
}
void FindSellers(Seller**Auction, int Size,int Bid)
{
bool SellerFound = false;
int *SellerArr = new int[Size],SellerCount = 0;
   for (int X = 0; X < Size;++X)
   {
       for (int V = 0; V < Auction[X]->Size &&
                                      !SellerFound; ++V)
       {
           if (Bid > Auction[X]->Items[V])
           {
                SellerFound = !SellerFound;
                SellerArr[SellerCount] = X+1;
                ++SellerCount;
           }
       }
         SellerFound = false;
   }
      cout << SellerCount<<endl;
       if (SellerCount != 0)
       {
           for (int X = 0; X < SellerCount; ++X)
               cout << SellerArr[X]<<" ";
       }
       delete[] SellerArr;
   cout << endl;
}
void CreateAuction(Seller**& Auction, int& Size,int& Bid)
{
  cin >> Size >> Bid;
   Auction = new Seller*[Size];
   for (int X = 0; X < Size; ++X)
   {
     Auction[X] = new Seller;
      cin >> Auction[X]->Size;
       Auction[X]->Items = new int[Auction[X]->Size];
         for (int V = 0; V < Auction[X]->Size; ++V)
         {
            cin >> Auction[X]->Items[V];
         }
   }
}
void DeleteAuction(Seller**&Auction, int Size)
{
    for (int X = 0; X < Size; ++X)
    {
        delete [] Auction[X]->Items;
        delete Auction[X];
    }
    delete [] Auction;
}


#include<iostream>
using namespace std;
struct Seller
{
int* Items, Size;
};
//Function to Create Jagged Struct Data Structure.
void CreateAuction(Seller**&, int&,int&);
//Function to Traverse Auction and Find Sellers.
void FindSellers(Seller**, int,int);
//Function to Free Memory.
void DeleteAuction(Seller**&, int);
//Function incorporating Solution.
void Solution(void);
void main(void)
{
Solution();
}
void Solution(void)
{
int Size = 0,Bid = 0;
Seller** Auction = NULL;
    CreateAuction(Auction, Size,Bid);
      FindSellers(Auction, Size,Bid);
}
void FindSellers(Seller**Auction, int Size,int Bid)
{
bool SellerFound = false;
int *SellerArr = new int[Size],SellerCount = 0;
   for (int X = 0; X < Size;++X)
   {
       for (int V = 0; V < Auction[X]->Size &&
                                      !SellerFound; ++V)
       {
           if (Bid > Auction[X]->Items[V])
           {
                SellerFound = !SellerFound;
                SellerArr[SellerCount] = Auction[X]->Size;
                ++SellerCount;
           }
       }
         SellerFound = false;
   }
      cout << SellerCount<<endl;
       if (SellerCount != 0)
       {
           for (int X = 0; X < SellerCount; ++X)
               cout << SellerArr[X]<<" ";
       }
       delete[] SellerArr;
   cout << endl;
}
void CreateAuction(Seller**& Auction, int& Size,int& Bid)
{
  cin >> Size >> Bid;
   Auction = new Seller*[Size];
   for (int X = 0; X < Size; ++X)
   {
     Auction[X] = new Seller;
      cin >> Auction[X]->Size;
       Auction[X]->Items = new int[Auction[X]->Size];
         for (int V = 0; V < Auction[X]->Size; ++V)
         {
            cin >> Auction[X]->Items[V];
         }
   }
}
void DeleteAuction(Seller**&Auction, int Size)
{
    for (int X = 0; X < Size; ++X)
    {
        delete [] Auction[X]->Items;
        delete Auction[X];
    }
    delete [] Auction;
}


#include <iostream>
using namespace std;

#define NUM 50

int main()
{
	int seller_num, money;
	cin >> seller_num >> money;

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price[NUM];
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price[j];
			if (item_price[j] < money)
			{
				deal_seller[deal_num++] = i + 1;
				break;
			}
		}
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << flush;

	return 0;
}


#include <iostream>
using namespace std;

#define NUM 50

int main()
{
	int seller_num, money;
	cin >> seller_num >> money;

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price;
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price;
			if (item_price < money)
			{
				deal_seller[deal_num++] = i + 1;
				break;
			}
		}
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << flush;

	return 0;
}


#include <iostream>
using namespace std;

#define NUM 55

int main()
{
	int seller_num, money;
	cin >> seller_num >> money;

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price;
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price;
			if (item_price < money)
			{
				deal_seller[deal_num++] = i + 1;
				break;
			}
		}
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << flush;

	return 0;
}


#include <iostream>
using namespace std;

#define NUM 50
int main()
{
	int seller_num, money;
	scanf("%d %d", &seller_num, &money);

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price[NUM];
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price[j];
			if (item_price[j] < money)
			{
				deal_seller[deal_num++] = i + 1;
				break;
			}
		}
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << endl;

	return 0;
}


#include <iostream>
using namespace std;

#define NUM 50

int main()
{
	int seller_num, money;
	cin >> seller_num >> money;

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price;
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price;
			if (item_price < money)
				deal_seller[deal_num] = i + 1;
		}
		++deal_num；
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << flush;

	return 0;
}


#include <iostream>
using namespace std;

#define NUM 50

int main()
{
	int seller_num, money;
	cin >> seller_num >> money;

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price;
		bool first_deal_seller = true;
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price;
			if (item_price < money && first_deal_seller)
			{
				first_deal_seller = false;
				deal_seller[deal_num++] = i + 1;
			}
		}
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << flush;

	return 0;
}


#include <iostream>
using namespace std;

#define NUM 50

int main()
{
	int seller_num, money;
	cin >> seller_num >> money;

	int deal_num = 0;
	int deal_seller[NUM];
	for (int i = 0; i < seller_num; ++i)
	{
		int item_num, item_price;
		cin >> item_num;
		for (int j = 0; j < item_num; ++j)
		{
			cin >> item_price;
			if (item_price < money)
				deal_seller[deal_num] = i + 1;
		}
		++deal_num;
	}

	cout << deal_num << endl;
	for(int i = 0; i < deal_num; ++i)
		cout << deal_seller[i] << " " << flush;

	return 0;
}


#include<stdio.h>
using namespace std;
int main(){
int p=0,n,V,K,P, mas[51];
scanf("%d %d",&n,&V);
for (int i=0; i<n; i++)
{scanf("%d",&K); for(int j=0; j<K; j++) {
scanf("%d",&P); if (V>P) {mas[p]=i+1; p++; break;}}}
if(!(p)) printf("%d",p);else {printf("%d\n",p);
for(int i=0; i<p; i++)
if(i==p-1) printf("%d",mas[i]); else printf("%d ",mas[i]);}
return 0;}


#include<stdio.h>
using namespace std;
int main(){
int p=0,n,V,K,P, mas[51]; bool C=1;
scanf("%d %d",&n,&V);
for (int i=0; i<n; i++)
{C=1;scanf("%d",&K); for(int j=0; j<K; j++) {
scanf("%d",&P); if ((V>P)&&(C)) {mas[p]=i+1; p++; C=0;}}}
if(!(p)) printf("%d",p);else {printf("%d\n",p);
for(int i=0; i<p; i++)
printf("%d ",mas[i]);}
return 0;}


#include<stdio.h>
using namespace std;
int main(){
int p=0,n,V,K,P, mas[51]; bool C=1;
scanf("%d %d",&n,&V);
for (int i=0; i<n; i++)
{scanf("%d",&K); for(int j=0; j<K; j++) {C=1;
scanf("%d",&P); if ((V>P)&&(C)) {mas[p]=i+1; p++; C=0;}}}
if(!(p)) printf("%d",p);else {printf("%d\n",p);
for(int i=0; i<p; i++)
printf("%d ",mas[i]);}
return 0;}


#include<stdio.h>
using namespace std;
int main(){
int p=0,n,V,K,P, mas[51];
scanf("%d %d",&n,&V);
for (int i=0; i<n; i++)
{scanf("%d",&K); for(int j=0; j<K; j++) {
scanf("%d",&P); if (V>P) {mas[p]=i+1; p++; break;}}}
if(!(p)) printf("%d",p);else {printf("%d\n",p);
for(int i=0; i<p; i++)
printf("%d ",mas[i]);}
return 0;}


#include<stdio.h>
using namespace std;
int main(){
int p=0,n,V,K,P, mas[51];
scanf("%d %d",&n,&V);
for (int i=0; i<n; i++)
{scanf("%d ",&K); for(int j=0; j<K; j++) {
scanf("%d ",&P); if (V>P) {mas[p]=i+1; p++; break;}}}
printf("%d\n",p);
for(int i=0; i<p; i++)
printf("%d ",mas[i]);
return 0;}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n, v;
    int count=0;
    cin>>n>>v;
    vector<int>prodavci(n);
    set<int>posled;
    set<int>::iterator ik;
    for(int i=0; i<n; i++){
        int kolvo;
        cin>>kolvo;
        for(int j=0; j<kolvo; j++){
            int tovar;
            cin>>tovar;
            if(v>tovar){
            posled.insert(i+1);
            count++;
            break;
            }
        }
    }

    cout<<posled.size()<<endl;

    for(ik=posled.begin(); ik!=posled.end(); ++ik){
        cout<<*ik<<" ";
    }

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n, v;
    int count=0;
    cin>>n>>v;
    vector<int>prodavci(n);
    vector<int>posled;
    for(int i=0; i<n; i++){
        int kolvo;
        cin>>kolvo;
        for(int j=0; j<kolvo; j++){
            int tovar;
            cin>>tovar;
            if(v>tovar){
            posled.insert(posled.end(), i+1);
            count++;
            break;
            }
        }
    }

    cout<<posled.size()<<endl;

    for(int i=0; i<posled.size(); i++){
        cout<<posled[i]<<" ";
    }

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n, v;
    int count=0;
    cin>>n>>v;
    vector<int>prodavci(n);
    vector<int>posled;
    for(int i=0; i<n; i++){
        int kolvo;
        cin>>kolvo;
        for(int j=0; j<kolvo; j++){
            int tovar;
            cin>>tovar;
            if(v>tovar){
            posled.insert(posled.end(), i+1);
            count++;
            continue;
            }
        }
    }

    cout<<posled.size()<<endl;

    for(int i=0; i<posled.size(); i++){
        cout<<posled[i]<<" ";
    }

return 0;
}


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<locale>
#include<iterator>
#include<string>
#include <sstream>
#include <queue>
using namespace std;
typedef long long LL;
const int MAXN = 35000;
#define all(c) c.begin(),c.end()

int main(){
    int n, v;
    int count=0;
    cin>>n>>v;
    vector<int>prodavci(n);
    set<int>posled;
    set<int>::iterator ik;
    for(int i=0; i<n; i++){
        int kolvo;
        cin>>kolvo;
        for(int j=0; j<kolvo; j++){
            int tovar;
            cin>>tovar;
            if(v>tovar){
                posled.insert(i+1);
                count++;
            }
        }
    }

    cout<<posled.size()<<endl;

    for(ik=posled.begin(); ik!=posled.end(); ++ik){
        cout<<*ik<<" ";
    }

return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
void quick(int *a,int i,int j)
{
int m,n,temp;
int k;
m=i;
n=j;
k=a[(i+j)/2];
do {
while(a[m]<k&&m<j) m++;
while(a[n]>k&&n>i) n--;
if(m<=n) {
temp=a[m];
a[m]=a[n];
a[n]=temp;
m++;
n--;
}
}while(m<=n);
if(m<j) quick(a,m,j);
if(n>i) quick(a,i,n);
}
int main()
{
	int n, v;
	while(scanf("%d%d", &n, &v)!=EOF)
	{
		int i, t, p, T, m = 0, a[100];
		for(i=0;i<n;i++)
		{
			scanf("%d", &t);
			T = t;
			while(t--)
			{
				scanf("%d", &p);
				if(v>p)
				{
					a[m] = T;
					m++;
				}
			}
		}
		quick(a, 0, n-1);
			printf("%d\n", m);
			for(i=0;i<m;i++)
			i==0?printf("%d", a[i]):printf(" %d", a[i]);
			m>0?printf("\n"):0;

	}
}


#include<stdio.h>
#include<math.h>
struct gudong
{
	int a,num,res;
}s[100001];
int main()
{
	int i,j,k=0,n,money,sum=0;
	scanf("%d%d",&n,&money);
	for(i=0;i<n;++i)
	{
		int m;
		scanf("%d",&m);
		s[i].res=0;
		for(j=0;j<m;++j)
		{
			scanf("%d",&s[i].a);
			if(money>s[i].a)
			{
				s[i].res=1;
			}
		}
		s[i].num=i+1;
	}
	for(i=0;i<n;++i)
		if(s[i].res==1)
			sum++;
	printf("%d\n",sum);
	for(i=0;i<n;++i)
		if(s[i].res==1)
		{
			if(k)
				printf(" ");
			printf("%d",s[i].num);
			k++;
		}
	if(k)
	    printf("\n");
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include <string.h>
#include<algorithm>
using namespace std;
int main()
{
    int money, peo, time, price, ava[100] = { 0 }, pri[100] = { 0 };
    int x, y, i, j;
    scanf("%d %d", &peo, &money);
    for (i = 0; i < peo; i++)
    {
        scanf("%d", &time);
        while (time--)
        {
            scanf("%d", &price);
            if (price < money)
                ava[i]++;
        }
    }
    int total = 0;
    j = 0;
    for (i = 0; i < peo;i++)
    {
        //printf("%d ", ava[i]);
        if (ava[i])
        {
            total++;
            pri[j] = i;
            j++;
        }
    }
    printf("%d\n", total);
    if (total != 0)
    {
        for (i = 0; i < total - 1; i++)
        {
            printf("%d ", pri[i] + 1);
        }
        printf("%d\n", pri[i] + 1);
    }
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
//#pragma comment(linker, "/STACK:102400000, 102400000")
using namespace std;
typedef unsigned int li;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1.0);
const double e = exp(1.0);
const double eps = 1e-8;
short n, k;
int extra, value;

int main()
{
	ios::sync_with_stdio(false);
	while (~scanf("%hd%d", &n, &extra))
	{
		short num[55], cnt=0;
		for (short i=0; i<n; i++)
		{
			scanf("%hd", &k);
			bool flag = false;
			while (k--)
			{
				scanf("%d", &value);
				if (extra > value)
					flag = true;
			}
			if (flag)
				num[cnt++] = i+1;
		}
		printf("%hd\n", cnt);
		for (short i=0; i<cnt; i++)
			printf("%d ", num[i]);
		printf("\n");
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,v;
	int a[51][51];
	while(cin>>n>>v)
	{
		int k=0;
		int b[51];
		int m;
		int time=0;
		for(int i=0;i<n;++i)
		{
			cin>>m;
			for(int j=0;j<m;++j)
				cin>>a[i][j];
			sort(a[i],a[i]+m);
			if(a[i][0]<v)
			{
				b[k++]=i;
				time++;
			}
		}
		cout<<time<<endl;
		for(int i=0;i<k-1;++i)
			cout<<b[i]+1<<" ";
		if(k==0)
			cout<<endl;
		else
			cout<<b[k-1]+1<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n, v;
    cin >> n >> v;
    int A[10000], ans = 0;
    for (int i = 0; i < n; i++){
        int m;
        bool is = false;
        cin >> m;
        for (int j = 0; j < m; j++){
            int k;
            cin >> k;
            if (v > k)
                is = true;
        }
        if (is)
            A[ans++] = i + 1;
    }
    cout << ans;
    if (ans > 0){
        cout << A[0];
        for (int i = 1; i < ans; i++)
            cout << A[i];

    }

    return 0;


#include<iostream>
using namespace std;
int main(){
    int n , p , a , arr[1000], cont=0 , arr2[1000];
    cin >> n >> p;
    for (int i = 0; i < n; i++)
    {
        bool is = false;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            cin >> arr[j];
            if (p >arr[j] )
            {
                is = true;
            }

        }
        if (  is = true )
        {
            arr2[cont++] = i + 1;
        }
    }
    cout << cont << endl;
    if (cont > 0)
    {
        cout << arr2[0] << endl;
    }
    for (int i = 1; i < cont; i++)
    {
        cout << arr2[i] << " " ;
    }

    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n , p , a , arr[10000], cont=0 , arr2[10000];
    cin >> n >> p;
    for (int i = 0; i < n; i++)
    {
        bool is = false;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            cin >> arr[j];
            if (p >arr[j] )
            {
                is = true;
            }

        }
        if (  is = true )
        {
            arr2[cont++] = i + 1;
        }
    }
    cout << cont << endl;
    if (cont > 0)
    {
        cout << arr2[0] << endl;
    }
    for (int i = 1; i < cont; i++)
    {
        cout << arr2[i] << " " ;
    }

    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,s1,n1,ss,arr[100000];
while(cin>>n>>s1)
{int count=0,x=0;
for(int i=0;i<n;i++){
    cin>>n1;
    for(int j=0;j<n1;j++){
        cin>>ss;
    if(s1>ss){
        arr[x++]=i+1;
        }}
}
for(int i=0;i<x;i++){
    for(int j=0;j<x&&arr[i]!=0;j++){
        if(i==j)
        continue;
        if(arr[i]==arr[j]){arr[j]=0;
        count++;}}}
cout<<x-count<<endl;
sort(arr+0,arr+x);
for(int i=0;i<x;i++)
    if(arr[i]!=0)
    cout<<arr[i]<<" ";
}
return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n , p , a , arr[1000] , arr2[1000];
cin >> n >> p;
    int cont=0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        bool is = false;
        for (int j = 0; j < a; j++)
        {
            cin >> arr[j];
            if (p >arr[j] )
            {
                is = true;
                break;
            }

        }
        if (  is == true )
        {
            arr2[cont++] = i + 1;
        }
        }
    cout << cont << endl;
    if (cont > 0)
    for (int i = 0; i < cont; i++)
        cout << arr2[i] << " " ;
    return 0;
}


#include<iostream>
using namespace std;
void sellers()
{
	int n,v,k,s[52],count=0,arr[52],cnt=0;
	cin>>n>>v;

	for(int i=0;i<n;i++){
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>s[j];
			if(v>s[j])
			{
				count=1;
			}
		}
		if(count==1){
			arr[cnt]=i+1;
			cnt++;
		}
		count=0;
	}
	if(cnt==0)
	cout<<cnt<<endl;
	else{
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++)
	cout<<arr[i]<<" ";
    }
}

int main()
{
	sellers();
	return 0;
}


#include<iostream>
using namespace std;
void sellers()
{
	int n,v,k,s[52],count=0,arr[52],cnt=0;
	cin>>n>>v;

	for(int i=0;i<n;i++){
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>s[j];
			if(v>s[j])
			{
				count=1;
			}
		}
		if(count==1){
			arr[i]=i+1;
			cnt++;
		}
		count=0;
	}
	if(cnt==0)
	cout<<cnt<<endl;
	else{
	cout<<cnt<<endl;
	for(int i=0;i<cnt;i++)
	cout<<arr[i]<<" ";
    }
}

int main()
{
	sellers();
	return 0;
}


#include<iostream>
using namespace std;
void sellers()
{
	int n,v,k,s[52],count=0,arr[52],cnt=0;
	cin>>n>>v;

	for(int i=0;i<n;i++){
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>s[j];
			if(v>s[j])
			{
				count=1;
			}
		}
		if(count==1){
			arr[i]=i+1;
			cnt++;
		}
		count=0;
	}
	if(cnt==0)
	cout<<cnt<<endl;
	else{
	cout<<cnt<<endl;
	for(int i=0;i<n;i++)
	cout<<arr[i]<<" ";
    }
}

int main()
{
	sellers();
	return 0;
}


#include <iostream>
using namespace std;
int main(){
int n,k,m=0,t,count=0,z=0;
cin>>n>>k;
int *out=new int[n];
while(m<n){
	cin>>t;
	int *arr=new int [t];
	for(int i=0;i<t;i++){
		cin>>arr[i];
		}
	for(int i=0;i<t;i++){
		if(k>arr[i]) {
		count++;
		out[z++]=m+1;
		break;}
		}
	m++;
	delete[] arr;
}
cout<<count<<endl;
for (int i=0;i<count;i++)
{
	cout<<out[i]<<" ";
}
cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;

int main(){
	int out[50];
	int n,v,x,y;
	cin>>n>>v;
	x=1;
	y=0;
	while (n--)
	{
		int k;
		cin>>k;
		long int mny[50];
		for(int i=0;i<k;i++)cin>>mny[i];
		for(int i=0;i<k;i++)
		{
			if(mny[i]<v){
				out[y++]=x;
				break;}
		}
		x++;
	}
	cout<<y<<endl;
	for(int i=0;i<y;i++)cout<<out[i]<<" ";
	//cout<<endl;
}


#include<iostream>
using namespace std;

int main(){
	int out[50];
	int n,v,y;
	cin>>n>>v;
	y=0;
	int x=1;
	while (n--)
	{
		int k;
		cin>>k;
		int mny[50];
		for(int i=0;i<k;i++)cin>>mny[i];
		for(int i=0;i<k;i++)
		{
			if(mny[i]<v)out[y++]=x;
		}
		x++;
	}
	cout<<y<<endl;
	for(int i=0;i<y;i++)cout<<out[i]<<" ";
	//cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;

int main(){
	int out[50];
	long long int  n, v, x, y;
	cin >> n >> v;
	x = 1;
	y = 0;
	while (n--)
	{
		int k;
		cin >> k;
		int mny[50];
		for (int i = 0; i<k; i++)cin >> mny[i];
		for (int i = 0; i<k; i++)
		{
			if (mny[i]<v)out[y++] = x;
		}
		x++;
	}
	cout << y << endl;
	for (int i = 0; i<y; i++)cout << out[i] << " ";
	//cout<<endl;
}


#include<iostream>
using namespace std;

int main(){
	int out[50];
	int n,v,y;
	cin>>n>>v;
	y=0;
	int x=1;
	while (n--)
	{
		int k;
		cin>>k;
		long int mny[50];
		for(int i=0;i<k;i++)cin>>mny[i];
		for(int i=0;i<k;i++)
		{
			if(mny[i]<v)out[y++]=x;
		}
		x++;
	}
	cout<<y<<endl;
	for(int i=0;i<y;i++)cout<<out[i]<<" ";
	//cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;

int main(){
	int out[50];
	int n,v,x,y;
	cin>>n>>v;
	x=1;
	y=0;
	while (n--)
	{
		int k;
		cin>>k;
		int mny[k];
		for(int i=0;i<k;i++)cin>>mny[i];
		for(int i=0;i<k;i++)
		{
			if(mny[i]<v)out[y++]=x;
		}
		x++;
	}
	cout<<y<<endl;
	for(int i=0;i<y;i++)cout<<out[i]<<" ";
	//cout<<endl;

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res,mx;

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    mx=max(n,m);
    for(int i=1;i*i<=k;i++){
        if(k%i==0){
            mul.push_back(i);
        }
    }
    int h=mul.size();
    for(int i=0;i<h;i++){
        if(mul[i]*mul[i]!=k)
            mul.push_back(k/mul[i]);
    }

//    for(int i=0;i<mul.size();i++)
//        cout<<mul[i]<<" ";
    //cout<<endl;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            for(int a=0;a<mul.size()&&mul[a]<=va[i];a++){
                if((k/mul[a])<=vb[j]){
                    res+=(va[i]-mul[a]+1)*(vb[j]-(k/mul[a])+1);
                }
            }
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res,mx;

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    mx=max(n,m);
    for(int i=1;i<=k;i++){
        if(k%i==0){
            mul.push_back(i);
        }
    }

//    for(int i=0;i<mul.size();i++)
//        cout<<mul[i]<<" ";
    //cout<<endl;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            for(int a=0;a<mul.size()&&mul[a]<=va[i];a++){
                if((k/mul[a])<=vb[j]){
                    res+=(va[i]-mul[a]+1)*(vb[j]-(k/mul[a])+1);
                }
            }
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res,mx;

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    mx=max(n,m);
    for(int i=1;i<=k;i++){
        if(k%i==0){
            mul.push_back(i);
        }
    }

//    for(int i=0;i<mul.size();i++)
//        cout<<mul[i]<<" ";
    //cout<<endl;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            for(int a=0;a<mul.size()&&mul[a]<va[i];a++){
                if((k/mul[a])<=vb[j]){
                    res+=(va[i]-mul[a]+1)*(vb[j]-(k/mul[a])+1);
                }
            }
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<vector>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res;

ll nor(ll n,ll m,ll k)
{
    ll ret=0;
    for(int i=0;i<mul.size()||mul[i]<=n;i++){
        if((k/mul[i])<=m)
            ret+=((n-mul[i]+1)*(m-(k/mul[i])+1));
    }
    return ret;
}

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    for(int i=1;i<=k;i++)
        if(k%i==0)
            mul.push_back(i);
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            res+=nor(va[i],vb[j],k);
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<vector>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res;

ll nor(ll n,ll m,ll k)
{
    ll ret=0;
    for(int i=0;(i<mul.size())&&(mul[i]<=n);i++){
        //cout<<ret<<" "<<mul[i]<<endl;
        if((k/mul[i])<=m){
            ret+=((n-mul[i]+1)*(m-(k/mul[i])+1));
        }
        //cout<<mul[i]<<" "<<ret<<endl;
    }
    return ret;
}

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    for(int i=1;i<=k;i++)
        if(k%i==0)
            mul.push_back(i);
//    for(int i=0;i<mul.size();i++)
//        cout<<mul[i]<<" ";
    //cout<<endl;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            res+=nor(va[i],vb[j],k);
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res,mx;

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    mx=max(n,m);
    for(int i=1;i*i<=k;i++){
        if(k%i==0){
            mul.push_back(i);
        }
    }
    int h=mul.size();
    for(int i=h-1;i>=0;i--){
        if(mul[i]*mul[i]!=k)
            mul.push_back(k/mul[i]);
    }

//    for(int i=0;i<mul.size();i++)
//        cout<<mul[i]<<" ";
    //cout<<endl;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            for(int a=0;a<mul.size()&&mul[a]<=va[i];a++){
                if((k/mul[a])<=vb[j]){
                    res+=(va[i]-mul[a]+1)*(vb[j]-(k/mul[a])+1);
                }
            }
        }
    }
    cout<<res<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int ll;

vector<ll>even,odd,mul;

ll n,m,k,a[40100],b[40100],x,res,mx;

int main()
{
    vector<int>va,vb;
    cin>>n>>m>>k;
    mx=max(n,m);
    for(int i=1;i*i<=k;i++){
        if(k%i==0){
            mul.push_back(i);
        }
    }
    int h=mul.size();
    for(int i=0;i<h;i++){
        mul.push_back(k/mul[i]);
    }

//    for(int i=0;i<mul.size();i++)
//        cout<<mul[i]<<" ";
    //cout<<endl;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>x;
        if(x)
            a[i]=x+a[i-1];
    }
    cin>>b[0];
    for(int i=1;i<m;i++){
        cin>>x;
        if(x)
            b[i]=x+b[i-1];
    }
    for(int i=0;i<n;i++){
        if(a[i]&&a[i+1]==0)
            va.push_back(a[i]);
    }
    for(int i=0;i<m;i++){
        if(b[i]&&b[i+1]==0)
            vb.push_back(b[i]);
    }

//    for(int i=0;i<vb.size();i++)
//        cout<<vb[i]<<" ";
//    cout<<"\n---------\n"<<endl;
//    for(int i=0;i<m;i++)
//        cout<<b[i]<<" ";
//    cout<<"\n---------\n"<<endl;
    res=0;
    for(int i=0;i<va.size();i++){
        for(int j=0;j<vb.size();j++){
            for(int a=0;a<mul.size()&&mul[a]<=va[i];a++){
                if((k/mul[a])<=vb[j]){
                    res+=(va[i]-mul[a]+1)*(vb[j]-(k/mul[a])+1);
                }
            }
        }
    }
    cout<<res<<endl;
}


#include<cstdio>
#include<iostream>

using namespace std;

typedef long long LL;
const int maxn = 4e4+4;
int n,m,k,a[maxn],b[maxn],c[maxn][maxn];

int sum_a(int n, int k)
{
	int tmp = 0;
	for(int i = k; i <= n; i++)
		if(a[i]-a[i-k] == k)
			tmp++;
	return tmp;
}

int sum_b(int n, int k)
{
	int tmp = 0;
	for(int i = k; i <= n; i++)
		if(b[i]-b[i-k] == k)
			tmp++;
	return tmp;
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] += a[i-1];
	}
	for(int i = 1; i <= n; i++)
	{
		cin >> b[i];
		b[i] += b[i-1];
	}
	LL ans = 0;
	for(int i = 1; i*i <= k; i++)
	{
		if(k%i == 0) {
			if(i*i == k)
				ans += sum_a(n,i)*sum_b(m,k/i);
			else {
				ans += sum_a(n,i)*sum_b(m,k/i);
				ans += sum_a(n,k/i)*sum_b(m,i);
			}
		}
	}
	cout << ans << endl;
}


#include<cstdio>
#include<iostream>

using namespace std;

typedef long long LL;
const int maxn = 4e4+4;
int n,m,k,a[maxn],b[maxn];

int sum_a(int x)
{
	int tmp = 0;
	for(int i = x; i <= n; i++)
		if(a[i]-a[i-x] == x)
			tmp++;
	return tmp;
}

int sum_b(int x)
{
	int tmp = 0;
	for(int i = x; i <= m; i++)
		if(b[i]-b[i-x] == x)
			tmp++;
	return tmp;
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] += a[i-1];
	}
	for(int i = 1; i <= m; i++)
	{
		cin >> b[i];
		b[i] += b[i-1];
	}
	LL ans = 0;
	for(int i = 1; i*i <= k; i++)
	{
		if(k%i == 0) {
			if(i*i == k)
				ans += 1LL*sum_a(i)*sum_b((k/i));
			else {
				ans += 1LL*sum_a(i)*sum_b((k/i));
				ans += 1LL*sum_a((k/i))*sum_b(i);
			}
		}
	}
	cout << ans << endl;
}


#include<cstdio>
#include<iostream>

using namespace std;

typedef long long LL;
const int maxn = 4e4+4;
int n,m,k,a[maxn],b[maxn];

int sum_a(int x, int y)
{
	int tmp = 0;
	for(int i = y; i <= x; i++)
		if(a[i]-a[i-y] == y)
			tmp++;
	return tmp;
}

int sum_b(int x, int y)
{
	int tmp = 0;
	for(int i = y; i <= x; i++)
		if(b[i]-b[i-y] == y)
			tmp++;
	return tmp;
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] += a[i-1];
	}
	for(int i = 1; i <= n; i++)
	{
		cin >> b[i];
		b[i] += b[i-1];
	}
	LL ans = 0;
	for(int i = 1; i*i <= k; i++)
	{
		if(k%i == 0) {
			if(i*i == k)
				ans += sum_a(n,i)*sum_b(m,k/i);
			else {
				ans += sum_a(n,i)*sum_b(m,k/i);
				ans += sum_a(n,k/i)*sum_b(m,i);
			}
		}
	}
	cout << ans << endl;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<set>
#define pb push_back
#define vc vector<int>
#define inf 0x3f3f3f3f
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define t_case ll tt; cin>>tt; while (tt--)
#define ll long long
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
using namespace std;
ll n, m, k, ans = 0;
vector<ll> cl(400001);
vector<ll> rw(400001);
void col() {
	 int length = 0;
	for (int i = 1;i <= m;i++) {
		int a; cin >> a;
		if (a)length++;
		else if (length) {
			for (int j = length;j;j--)cl[j] += length - j + 1;
			length = 0;
		}
	}
	for (int j = length;j;j--)cl[j] += length - j + 1;
}
void row() {
	int length = 0;
	for (int i = 1;i <= n;i++) {
		int a; cin >> a;
		if (a)length++;
		else if (length) { for (int j = length;j;j--)rw[j] += length - j + 1;
		length = 0;}
	}
	for (int j = length;j;j--)rw[j] += length - j + 1;}
int main() {
	fastio
		cin >> n >> m >> k;
	row(), col();
	for (int i = 1;i <= (k / i);i++) {
		if (!(k%i)) {
			if(i<=n&&k/i<=m)ans += rw[i] * cl[k / i];
			if (i != k / i&&i <= m&&k / i <= n)ans += rw[k / i] * cl[i];
		}
	}
	cout << ans << "\n";

}


#include <iostream>
#include<vector>
#include<algorithm>
#include<set>
#define pb push_back
#define vc vector<int>
#define inf 0x3f3f3f3f
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define t_case ll tt; cin>>tt; while (tt--)
#define ll long long
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
using namespace std;
ll n, m, k, ans = 0;
vector<ll> cl(400001);
vector<ll> rw(400001);
void col() {
	 int length = 0;
	for (int i = 1;i <= m;i++) {
		int a; cin >> a;
		if (a)length++;
		else if (length) {
			for (int j = length;j;j--)cl[j] += length - j + 1;
			length = 0;
		}
	}
	for (int j = length;j;j--)cl[j] += length - j + 1;
}
void row() {
	int length = 0;
	for (int i = 1;i <= n;i++) {
		int a; cin >> a;
		if (a)length++;
		else if (length) { for (int j = length;j;j--)rw[j] += length - j + 1;
		length = 0;}
	}
	for (int j = length;j;j--)rw[j] += length - j + 1;}
int main() {
	fastio
		cin >> n >> m >> k;
	row(), col();
	for (int i = 1;i <= (k / i);i++) {
		if (!(k%i)) {
			if(i<=n&&k/i<=m)ans += rw[i] * cl[k / i];
			if (i <= m&&k / i <= n)ans += rw[k/i] * cl[i];
		}
	}
	cout << ans << "\n";
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, q, k, i, j, a;
long long g, qa[40002], qb[40002];
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
		}
		else
		{
			for (j = 1; j <= q; j++)
				qa[j] += q - j + 1;
			q = 0;
		}
	}
	if(q!=0)
		for (j = 1; j <= q; j++)
			qa[j] += q - j + 1;
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
		}
		else
		{
			for (j = 1; j <= q; j++)
				qb[j] += q - j + 1;
			q = 0;
		}
	}
	if (q != 0)
		for (j = 1; j <= q; j++)
			qb[j] += q - j + 1;
	for (i = 1; i <= n; i++)
	{
		if (qa[i] != 0)
			if (k%i == 0)
				g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, q, k, i, j, l, a, g, qa[40002], qb[40002];
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
			for (j = q; j >= 1; j--)
				qa[j]++;
		}
		else
			q = 0;
	}
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
			for (j = q; j >= 1; j--)
				qb[j]++;
		}
		else
			q = 0;
	}
	for (i = 1; i <= n; i++)
	{
		if (qa[i] != 0)
			if (k%i == 0)
				g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
//#include <algorithm>
//#include <string>
//#include <cmath>
using namespace std;
long long  n, m, a, g, k, qa[40002], qb[40002], q, i, j;
int main()
{
	memset(qa, 0, 40002);
	memset(qb, 0, 40002);
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
			q++;
		else
		{
			for (j = 1; j <= q; j++)
				qa[j] += q - j + 1;
			q = 0;
		}
	}
	for (j = 1; j <= q; j++)
		qa[j] += q - j + 1;
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
			q++;
		else
		{
			for (j = 1; j <= q; j++)
				qb[j] += q - j + 1;
			q = 0;
		}
	}
	for (j = 1; j <= q; j++)
		qb[j] += q - j + 1;
	if (n > m)
		for (i = 1; i <= n; i++)
		{
			if (k%i == 0)
				g += qa[i] * qb[k / i];
		}
	else
		for (i = 1; i <= m; i++)
		{
			if (k%i == 0)
				g += qb[i] * qa[k / i];
		}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, a;
long long g, k, qa[40002], qb[40002], q, i, j;
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
			q++;
		else
		{
			for (j = 1; j <= q; j++)
				qa[j] += q - j + 1;
			q = 0;
		}
	}
	for (j = 1; j <= q; j++)
		qa[j] += q - j + 1;
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
			q++;
		else
		{
			for (j = 1; j <= q; j++)
				qb[j] += q - j + 1;
			q = 0;
		}
	}
	for (j = 1; j <= q; j++)
		qb[j] += q - j + 1;
	for (i = 1; i <= n; i++)
	{
		if (k%i == 0)
			g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, q, i, j, l, a, qa[40002], qb[40002];
long long g, k;
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
			for (j = q; j >= 1; j--)
				qa[j]++;
		}
		else
			q = 0;
	}
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
			for (j = q; j >= 1; j--)
				qb[j]++;
		}
		else
			q = 0;
	}
	for (i = 1; i <= n; i++)
	{
		if (qa[i] != 0)
			if (k%i == 0)
				g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, q, i, j, a;
long long g, k, qa[40002], qb[40002];
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
		}
		else
		{
			for (j = 1; j <= q; j++)
				qa[j] += q - j + 1;
			q = 0;
		}
	}
	if(q!=0)
		for (j = 1; j <= q; j++)
			qa[j] += q - j + 1;
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
		}
		else
		{
			for (j = 1; j <= q; j++)
				qb[j] += q - j + 1;
			q = 0;
		}
	}
	if (q != 0)
		for (j = 1; j <= q; j++)
			qb[j] += q - j + 1;
	for (i = 1; i <= n; i++)
	{
		if (qa[i] != 0)
			if (k%i == 0)
				g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, a;
long long g, k, qa[40002], qb[40002], q, i, j;
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
		}
		else
		{
			for (j = 1; j <= q; j++)
				qa[j] += q - j + 1;
			q = 0;
		}
	}
	if(q!=0)
		for (j = 1; j <= q; j++)
			qa[j] += q - j + 1;
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
		}
		else
		{
			for (j = 1; j <= q; j++)
				qb[j] += q - j + 1;
			q = 0;
		}
	}
	if (q != 0)
		for (j = 1; j <= q; j++)
			qb[j] += q - j + 1;
	for (i = 1; i <= n; i++)
	{
		if (qa[i] != 0)
			if (k%i == 0)
				g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int n, m, q, i, j, l, a;
long long g, k, qa[40002], qb[40002];
int main()
{
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
			for (j = q; j >= 1; j--)
				qa[j]++;
		}
		else
			q = 0;
	}
	q = 0;
	for (i = 1; i <= m; i++)
	{
		cin >> a;
		if (a == 1)
		{
			q++;
			for (j = q; j >= 1; j--)
				qb[j]++;
		}
		else
			q = 0;
	}
	for (i = 1; i <= n; i++)
	{
		if (qa[i] != 0)
			if (k%i == 0)
				g += qa[i] * qb[k / i];
	}
	cout << g;
	cin >> i;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int num;
vector<int> v;

void cal() {
	for (int i = 1; i*i <= num; i++) {
		if (num%i == 0) {
			v.push_back(i);
			if(i*i!=num)
				v.push_back(num / i);
		}
	}
}
map<int, int> a;
map<int, int> b;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int alen, blen, tt;
	cin >> alen >> blen >> num;
	int cnt = 0;
	cal();		//��� ���ϱ�
	for (int i = 0; i < alen; i++) {
		cin >> tt;
		if (tt == 1) cnt++;
		else {
			if (cnt != 0) {
				if (a.find(cnt) == a.end())
					a[cnt] = 1;
				else
					a[cnt]++;
			}
			cnt = 0;
		}
	}
	if (cnt != 0) {
		if (a.find(cnt) == a.end())
			a[cnt] = 1;
		else
			a[cnt]++;
	}
	cnt = 0;
	sort(v.begin(), v.end());
	for (int i = 0; i < blen; i++) {
		cin >> tt;
		if (tt == 1) cnt++;
		else {
			if (cnt != 0) {
				if (b.find(cnt) == b.end())
					b[cnt] = 1;
				else
					b[cnt]++;
			}
			cnt = 0;
		}
	}
	if (cnt != 0) {
		if (b.find(cnt) == b.end())
			b[cnt] = 1;
		else
			b[cnt]++;
	}
	long long ans = 0;

	for (int i = 0; i < v.size(); i++) {
		int first = v[i];
		int second = v[v.size() - 1 - i];
		if (second < first) break;
		long long cnt1 = 0, cnt2 = 0;
		for (auto it = a.begin(); it != a.end(); it++) {
			if (it->first >= first) {
				cnt1 += ((it->first - first + 1)*(it->second));
			}
		}
		for (auto it = b.begin(); it != b.end(); it++) {
			if (it->first >= second) {
				cnt2 += ((it->first - second + 1)*(it->second));
			}
		}
		ans += cnt1 * cnt2;
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
long long num;
vector<int> v;

void cal() {
	for (int i = 1; i*i <= num; i++) {
		if (num%i == 0) {
			v.push_back(i);
			if (i*i != num)
				v.push_back(num / i);
		}
	}
}
map<int, int> a;
map<int, int> b;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int alen, blen, tt;
	cin >> alen >> blen >> num;
	int cnt = 0;
	cal();		//��� ���ϱ�
	sort(v.begin(), v.end());
	for (int i = 0; i < alen; i++) {
		cin >> tt;
		if (tt == 1) cnt++;
		else {
			if (cnt != 0) {
				if (a.find(cnt) == a.end())
					a[cnt] = 1;
				else
					a[cnt]++;
				cnt = 0;
			}
		}
	}
	if (cnt != 0) {
		if (a.find(cnt) == a.end())	a[cnt] = 1;
		else	a[cnt]++;
	}
	cnt = 0;
	for (int i = 0; i < blen; i++) {
		cin >> tt;
		if (tt == 1) cnt++;
		else {
			if (cnt != 0) {
				if (b.find(cnt) == b.end())
					b[cnt] = 1;
				else
					b[cnt]++;
				cnt = 0;
			}
		}
	}
	if (cnt != 0) {
		if (b.find(cnt) == b.end())	b[cnt] = 1;
		else	b[cnt]++;
	}
	long long ans = 0;
	for (int i = 0; i < v.size(); i++) {
		int first = v[i];
		int second = v[v.size() - 1 - i];
		long long cnt1 = 0, cnt2 = 0;
		for (auto it = a.begin(); it != a.end(); it++) {
			if (it->first >= first) {
				cnt1 += ((it->first - first + 1)*(it->second));
			}
		}
		for (auto it = b.begin(); it != b.end(); it++) {
			if (it->first >= second) {
				cnt2 += ((it->first - second + 1)*(it->second));
			}
		}
		ans += cnt1 * cnt2;
	}
	cout << ans;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <fstream>
#include <queue>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <math.h>
#include <cmath>
#include <map>
#include <ctime>
#pragma comment(linker, "/STACK:10000000000")

#define ll long long
#define rt return
#define all(a) a.begin(), a.end()
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

const int MAX_SIZE = 1000, INF = 2 * 1e9;
const long long SuperINF = 1e12, MOD = 1e9;
const double eps = 0.5, PI = 20 / 7;

void files() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}

void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> arr_a, arr_b;

	for (int i = 0; i < n; i++) {
		int g;
		cin >> g;
		arr_a.push_back(g);
	}

	for (int i = 0; i < m; i++) {
		int c;
		cin >> c;
		arr_b.push_back(c);
	}

	vector<int> dels;

	for (int i = 1; i <= sqrt(k); i++) {
		if (k % i == 0) {
			int a = i;
			int b = k / i;
			dels.push_back(a);

			if (b != a)
				dels.push_back(b);
		}

	}

	map<int, int> cnts1, cnts2;

	bool flag1 = false;
	int cnt1 = 0;
	for (int i = 0; i < n; i++) {
		if (!flag1) {
			if (arr_a[i] == 1) {
				cnt1++;
				flag1 = 1;
			}
			else {
				flag1 = 0;
				cnt1 = 0;
			}
		}
		else {
			if (arr_a[i] == 1)
				cnt1++;
			else {

				for(int j = 0;j < dels.size(); j++){
					int xx = dels[j];
					cnts1[xx] += max(0, cnt1 - xx + 1);

				}
				cnt1 = 0;
				flag1 = false;
			}

		}

	}

	for (int j = 0; j < dels.size(); j++) {
		int xx = dels[j];
		cnts1[xx] += max(0, cnt1 - xx + 1);
	}

	cnt1 = 0;
	flag1 = false;

	for (int i = 0; i < m; i++) {
		if (!flag1) {
			if (arr_b[i] == 1) {
				cnt1++;
				flag1 = 1;
			}
			else {
				flag1 = 0;
				cnt1 = 0;
			}
		}
		else {
			if (arr_b[i] == 1)
				cnt1++;
			else {

				for (int j = 0; j < dels.size(); j++) {
					int xx = dels[j];
					cnts2[xx] += max(0, cnt1 - xx + 1);

				}
				cnt1 = 0;
				flag1 = false;
			}

		}

	}

	for (int j = 0; j < dels.size(); j++) {
		int xx = dels[j];
		cnts2[xx] += max(0, cnt1 - xx + 1);
	}

	cnt1 = 0;
	flag1 = false;

	int ans = 0;
	for (int i = 1; i <= sqrt(k); i++) {
		if (k % i == 0) {
			int a = i;
			int b = k / i;
			ans += cnts1[a] * cnts2[b];

			if (a != b) {
				ans += cnts1[b] * cnts2[a];
			}

		}

	}
	cout << ans;
}

int main() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//files();

	int t = 1;
	// >> t;
	while (t--)
		solve();

	rt 0;
}