#include #include int collide(int b1_start, int b2_start, std::vector>& positions) { int collisions = 0; for (int b1_dest : positions[b1_start]) { for (int b2_dest : positions[b2_start]) { if ((b1_dest > b2_dest)) { collisions++; } } } return collisions; } int main(){ int n; std::cin >> n; std::vector> desiredPos; for (int i = 0; i < n; i++) { int birdsCount; std::cin >> birdsCount; std::vector destinations; for (int j = 0; j < birdsCount; j++) { int dest; std::cin >> dest; destinations.push_back(dest); } desiredPos.push_back(destinations); } long sum = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { sum += collide(i, j, desiredPos); } } std::cout << sum; return 0; }