// author : black_trees#include<cmath>#include<cstdio>#include<vector>#include<cstring>#include<iostream>#include<algorithm>#define endl '\n'#define int long longusingnamespacestd;usingi64=longlong;constintsi=2e6+10;structobj{intsiz,id;std::vector<int>v;voidinit(){siz=id=0,v.clear();}booloperator<(constobj&b)const{returnsiz>b.siz;}}p[si];intn;intbel[si],rec[si];signedmain(){cin.tie(0)->sync_with_stdio(false);cin.exceptions(cin.failbit|cin.badbit);intT;cin>>T;while(T--){cin>>n;for(inti=1;i<=n;++i){p[i].init(),bel[i]=0,p[i].id=i;cin>>p[i].siz;for(intj=0,x;j<p[i].siz;++j)cin>>x,p[i].v.emplace_back(x);}sort(p+1,p+1+n);intu,v;intcol=0;for(inti=1;i<=n;++i){u=v=0;col=p[i].id,rec[p[i].id]=i;for(intj=0;j<p[i].siz;++j){intt=p[i].v[j];inttmp=bel[t];bel[t]=col;if(!tmp)tmp=col;if(!u)u=tmp;elseif(u!=tmp)v=tmp;if(u&&v){n=-1;p[i].siz=-1;}}}if(n!=-1)cout<<"NO"<<endl;else{if(u==col||v==col);elseif(p[rec[u]].siz>p[rec[v]].siz)u=col;elsev=col;cout<<"YES"<<endl;cout<<u<<" "<<v<<endl;}}return0;}
// author : black_trees#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define endl '\n'#define int long longusingnamespacestd;usingi64=longlong;constintsi=2e5+5;constintV=si<<1;constintinf=0x3f3f3f3f3f3f3f3fll;intn,m;inta[5][si],ord[]={1,2,3,4};classFenwick{private:intt[V+10];inlineintlowbit(intx){returnx&-x;}public:voidinit(){memset(t,0,sizeoft);}voidadd(intx,intv){while(x<=V)t[x]+=v,x+=lowbit(x);}intque(intx){intret=0;while(x)ret+=t[x],x-=lowbit(x);returnret;}}tr;structOperations{inttyq,x,y,v;Operations(){tyq=x=y=v=0;}Operations(inta,intb,intc,intd):tyq(a),x(b),y(c),v(d){}booloperator<(constOperations&t)const{if(x!=t.x)returnx<t.x;returntyq<t.tyq;}}b[si<<1];intsolve(intp[]){inte=p[0],f=p[1],g=p[2];tr.init();intret=0,cnt=0;for(inti=1;i<=n;++i){b[++cnt]=Operations(1,a[e][i]-a[f][i],a[f][i]-a[g][i],0);b[cnt].x+=(e>f),b[cnt].y+=(f>g);b[++cnt]=Operations(2,a[f][i]-a[e][i],a[g][i]-a[f][i],a[f][i]);}sort(b+1,b+1+cnt);for(inti=1;i<=cnt;++i){auto[tyq,x,y,v]=b[i];if(tyq==1)tr.add(y+si,1);if(tyq==2)ret+=v*tr.que(y+si);}returnret;}signedmain(){cin.tie(0)->sync_with_stdio(false);cin.exceptions(cin.failbit|cin.badbit);cin>>m>>n;for(inti=1;i<=m;++i){for(intj=1;j<=n;++j){cin>>a[i][j];}}for(inti=m+1;i<=4;++i){for(intj=1;j<=n;++j){a[i][j]=a[i-m][j];}}intans=0;for(inti=1;i<=4;++i){for(intj=1;j<=n;++j){ans+=(2ll*n*a[i][j]);}}do{ans-=solve(ord);}while(next_permutation(ord,ord+4));cout<<ans<<endl;return0;}