#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> a(n); for (int i = 0; i < n; i++) { int p; cin >> p; for (int j = 0; j < p; j++) { int x; cin >> x; a[i].push_back(x); } } vector idx(n); vector ans; while (true) { bool updated = false; for (int i = 0; i < n; i++) { if (idx[i] >= (int) a[i].size()) continue; ans.push_back(a[i][idx[i]]); idx[i]++; updated = true; } if (!updated) break; } for (int i = 0; i < (int) ans.size(); i++) { if (i > 0) cout << " "; cout << ans[i]; } return 0; }