#include <iostream> #include <vector> using namespace std; typedef long long ll; ll a[100010],b[100010],d[100010],p = 223577; int cnt[300010]; vector<int> 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<pair<int,int>> 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<ans.size();i++){ cout << 1 << " " << ans[i].first + 1 << " " << ans[i].second + 1 << endl; } cout << 2 << endl; } int main(){ int i,n,x; cin >> n >> x; for(i=0;i<n;i++) cin >> a[i]; for(i=0;i<n;i++) cin >> b[i]; bool f1 = false,f2 = false; for(i=0;i<n;i++){ if(a[i]) f1 = true; if(b[i]) f2 = true; } if((f1 && !f2) || (!f1 && f2)){ cout << -1 << endl; return 0; } if(!f1 && !f2){ cout << 0 << endl; return 0; } vector<int> z1,z2; int j = -1,k = -1; for(i=0;i<n;i++){ if(a[i]) z1.push_back(i); if(b[i]) z2.push_back(i); } if(z1.size()==1 && z2.size()==1 && z1[0]==z2[0]){ j = z1[0]; for(i=0;i<p;i++){ if(a[j]!=b[j]) solve(j,j); } if(a[j]==b[j]) fin(); else cout << -1 << endl; return 0; } j = z1[0],k = z2[0]; if(j==k){ if(z1.size()>1) j = z1[1]; else k = z2[1]; } ll inv = pw(a[j],p - 2); for(i=0;i<n;i++) (a[i] *= inv) %= p, (b[i] *= inv) %= p; if(a[k]>b[k]) a[k] -= p; ll dif = b[k] - a[k]; while(dif){ if(dif&1) solve(k,j); solve(j,j); dif /= 2; } //cout << ans.size() << endl; ll inv2 = pw(a[k],p - 2); for(i=0;i<n;i++){ (a[i] *= inv2) %= p; (b[i] *= inv2) %= p; d[i] = b[i] - a[i]; if(d[i]<0) d[i] += p; } int rr = 1; for(i=0;i<p;i++){ cnt[rr]++; rr *= 2; rr %= p; } cnt[0]++; vector<int> v; for(i=0;i<p;i++){ if(cnt[i]) v.push_back(i); } for(i=0;i<p;i++){ for(j=0;j<v.size();j++){ if(i>=v[j] && cnt[i - v[j]]){ if(v[j]) pa[i].push_back(v[j]); if(i - v[j]) pa[i].push_back(i - v[j]); break; } } } 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); vector<vector<int>> uu(p); for(i=0;i<n;i++){ for(int y:pa[d[i]]){ uu[y].push_back(i); } } //cout << v.size() << endl; /*for(i=0;i<p;i++){ int sum = 0; for(int x:pa[i]) (sum += x) %= p; if(sum!=i) cout << "x " << i << endl; }*/ vector<bool> ok(n,false); int c = 0,z = 0; for(j=0;j<p;j++){ for(int y:uu[a[k]]){ if(y==k) continue; solve(y,k); z++; if(a[y]==b[y]) c++; } /*bool f = true; for(i=0;i<n;i++){ if(a[i]==b[i]) continue; f = false; if(pa[d[i]][0]==a[k]) solve(i,k); if(pa[d[i]].size()>1 && 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;*/ if(c==n - 1) break; solve(k,k); } for(i=0;i<n;i++){ if(i==k) continue; if(a[i]!=b[i]) return 0; } //cout << ans.size() << endl; for(i=0;i<p;i++){ if(a[k]==b[k]) continue; solve(k,k); } //cout << ans.size() << endl; fin(); for(i=0;i<n;i++){ if(a[i]!=b[i]){ cout << i << endl; return 0; } } if(ans.size()>p) exit(1); /*for(i=0;i<n;i++) cout << a[i] << " "; cout << endl; for(i=0;i<n;i++) cout << b[i] << " "; cout << endl;*/ //cout << "hoge" << endl; }