#include<bits/stdc++.h>#pragma GCC target("popcnt")#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S secondusingnamespacestd;constintINF=2e18;constintmaxn=3005;constintM=1e9+7;constintX=131;intn,m;bitset<maxn>B[maxn];inta[maxn][maxn];voidinit(){cin>>n;for(inti=1;i<=n;i++){cin>>B[i];}}voidsolve(){intans=0;bitset<maxn>b;for(inti=1;i<=n;i++){for(intj=i+1;j<=n;j++){b=B[i]&B[j];intcnt=b.count();ans+=cnt*(cnt-1)/2;}}cout<<ans<<"\n";}signedmain(){ios::sync_with_stdio(0);cin.tie(0);intt=1;//cin >> t;while(t--){init();solve();}}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S secondusingnamespacestd;constintINF=2e18;constintmaxn=5e4+5;constintM=1e9+7;constintX=131;intn,m;vector<int>G[maxn];bitset<maxn>B[maxn];intvis[maxn];voiddfs(intu){if(vis[u])return;vis[u]=true;for(autov:G[u]){dfs(v);B[u][v]=1;B[u]|=B[v];}}voidinit(){cin>>n>>m;intu,v;for(inti=1;i<=m;i++){cin>>u>>v;G[u].pb(v);}}voidsolve(){for(inti=1;i<=n;i++)if(!vis[i])dfs(i);for(inti=1;i<=n;i++)cout<<B[i].count()+1<<" ";}signedmain(){// ios::sync_with_stdio(0);// cin.tie(0);intt=1;//cin >> t;while(t--){init();solve();}}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_backusingnamespacestd;constintmaxn=2505;constintM=1e9+7;constintINF=0x3f3f3f3f;bitset<maxn>B[maxn];intn,m;voidinit(){cin>>n;for(inti=1,u,v;i<=n;i++){intt;cin>>t;while(t--){cin>>v;v++;B[i][v]=1;}}}voidsolve(){bitset<maxn>b;intres=0;for(inti=1;i<=n;i++){for(intj=i+1;j<=n;j++){b=B[i]&B[j];if(b.count())res++;}}cout<<res<<"\n";}signedmain(){init();solve();}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;constintINF=2e18;constintmaxn=1e5+5;bitset<maxn>dp;voidsolve(){intn,W;cin>>n>>W;dp.reset();dp.set(0);for(inti=0;i<n;i++){intx,y,z;cin>>x>>y>>z;dp=(dp<<x)|(dp<<y)|(dp<<z);}for(inti=W;i>0;i--){if(dp[i]){cout<<i<<'\n';return;}}cout<<"no solution\n";}signedmain(){intt=1;cin>>t;while(t--){solve();}}
#include<bitset>#include<iostream>#include<vector>#define int long longusingnamespacestd;constintmaxn=1e5+5;intn,m;intpar[maxn],sz[maxn];vector<int>W;voiddsu_init(){for(inti=1;i<=n;i++){par[i]=i;sz[i]=1;}}intfind(intx){if(par[x]==x)returnx;returnpar[x]=find(par[x]);}voidmerge(inta,intb){intx=find(a),y=find(b);if(x==y)return;par[x]=y;sz[y]+=sz[x];sz[x]=0;}voidinit(){cin>>n>>m;intu,v;dsu_init();for(inti=0;i<m;i++){cin>>u>>v;merge(u,v);}}voidsolve(){W.resize(n+1);for(inti=1;i<=n;i++){W[sz[i]]++;}bitset<maxn>B;B.reset();B[0]=1;for(inti=1;i<=n;i++){if(W[i]>=2){intk=(W[i]-1)/2;W[2*i]+=k;W[i]-=2*k;}}for(inti=1;i<=n;i++){for(intj=1;j<=W[i];j++){B|=(B<<i);}}for(inti=1;i<=n;i++){cout<<B[i];}}signedmain(){ios::sync_with_stdio(0);cin.tie(0);intt=1;// cin >> t;while(t--){init();solve();}}