program xqz; const maxm=200001; var i,j,k,m,n,ll,rr,x,de,ans,o:longint; a,b,s,t,y:array[0..maxm] of longint; c,f:array[0..maxm*2] of longint; procedure swap(var a,b:longint); var k:longint; begin k:=a; a:=b; b:=k; end; procedure sort1(ll,rr:longint); var i,j:longint; begin i:=ll; j:=rr; x:=a[random(rr-ll+1)+ll]; while i<=j do begin while a[i]<x do inc(i); while a[j]>x do dec(j); if i<=j then begin swap(a[i],a[j]); inc(i); dec(j); end; end; if j>ll then sort1(ll,j); if i<rr then sort1(i,rr); end; procedure sort2(ll,rr:longint); var i,j:longint; begin i:=ll; j:=rr; x:=y[random(rr-ll+1)+ll]; while i<=j do begin while y[i]<x do inc(i); while y[j]>x do dec(j); if i<=j then begin swap(s[i],s[j]); swap(t[i],t[j]); swap(y[i],y[j]); inc(i); dec(j); end; end; if j>ll then sort2(ll,j); if i<rr then sort2(i,rr); end; procedure ins(i,s,t:longint); var tt,mid:longint; begin if (ll<a[s])and(a[t]<=rr) then//注意不等号,这样代入a[s],a[t]就不用二分ll,rr的序号以后再做了。 begin inc(c[i],de); inc(f[i],de); exit; end; tt:=i*2; mid:=(s+t) shr 1; if ll<a[mid] then ins(tt,s,mid);//注意不等号 if rr>a[mid] then ins(tt+1,mid+1,t); if f[tt]>f[tt+1] then f[i]:=f[tt]+c[i] else f[i]:=f[tt+1]+c[i];//在这里让标记起作用 end; begin read(n); randomize; for n:=1 to n do begin read(k); for k:=1 to k do read(b[k]); b[k+1]:=b[1]; for i:=1 to k do if odd(i) then begin inc(m); a[m]:=b[i]; inc(rr); s[rr]:=b[i]; t[rr]:=b[i+2]; y[rr]:=b[i+1]; end; end; sort2(1,rr); k:=rr; sort1(1,m); i:=m; m:=1; for i:=2 to i do if a[i]<>a[i-1] then begin inc(m); a[m]:=a[i]; end; for k:=1 to k do begin ll:=s[k]; rr:=t[k]; de:=1; if ll>rr then begin swap(ll,rr); de:=-1; end; ins(1,1,m); if f[1]>ans then ans:=f[1]; end; writeln(ans); end.