#include #include using namespace std; typedef long long ll; ll a[100010],b[100010],d[100010],p = 223577; int cnt[300010]; vector pa[300010]; ll pw(ll a,ll x){ ll ret = 1; while(x){ if(x&1) (ret *= a) %= p; (a *= a) %= p; x /= 2; } return ret; } vector> ans; void solve(int i,int j){ ans.push_back({i,j}); (a[i] += a[j]) %= p; } void fin(){ cout << ans.size() + 1 << endl; for(int i=0;i> n >> x; for(i=0;i> a[i]; for(i=0;i> b[i]; bool f1 = false,f2 = false; for(i=0;i z1,z2; int j = -1,k = -1; for(i=0;i1) j = z1[1]; else k = z2[1]; } ll inv = pw(a[j],p - 2); for(i=0;ib[k]) a[k] -= p; ll dif = b[k] - a[k]; while(dif){ if(dif&1) solve(k,j); solve(j,j); dif /= 2; } ll inv2 = pw(a[k],p - 2); for(i=0;i v; for(i=0;i=v[j] && cnt[i - v[j]]){ pa[i].push_back(v[j]); pa[i].push_back(i - v[j]); break; } if(j==v.size() - 1){ //cout << i << endl; //cout << " xxx " << endl; } } } pa[13].push_back(1); pa[13].push_back(4); pa[13].push_back(8); pa[25].push_back(1); pa[25].push_back(8); pa[25].push_back(16); for(j=0;j1 && pa[d[i]][1]==a[k]) solve(i,k); if(pa[d[i]].size()>2 && pa[d[i]][2]==a[k]) solve(i,k); if(pa[d[i]].size()>3 && pa[d[i]][3]==a[k]) solve(i,k); } if(f) break; solve(k,k); } for(i=0;ip) exit(1); /*for(i=0;i