#include #include using namespace std; struct Vertice { size_t index; set to_path; }; size_t count (const vector & vertices) { size_t ans = 0; for (size_t v = 0; v < vertices.size(); v++){ for (size_t to : vertices[v].to_path){ for (size_t next_v = v + 1; next_v < vertices.size(); next_v++){ for (size_t next_to : vertices[next_v].to_path){ if (next_to < to) ans++; } } } } return ans; }; int main() { vector vertices; int n; cin >> n; for (int i = 0; i < n; i++){ Vertice vert; vert.index = i; int m; cin >> m; for (int j = 0; j < m; j++){ int l; cin >> l; vert.to_path.insert(l); } vertices.insert(vertices.end(), vert); } cout << count(vertices); return 0; }