#include #define endl '\n' using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } struct clothes { int c,p; clothes(){} clothes(int _c,int _p) { c=_c; p=_p; } }; bool cmp(clothes c1,clothes c2) { return c1.p>c2.p; } const int maxn=52; const int maxx=125002; const int maxc=1e7+2; int n,x[maxn]; int ans; clothes cl[maxn][maxx]; int used[maxc]; void read() { cin>>n; for(int i=1;i<=n;i++) { cin>>x[i]; for(int j=1;j<=x[i];j++) { cin>>cl[i][j].c>>cl[i][j].p; } } } void rec(int pos,int sum,int used[]) { if(pos>n) { if(sum>ans)ans=sum; return; } for(int i=1;i<=x[pos];i++) { if(!used[cl[pos][i].c]) { used[cl[pos][i].c]=1; rec(pos+1,sum+cl[pos][i].p,used); used[cl[pos][i].c]=0; } } } void solve() { rec(1,0,used); cout<