#include using namespace std; #define For(i, a, n) for(int i =a;i pii; template void dbg(Args&&... args){ ((cerr< pair operator+(const pair&a, const pair& b){ return {a.first +b.first, a.second + b.second}; } template ostream& operator<< (ostream& os, const pair& a){ return os<<"("< basic_ostream& operator<<(basic_ostream& os, const C&c){ for(auto it=begin(c); it!=end(c);++it){ os<<(it==begin(c)?"":" ")<<*it; } return os; } class intervalac{ vec h, z , k; int velkost=1; public: intervalac(int a){ while(velkost 0;i--){ z[i] = z[i*2]; k[i] = k[i*2+1]; } // dbg(z, k); } void add(int index, int value = 1){ int t = index + velkost; while(t!=0){ // dbg(t); h[t]+= value; t/=2; } // dbg(h); } int sum(int l, int r = 1000000000, int v = 1){ // dbg(l, r, v, z[v], k[v]); if(l<=z[v]&&k[v]<=r)return h[v]; if(k[v]<=l||r<=z[v])return 0; return sum(l, r, v*2) + sum(l, r, v*2+1); } }; void solve(){ int n;cin>>n; ll ans = 0; intervalac it = intervalac(n); For(i, 0, n){ int p;cin>>p; vec q(p); For(j, 0, p){ cin>>q[j]; // dbg(q[j]); ll t = it.sum(q[j] + 1); // dbg("teraz", t); ans += t; } for(auto j:q){ it.add(j); } } cout<sync_with_stdio(0); cin.exceptions(cin.failbit); int t=1;//cin>>t; while(t--){ solve(); } }