// // Created by cteam37 on 10/19/24. // #include #include using namespace std; int main() { int n; cin >> n; vector> powerLine1; vector> powerLine2; for (int line = 0; line < n; ++line) { int count; cin >> count; powerLine1.push_back({}); powerLine2.push_back({}); for (int i = 0; i < count; ++i) { int tmp; cin >> tmp; powerLine1[line].push_back(tmp); } } for (int i = 0; i < n; ++i) { for (int j = 0; j < powerLine1[i].size(); ++j) { int bird = powerLine1[i][j]; powerLine2[bird].push_back(i); } } int crossings = 0; for (int i = 0; i < powerLine2.size(); ++i) { //misto na kabelu for (int j = 0; j < powerLine2[i].size(); ++j) { //konkretní pták for (int k = i+1; k < powerLine2.size(); ++k) { // ostatní mista na kabelu for (int l = 0; l < powerLine2[k].size(); ++l) { //ostatní ptáci if(powerLine2[i][j] > powerLine2[k][l]) crossings++; } } } } cout << crossings << endl; return 0; }