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