#include #include #include int basic(int n, const std::vector> & birds) { int res = 0; for (int a = 0; a < n; ++a) for (int birdA : birds[a]) for (int b = a + 1; b < n; ++b) for (int birdB : birds[b]) if (birdA > birdB) res++; return res; } int main() { int n; std::ios::sync_with_stdio(false); std::cin >> n; std::vector> birds(n); for (int i = 0; i < n; ++i) { int b; std::cin >> b; for (int j = 0; j < b; ++j) { int en; std::cin >> en; birds[i].push_back(en); } std::sort(birds[i].begin(), birds[i].end()); } int res = 0; // basic(n, birds); std::vector crosses(n, 0); for (int pos = 0; pos < n; ++pos) { for (int bird : birds[pos]) { res += crosses[bird]; for (int i = 0; i < bird; ++i) ++crosses[i]; } } std::cout << res << std::endl; return 0; }