#include #include #include using namespace std; int main() { int crossings = 0; int n; cin >> n; vector vec(n, 0); for (size_t i = 0; i < n; i++) { vector now; int x; cin >> x; for (size_t j = 0; j < x; j++) { int y; cin >> y; now.push_back(y); } for (size_t k = 0; k < now.size(); k++) { for (size_t l = now[k] + 1; l < n; l++) { crossings += vec[l]; } } for (size_t p = 0; p < now.size(); p++) { ++vec[now[p]]; } } cout << crossings; }