#include #include #include int main() { unsigned int n; std::ios::sync_with_stdio(false); std::cin >> n; std::vector> birds(n); for (unsigned int i = 0; i < n; ++i) { unsigned int b; std::cin >> b; for (unsigned int j = 0; j < b; ++j) { unsigned int en; std::cin >> en; birds[i].insert(en); } // std::sort(birds[i].begin(), birds[i].end()); } unsigned int res = 0; std::vector crosses(n, 0); for (unsigned int pos = 0; pos < n; ++pos) { for (unsigned int bird : birds[pos]) { res += crosses[bird]; for (unsigned int i = 0; i < bird; ++i) ++crosses[i]; } } std::cout << res << std::endl; return 0; }