#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <unordered_map>
#include <queue>
#include <array>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
//const int mod = ;

const int N = 1 << 12;
ll d[2][N][3001];

void umax(ll& x, ll y) {
  x = max(x, y);
}

const int DEBUG = 0;

int main() {
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  //int n = 3000, k = 3000;
  for (int tt = 0; tt < (DEBUG ? 100 : 1); ++tt) {
  int n = 10, k = rand() % 10;
  if (!DEBUG) cin >> n >> k;
  vvi a(n);
  vi l(n);
  vl sum(n);
  for (int i = 0; i < n; ++i) {
    //int t = 300;
    int t = 1 + rand() % 10;
    if (!DEBUG) cin >> t;
    a[i].resize(t);
    l[i] = t;
    for (int j = 0; j < t; ++j) {
      if (!DEBUG) cin >> a[i][j];
      else a[i][j] = j > 0 ? a[i][j - 1] + rand() % 5 : rand() % 2;
      sum[i] += a[i][j];
    }
  }
  int pw = 1;
  while (pw < n) pw *= 2;
  while (l.size() < pw) {
    l.push_back(0);
    sum.push_back(0);
  }
  memset(d[0], 0, sizeof(d[0]));
  int pr = 0, nx = 1;
  while (pw > 1) {
    pw /= 2;
    for (int s = 0; s < l.size(); s += 2 * pw) {
      memcpy(d[nx][s], d[pr][s], sizeof(d[nx][s]));
      memcpy(d[nx][s + pw], d[pr][s], sizeof(d[nx][s]));
      for (int i = s; i < s + pw; ++i) for (int j = k; j >= l[i]; --j) {
        umax(d[nx][s + pw][j], d[nx][s + pw][j - l[i]] + sum[i]);
      }
      for (int i = s + pw; i < s + 2 * pw; ++i) for (int j = k; j >= l[i]; --j) {
        umax(d[nx][s][j], d[nx][s][j - l[i]] + sum[i]);
      }
    }
    swap(pr, nx);
  }
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    ll s = 0;
    for (int j = 0; j < min(k + 1, (int)a[i].size() + 1); ++j) {
      res = max(res, d[pr][i][k - j] + s);
//      cerr << res << ' ' << i << ' ' << j << ' ' << s << ' ' << d[pr][i][k - j] << endl;
      if (j < a[i].size()) s += a[i][j];
    }
  }
  cout << res << endl;
  if (DEBUG) {
    vl v(k + 1);
    for (int i = 0; i < n; ++i) {
      ll s = 0;
      vl res = v;
      for (int j = 0; j < min(k + 1, (int)a[i].size() + 1); ++j) {
        vl v1 = v;
        for (int t = k; t >= j; --t) {
          v1[t] = max(v1[t], v1[t - j] + s);
        }
        for (int t = 0; t <= k; ++t) res[t] = max(res[t], v1[t]);
        if (j < a[i].size()) s += a[i][j];
      }
      v = res;
    }
    cerr << v[k] << endl;
    if (v[k] != res) {
      cout << n << ' ' << k << endl;
      for (int i = 0; i < n; ++i) {
        for (int x : a[i]) cout << x << ' '; cout << endl;
      }
    }
    assert(v[k] == res);
  }
  }
  return 0;
}


/**
 *    author:  tourist
 *    created: 01.11.2020 17:14:09
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> a(n);
  vector<int> sz(n);
  vector<long long> sum(n);
  for (int i = 0; i < n; i++) {
    int foo;
    cin >> foo;
    a[i].resize(foo);
    sz[i] = foo;
    sum[i] = 0;
    for (int j = 0; j < foo; j++) {
      cin >> a[i][j];
      sum[i] += a[i][j];
    }
  }
  const long long inf = (long long) 1e18;
  vector<vector<long long>> save(30, vector<long long>(k + 1, -inf));
  vector<long long> dp(k + 1, -inf);
  dp[0] = 0;
  long long ans = 0;
  function<void(int, int, int)> Solve = [&](int level, int from, int to) {
    if (from == to) {
      long long took = 0;
      for (int i = 0; i <= k; i++) {
        ans = max(ans, took + dp[k - i]);
        if (i == (int) a[from].size()) {
          break;
        }
        took += a[from][i];
      }
      return;
    }
    for (int j = 0; j <= k; j++) {
      save[level][j] = dp[j];
    }
    int mid = (from + to) >> 1;
    {
      for (int i = from; i <= mid; i++) {
        for (int j = k - sz[i]; j >= 0; j--) {
          dp[j + sz[i]] = max(dp[j + sz[i]], dp[j] + sum[i]);
        }
      }
      Solve(level + 1, mid + 1, to);
      for (int j = 0; j <= k; j++) {
        dp[j] = save[level][j];
      }
    }
    {
      for (int i = mid + 1; i <= to; i++) {
        for (int j = k - sz[i]; j >= 0; j--) {
          dp[j + sz[i]] = max(dp[j + sz[i]], dp[j] + sum[i]);
        }
      }
      Solve(level + 1, from, mid);
      for (int j = 0; j <= k; j++) {
        dp[j] = save[level][j];
      }
    }
  };
  Solve(0, 0, n - 1);
  cout << ans << '\n';
  return 0;
}


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

typedef long long ll;

const ll INF = (ll)1e18 + 41;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<ll> dp(k + 1, 0);
    vector<ll> maxUseless(k + 1, -INF);

    vector<vector<ll>> prefs(n);

    for (int i = 0; i < n; i++) {
        ll sum = 0;
        int sz; cin >> sz;
        vector<pair<int, ll>> pref;
        for (int j = 0; j < sz; j++) {
            int x; cin >> x; sum += x;
            if (j + 1 <= k)
                prefs[i].push_back(sum);
        }
    }

    mt19937 rnd(3431);
    shuffle(prefs.begin(), prefs.end(), rnd);

    for (int i = 0; i < n; i++) {
        vector<pair<int, ll>> a;
        const auto &pp = prefs[i];
        for (int j = 0; j < (int)pp.size(); j++) if (pp[j] > maxUseless[j + 1]) {
            a.emplace_back(j + 1, pp[j]);
        }
        vector<bool> isA(a.size(), false);

        for (int pos = k; pos > 0; pos--) {
            ll oldDp = dp[pos];
            for (int j = 0; j < (int)a.size(); j++) {
                int len = a[j].first;
                if (pos < len) continue;
                ll val = a[j].second;
                if (oldDp < dp[pos - len] + val) isA[j] = true;
                if (dp[pos] < dp[pos - len] + val) dp[pos] = dp[pos - len] + val;
            }
        }

        for (int j = 0; j < (int)a.size(); j++) {
            if (!isA[j]) {
                maxUseless[a[j].first] = max(maxUseless[a[j].first], a[j].second);
            }
        }
    }

    cout << dp[k] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
#ifdef SERT
    freopen("a.in", "r", stdin);
    t = 1;
#endif
    while (t--) solve();
}


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

typedef long long ll;

const ll INF = (ll)1e18 + 41;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<ll> dp(k + 1, 0);
    vector<ll> maxUseless(k + 1, -INF);

    vector<vector<ll>> prefs(n);

    for (int i = 0; i < n; i++) {
        ll sum = 0;
        int sz; cin >> sz;
        vector<pair<int, ll>> pref;
        for (int j = 0; j < sz; j++) {
            int x; cin >> x; sum += x;
            if (j + 1 <= k)
                prefs[i].push_back(sum);
        }
    }

    mt19937 rnd(3431);
    shuffle(prefs.begin(), prefs.end(), rnd);

    for (int i = 0; i < n; i++) {
        vector<pair<int, ll>> a;
        const auto &pp = prefs[i];
        for (int j = 0; j < (int)pp.size(); j++) if (pp[j] > maxUseless[j + 1]) {
            a.emplace_back(j + 1, pp[j]);
        }
        vector<bool> isA(a.size(), false);

        for (int pos = k; pos > 0; pos--) {
            ll oldDp = dp[pos];
            for (int j = 0; j < (int)a.size(); j++) {
                int len = a[j].first;
                if (pos < len) continue;
                ll val = a[j].second;
                if (oldDp < dp[pos - len] + val) isA[j] = true;
                if (dp[pos] < dp[pos - len] + val) dp[pos] = dp[pos - len] + val;
            }
        }

        for (int j = 0; j < (int)a.size(); j++) {
            if (!isA[j]) {
                maxUseless[a[i].first] = max(maxUseless[a[i].first], a[i].second);
            }
        }
    }

    cout << dp[k] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
#ifdef SERT
    freopen("a.in", "r", stdin);
    t = 1;
#endif
    while (t--) solve();
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define int64 long long
#define ldb long double
const ldb pi = acos(-1.0);

const int N = 20;
const double eps = 1e-10;
int n, k;
double a[N], p[1 << N], res[N];

int main() {
	// assert(freopen("input.txt", "r", stdin));
	// assert(freopen("output.txt", "w", stdout));
	scanf("%d%d", &n, &k);
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%lf", &a[i]);
		if (a[i] < eps) ++cnt;
	}
	k = min(n - cnt, k);
	p[0] = 1;
	for (int mask = 1; mask < (1 << n); ++mask) {
		double suma = 0;
		bool ok = true;
		int cnt = 0;
		for (int i = 0; i < n; ++i)
			if (mask & (1 << i)) {
				suma += a[i];
				if (a[i] < eps) ok = false;
				++cnt;
			}
		if (!ok) {
			p[mask] = 0;
			continue;
		} else {
			double sump = 0;
			for (int i = 0; i < n; ++i)
				if (mask & (1 << i))
					sump += a[i] / (1 - suma + a[i]) * p[mask ^ (1 << i)];
			p[mask] = sump;
		}
		if (cnt == k)
			for (int i = 0; i < n; ++i)
				if (mask & (1 << i))
					res[i] += p[mask];
	}
	for (int i = 0; i < n; ++i)
		printf("%.10f%c", res[i], " \n"[i == n - 1]);
	return 0;
}


//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <bitset>
#include <cstring>
#include <string>
#include <complex>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

using ll = long long;
using pii = pair<int, int>;
template<class T1, class T2, class T3> struct triple {
	T1 x; T2 y; T3 z;
};
using tri = triple<int, int, int>;
using trll = triple<ll, ll, ll>;
template<class T1, class T2, class T3>
bool operator<(const triple<T1, T2, T3>& t1, const triple<T1, T2, T3>& t2) {
	return t1.x < t2.x || (t1.x == t2.x && (t1.y < t2.y || t1.y == t2.y && t1.z < t2.z));
}

#define eps 1e-9
#define bs 1000000007
const int mod = 1000000007;
const int INF = 1000111000;
const ll LLINF = 1000111000111000111LL;
const double PI = acos(-1.0);
#define bsize 256

#define all(v) (v).begin(), (v).end()
#define FI(n) for (int i = 0; i < n; ++i)
#define FJ(n) for (int j = 0; j < n; ++j)
#define FK(n) for (int k = 0; k < n; ++k)
#define FREIN(file) freopen(file, "rt", stdin)
#define FREOUT(file) freopen(file, "wt", stdout)
#define sqr(x) ((x)*(x))

#define DB(n) cerr<<#n<<" = "<<(n)<<" "
#define DBN(n) cerr<<#n<<" = "<<(n)<<"\n"

int gcd(int x, int y) { while (y) { x %= y, swap(x, y); } return y; }
ll gcd(ll x, ll y) { while (y) { x %= y, swap(x, y); } return y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll powmod(ll x, ll n, const int mod) {
	ll res = 1; while (n)
	{
		if (n & 1) res = res * x % mod; n /= 2; x = x * x % mod;
	} return res;
}

int n, k;
double prob[200];
double dp[1 << 20];
double sum[1 << 20];
double ans[22];

int count_bits(int x)
{
	if (x == 0)
		return 0;
	return count_bits(x / 2) + x % 2;
}

int flag;

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

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> prob[i];
	}

	for (int mask = 0; mask < (1 << n); mask++)
	{
		double s = 0;
		for (int i = 0; i < n; i++)
		{
			if (mask&(1 << i))
				s += prob[i];
		}
		sum[mask] = s;
	}

	dp[0] = 1;

	for (int mask = 0; mask < (1 << n); mask++)
	{
		int qb = count_bits(mask);
		if (qb > k)
			continue;
		if (dp[mask]<1e-100)
			continue;
		if (qb == k)
			flag = 1;
		double rem_sum = 1.0 - sum[mask];
		if (rem_sum < 1e-6)
			continue;
		for (int i = 0; i < n; i++)
		{
			if (mask&(1 << i))
				continue;
			double chance_move = dp[mask] * prob[i] / rem_sum;
			dp[mask | (1 << i)] += chance_move;
		}
	}

	if (flag == 0)
	{
		for (int i = 0; i < n; i++)
		{
			if (prob[i] < 1e-6)
				ans[i] = 0;
			else
				ans[i] = 1;
		}
	}
	else
	{
		for (int mask = 0; mask < (1 << n); mask++)
		{
			if (count_bits(mask) == k)
			{
				for (int i = 0; i < n; i++)
				{
					if (mask&(1 << i))
						ans[i] += dp[mask];
				}
			}
		}
	}

	cout.precision(12);
	for (int i = 0; i < n; i++)
	{
		if (i)
			cout << " ";
		cout << fixed << ans[i];
	}
	cout << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <ctime>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("task.in", "r", stdin);
	freopen("task.out", "w", stdout);
#endif

	cout.precision(15);
	cout << fixed;

	int n, k;
	while (cin >> n >> k) {
		vector<double> p(n);
		for (int i = 0; i < n; i++) cin >> p[i];

		vector<double> sum(1 << n);
		for (int i = 0; i < 1 << n; i++) {
			for (int j = 0; j < n; j++) {
				if (i & (1 << j)) {
					sum[i] += p[j];
				}
			}
		}

		vector<double> dp(1 << n);
		dp[0] = 1;
		for (int mask = 0; mask < 1 << n; mask++) {
			int rmask = (~mask) & ((1 << n) - 1);
			for (int i = 0; i < n; i++) if (rmask & (1 << i)) {
				dp[mask | (1 << i)] += dp[mask] * p[i] / sum[rmask];
			}
		}
		vector<double> ans(n);
		for (int mask = 0; mask < 1 << n; mask++) {
			int cnt = 0;
			for (int i = 0; i < n; i++) cnt += (mask & (1 << i)) != 0;
			if (cnt != k) continue;
			for (int i = 0; i < n; i++) if (mask & (1 << i)) {
				ans[i] += dp[mask];
			}
		}
		for (int i = 0; i < n; i++) cout << ans[i] << " \n"[i + 1 == n];
	}

	return 0;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define int64 long long
#define ldb long double
const ldb pi = acos(-1.0);

#define FULL 2
#define OK 1
#define EMPTY 0

int get_state(int a, int b, int c) {
	if ((a == 0) && (b == 0)) {
		if (c == 0) return FULL;
		return EMPTY;
	}
	return OK;
}

int det2(int a, int b, int c, int d) {
	return a * d - b * c;
}

int main() {
	// assert(freopen("input.txt", "r", stdin));
	// assert(freopen("output.txt", "w", stdout));
	int a1, b1, c1, a2, b2, c2;
	scanf("%d%d%d", &a1, &b1, &c1);
	scanf("%d%d%d", &a2, &b2, &c2);
	int s1 = get_state(a1, b1, c1);
	int s2 = get_state(a2, b2, c2);
	if (s1 == EMPTY || s2 == EMPTY) {
		printf("0\n");
		return 0;
	}
	if (s1 == FULL || s2 == FULL) {
		printf("-1\n");
		return 0;
	}
	int d = det2(a1, b1, a2, b2);
	if (d == 0) {
		if (det2(a1, c1, a2, c2) == 0) {
			printf("-1\n");
		} else {
			printf("0\n");
		}
	} else {
		printf("1\n");
	}
	return 0;
}