#include using namespace std; #define ll long long int main() { int pct; cin >> pct; int tot = 0; vector > linia1; vector > linia2; linia1.resize(pct); linia2.resize(pct); for (int i = 0; i < pct; i++) { int numb; cin >> numb; for (int g = 0; g < numb; g++) { int to; cin >> to; linia1[i].push_back(to); linia2[to].push_back(i); } } int bot = 0; int top = 0; for (int i = 0; i < pct; i++) { int debili = 0; int debilitop = 0; int debilibot = 0; for (int g = 0; g < linia1[i].size(); g++) { if (linia1[i][g] == i) { debili += 1; } else if (linia1[i][g] > i) { debilitop +=1; } else { bot-=1; } } for (int g = 0; g < linia2[i].size(); g++) { if (linia2[i][g] == i) { } else if (linia2[i][g] > i) { debilibot +=1; } else { top-=1; } } tot += debili*(top+bot); tot += debilibot*top; tot += debilitop*bot; tot += debilitop*debilibot; bot+= debilibot; top+= debilitop; } cout << tot; cout << endl; }