#include using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const int M=223577; struct Query{ int i,j; }; int N; LL P; LL A[100000]; LL B[100000]; int I[M]; vector ans; bool test_AeqB(){ rep(i,N) if(A[i]!=B[i]) return false; return true; } // A[i]+=A[j] void op(int i,int j){ A[i]+=A[j]; if(A[i]>=P) A[i]-=P; ans.push_back({i+1,j+1}); } // A[mem]!=0 // takes 40 moves void make_k(int dst,int mem,LL k){ LL t = (k+(P-A[dst])*(1ll<<18))%P *I[A[mem]]%P; for(int d=17; d>=0; d--){ op(dst,dst); if(t&(1ll<> V0(sqrtP); vector> V1(sqrtP); for(int i=2; i