#include #include #include #include using namespace std; #define mod 1000000007 queue q; struct edge{ int t,nxt; }a[4000009]; int dist[200009],cur,n,m; int fir[200009],T,now[200009],s[20],x,y,ans; bool inq[200009]; void addedge(int from,int to){ cur++; if (fir[from]==0) fir[from]=cur; a[cur].t=to; a[now[from]].nxt=cur; now[from]=cur; } void bfs(int ss){ dist[0]=0; for (int i=0;i<1<<17;i++){ if (dist[i]<100) q.push(i),inq[i]=1; } while(!q.empty()){ int x=q.front(); q.pop(); inq[x]=false; for (int i=fir[x];i!=0;i=a[i].nxt){ if (dist[a[i].t]>dist[x]+1){ dist[a[i].t]=dist[x]+1; if (!inq[a[i].t]){ inq[a[i].t]=1; q.push(a[i].t); } } } } } int main(){ #ifdef YJQ_LOCAL freopen(".in","r",stdin); #endif scanf("%d",&T); for (int i=0;i<1<<17;i++){ for (int j=0;j<=16;j++){ addedge(i,i^(1<>j) & 1)!=0){ tmp^=s[j],cnt++; } } dist[tmp]=min(dist[tmp],cnt); } bfs(0); for (int i=1;i<=m;i++){ scanf("%d%d",&x,&y); x^=y; //printf("%d",dist[i]); ans=(ans+dist[x]*i) % mod; } printf("%d\n",ans); } }