#include <bits/stdc++.h>
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define st first
#define nd second
using namespace std;
typedef pair<int, int> PII;
typedef pair<unsigned, unsigned> PUU;
typedef long long LL;
typedef long double K;
const int mod = 1000000007;
struct node {
node *left, *right;
unsigned val;
};
struct khash {
unsigned operator()(const PUU& k) const {
return hash<unsigned>()(k.st) ^ (hash<unsigned>()(k.nd) << 1);
}
};
unordered_map<PUU, unsigned, khash> id;
unsigned get_id(int a, int b){
if(id.find(PUU(a,b)) == id.end()){
unsigned s = id.size();
return id[PUU(a,b)] = s;
}
return id[PUU(a,b)];
}
node* make(node* a, node* b){
return new node({a, b, get_id(a->val, b->val)});
}
pair<node*, bool> add(node* u, int b, int s=128*1024){
if(s==32)
return make_pair(new node({0, 0, u->val+(1<<b)}), u->val > u->val+(1<<b));
if(b < s/2){
pair<node*, bool> r = add(u->left, b, s/2);
if(r.nd){
pair<node*, bool> q = add(u->right, 0, s/2);
return make_pair(make(r.st, q.st), q.nd);
}
return make_pair(make(r.st, u->right), 0);
}else{
pair<node*, bool> r = add(u->right, b-s/2, s/2);
return make_pair(make(u->left, r.st), r.nd);
}
}
LL P2[64*1024+3];
LL res(node *u, int s=128*1024){
if(s==32) return u->val % mod;
return (res(u->left, s/2) + res(u->right, s/2) * P2[s/2]) % mod;
}
node* zero(int s=128*1024){
if(s==32)
return new node({0,0,0});
node* v = zero(s/2);
return new node({v, v, 0});
}
bool shorter(const node* a, const node *b){
if(a->val == b->val) return 0;
if(!a->left) return a->val < b->val;
if(a->right->val == b->right->val) return shorter(a->left, b->left);
return shorter(a->right, b->right);
}
const int MAXN = 100010;
int n, m;
vector<PII> E[MAXN];
node* dist[MAXN];
bool vis[MAXN];
bool reach[MAXN];
int pre[MAXN];
typedef pair<node*, int> elem;
struct comp{
bool operator()(elem a, elem b){
return shorter(b.st, a.st);
}
};
priority_queue<elem, vector<elem>, comp> Q;
void check(int p, int u, node* new_dist){
if(vis[u]) return;
if(!reach[u] || shorter(new_dist, dist[u])){
reach[u] = 1;
pre[u] = p;
dist[u] = new_dist;
Q.push(make_pair(new_dist, u));
}
}
int main(){
id[PII(0,0)] = 0;
P2[0] = 1;
FWD(i,1,64*1024+3) P2[i] = P2[i-1] * 2 % mod;
// scanf("%d %d", &n, &m);
n = 100000;
m = 100000 - 1;
FWD(i,0,m){
int a, b, c;
// scanf("%d %d %d", &a, &b, &c);
if (i < 50000) {
a = i + 1;
b = i + 2;
c = i;
}
else if (i < m - 1) {
a = 50001;
b = i + 2;
c = 0;
}
else {
a = 1;
b = n;
c = 100000;
}
E[a].push_back(PII(b,c));
E[b].push_back(PII(a,c));
}
int s, t;
// scanf("%d %d", &s, &t);
s = 1;
t = n;
check(0, s, zero());
while(!Q.empty()){
int u = Q.top().nd;
Q.pop();
if(vis[u]) continue;
vis[u] = 1;
for(PII e : E[u])
check(u, e.st, add(dist[u], e.nd).st);
}
if(!reach[t])
printf("-1\n");
else{
printf("%d\n", (int)res(dist[t]));
vector<int> path;
int u = t;
while(u){
path.push_back(u);
u = pre[u];
}
printf("%d\n", (int)path.size());
while(!path.empty()){
printf("%d ", path.back());
path.pop_back();
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRldEKGEsYixjKSBmb3IoaW50IGE9KGIpOyBhPChjKTsgKythKQojZGVmaW5lIEJDSyhhLGIsYykgZm9yKGludCBhPShiKTsgYT4oYyk7IC0tYSkKI2RlZmluZSBBTEwoYSkgKGEpLmJlZ2luKCksIChhKS5lbmQoKQojZGVmaW5lIHN0IGZpcnN0CiNkZWZpbmUgbmQgc2Vjb25kCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBwYWlyPGludCwgaW50PiBQSUk7CnR5cGVkZWYgcGFpcjx1bnNpZ25lZCwgdW5zaWduZWQ+IFBVVTsKdHlwZWRlZiBsb25nIGxv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ICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoaSA8IG0gLSAxKSB7CiAgICAgICAgICAgIGEgPSA1MDAwMTsKICAgICAgICAgICAgYiA9IGkgKyAyOwogICAgICAgICAgICBjID0gMDsKICAgICAgICB9CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIGEgPSAxOwogICAgICAgICAgICBiID0gbjsKICAgICAgICAgICAgYyA9IDEwMDAwMDsKICAgICAgICB9CgogICAgICAgIEVbYV0ucHVzaF9iYWNrKFBJSShiLGMpKTsKICAgICAgICBFW2JdLnB1c2hfYmFjayhQSUkoYSxjKSk7CiAgICB9CiAgICBpbnQgcywgdDsKLy8gICAgc2NhbmYoIiVkICVkIiwgJnMsICZ0KTsKICAgIHMgPSAxOwogICAgdCA9IG47CgogICAgY2hlY2soMCwgcywgemVybygpKTsKICAgIHdoaWxlKCFRLmVtcHR5KCkpewogICAgICAgIGludCB1ID0gUS50b3AoKS5uZDsKICAgICAgICBRLnBvcCgpOwogICAgICAgIGlmKHZpc1t1XSkgY29udGludWU7CiAgICAgICAgdmlzW3VdID0gMTsKICAgICAgICBmb3IoUElJIGUgOiBFW3VdKQogICAgICAgICAgICBjaGVjayh1LCBlLnN0LCBhZGQoZGlzdFt1XSwgZS5uZCkuc3QpOwogICAgfQogICAgaWYoIXJlYWNoW3RdKQogICAgICAgIHByaW50ZigiLTFcbiIpOwogICAgZWxzZXsKICAgICAgICBwcmludGYoIiVkXG4iLCAoaW50KXJlcyhkaXN0W3RdKSk7CiAgICAgICAgdmVjdG9yPGludD4gcGF0aDsKICAgICAgICBpbnQgdSA9IHQ7CiAgICAgICAgd2hpbGUodSl7CiAgICAgICAgICAgIHBhdGgucHVzaF9iYWNrKHUpOwogICAgICAgICAgICB1ID0gcHJlW3VdOwogICAgICAgIH0KICAgICAgICBwcmludGYoIiVkXG4iLCAoaW50KXBhdGguc2l6ZSgpKTsKICAgICAgICB3aGlsZSghcGF0aC5lbXB0eSgpKXsKICAgICAgICAgICAgcHJpbnRmKCIlZCAiLCBwYXRoLmJhY2soKSk7CiAgICAgICAgICAgIHBhdGgucG9wX2JhY2soKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQo=