#include using namespace std; int main(){ ios_base::sync_with_stdio(false); long long x = 0; cin >> x; vector line (x,0); long long dangerous = 0; for(long long i = 0; i < x; i++){ long long birds; cin >> birds; vector next (birds, 0); for(long long j = 0; j < birds; j++){ long long index; cin >> index; for(long long k = index+1; k < x; k++){ dangerous += line[k]; } next[j] = index; } for(auto num : next){ ++line[num]; } } cout << dangerous << endl; }